From 16509b590987a0b966a326b6d39d8a2d553582be Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 17 May 2009 02:47:22 +0100 Subject: [PATCH] Treat backwards-going timestamp as a day change. Not perfect if the clocks change but what can you do. --- TODO | 3 --- yoweb-scrape | 18 ++++++++++++++---- yoweb-scrape.txt | 8 ++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 17e32cb..ecd5199 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,4 @@ yoweb-scrape - do right thing when chat log timestamp goes backwards: - assume it's the next day (will go wrong when - clocks go wrong - oh well) parse officer chat for /off /a [:] ... /off /d [:] ... diff --git a/yoweb-scrape b/yoweb-scrape index c99b2b0..cc98ea3 100755 --- a/yoweb-scrape +++ b/yoweb-scrape @@ -482,7 +482,8 @@ class ChatLogTracker: m = rm('=+ (\\d+)/(\\d+)/(\\d+) =+$') if m: - self._date = m.groups() + self._date = [int(x) for x in m.groups()] + self._previous_timestamp = None return d('date '+`self._date`) if self._date is None: @@ -492,9 +493,18 @@ class ChatLogTracker: if not m: return d('no timestamp') - time_tuple = [int(x) for x in self._date + m.groups()] - time_tuple += (-1,-1,-1) - timestamp = time.mktime(time_tuple) + while True: + time_tuple = (self._date + + [int(x) for x in m.groups()] + + [-1,-1,-1]) + timestamp = time.mktime(time_tuple) + if timestamp >= self._previous_timestamp: break + self._date[2] += 1 + self._debug_line_disposition(timestamp,'', + 'new date '+`self._date`) + + self._previous_timestamp = timestamp + l = l[l.find(' ')+1:] def ob_x(who,event): diff --git a/yoweb-scrape.txt b/yoweb-scrape.txt index 2878be4..84368c5 100644 --- a/yoweb-scrape.txt +++ b/yoweb-scrape.txt @@ -73,6 +73,14 @@ Other things to mention: * I haven't decided on a final copyright licence. You may treat this version as GPLv3. + * The program will become confused when the clocks change, + particularly when they go backwards. This is due to the chat log + containing timestamps in local time without a timezone. If this + bothers you, make everything be in UTC. If it does get confused, + you can fix it by logging off and logging on again (perhaps waiting + until after the duplicated hour has passed) as that writes a new + date record to the log and starts a new series of timestamps. + Ian. -- 2.30.2