chiark / gitweb /
Treat backwards-going timestamp as a day change. Not perfect if the clocks change...
authorIan Jackson <ian@liberator.(none)>
Sun, 17 May 2009 01:47:22 +0000 (02:47 +0100)
committerIan Jackson <ian@liberator.(none)>
Sun, 17 May 2009 01:47:22 +0000 (02:47 +0100)
TODO
yoweb-scrape
yoweb-scrape.txt

diff --git a/TODO b/TODO
index 17e32cbbae3beff1e36bb81fbc59cf8d3bb6e50b..ecd519919bc96a948597300e432551a8d0c96b90 100644 (file)
--- 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 [<ship>:] <pirate>...
                /off /d [<ship>:] <pirate>...
index c99b2b0c684362f3db3b4507823bba7af6bb2ce9..cc98ea3b21b869154ed0a46ca5aec941d7f71a71 100755 (executable)
@@ -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):
index 2878be488f8b89a0fbe89b4154f4ff8fe782c7ea..84368c5d42eada95571c482e0c649e651a3648a9 100644 (file)
@@ -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.