Felix Geller avatar Felix Geller committed 0c86e81

Change to fix problem with multi-day all-day events
- Always insert range, but subtract a day from last day on all-day event. For example:
:When: <2011-06-16 Thu>--<2011-06-16 Thu>
:Where: N/A
:Who: fgeller@gmail.com

Comments (0)

Files changed (1)

 import gdata.calendar.client
 from datetime import date, datetime, timedelta
-import time, sys, re, os, getopt
+from time import strftime, strptime, mktime, localtime
+import sys, re, os, getopt
 preamble = """#+STARTUP: overview
 #+DESCRIPTION: Converted on %s
   feed = cal_client.GetCalendarEventFeed(q=query)
   return feed.entry
-def timestamp(date):
-  if 'T' in date:
-    t = time.strptime(date[:16], '%Y-%m-%dT%H:%M')
-    return time.strftime('<%Y-%m-%d %a %H:%M>', t)
+def date_range(start_time, end_time):
+  if 'T' in start_time:
+    st = strptime(start_time[:16], '%Y-%m-%dT%H:%M')
+    et = strptime(end_time[:16], '%Y-%m-%dT%H:%M')
+    tstamp = '<%Y-%m-%d %a %H:%M>'
-    t = time.strptime(date, '%Y-%m-%d')
-    return time.strftime('<%Y-%m-%d %a>', t)
-def singleday(start_time, end_time):
-  if 'T' in start_time:
-    return False
-  else:
-    st = time.mktime(time.strptime(start_time, '%Y-%m-%d'))
-    et = time.mktime(time.strptime(end_time, '%Y-%m-%d'))
-    if et - st <= 86400.0:
-      return True
-    else:
-      return False
+    st = strptime(start_time, '%Y-%m-%d')
+    et = localtime(mktime(strptime(end_time, '%Y-%m-%d')) - 86400.0)
+    tstamp = '<%Y-%m-%d %a>'
+  return '%s--%s' % tuple([strftime(tstamp, t) for t in (st, et)])
 def write_item(event, org_file):
-  s = event.when[0].start
-  e = event.when[0].end
   title = event.title.text
-  when = timestamp(s) if singleday(s, e) else '%s--%s' % tuple([timestamp(d) for d in (s, e)])
+  when = date_range(event.when[0].start, event.when[0].end)
   where = event.where[0].text or 'N/A'
   who = ', '.join([x.value for x in event.who])
   description = event.content.text or 'N/A'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.