]> git.madduck.net Git - etc/mutt.git/blobdiff - .mutt/icalparser

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

handle events with duration rather than end time
[etc/mutt.git] / .mutt / icalparser
index 38e2fe7c9fbd8472558a73cbaf8ce996d2f6d25d..77e7fe2880cf4b1090ddf9be14ca416ea2304714 100755 (executable)
@@ -13,8 +13,13 @@ COLUMNS = int(os.getenv('COLUMNS', 80))-10
 WIDTH = max(len(i) for i in FIELDS)
 INDENT = WIDTH + len(COLSEP)
 
 WIDTH = max(len(i) for i in FIELDS)
 INDENT = WIDTH + len(COLSEP)
 
-def dtstrs(start, end):
-    start, end = start.dt, end.dt
+def dtstrs(event):
+    start, end = event.get('dtstart').dt, event.get('dtend')
+    if not end:
+        duration = event.get('duration').dt
+        end = start + duration
+    else:
+        end = end.dt
 
     def strftime(dt, strf):
         return dt.astimezone().strftime(strf)
 
     def strftime(dt, strf):
         return dt.astimezone().strftime(strf)
@@ -39,7 +44,7 @@ def parse_ics_file(fp):
 
     for event in cal.walk():
         if event.name != "VEVENT": continue
 
     for event in cal.walk():
         if event.name != "VEVENT": continue
-        print('{} → {}'.format(*dtstrs(event.get('dtstart'), event.get('dtend'))))
+        print('{} → {}'.format(*dtstrs(event)))
         flags = []
         for k in ('status', 'class', 'transp', 'priority'):
             t = event.get(k)
         flags = []
         for k in ('status', 'class', 'transp', 'priority'):
             t = event.get(k)