skarim / vobject

A full-featured Python package for parsing and creating iCalendar and vCard files
https://vobject.sameenkarim.com
258 stars 93 forks source link

please parse slightly wrong-formatted timestamps #165

Open dorchain opened 3 years ago

dorchain commented 3 years ago

Hi,

I found a server ( https://www.officeholidays.com/ics/germany/) that returns calendar entries with timestamps like this: 20210402T63058Z Obviously this is not a valid DATE-TIME. IMHO this is meant to be 20210402T063058Z (Note the 0 after the T for 2 digit hour)

Please consider autocorrecting this, e.g. with the patch below:

--- icalendar.py.orig   2021-04-02 14:07:52.618401523 +0200
+++ icalendar.py        2021-04-02 14:09:18.279702313 +0200
@@ -1727,6 +1727,10 @@
     """
     Returns datetime.datetime object.
     """
+    t=s[9:]
+    # assume the missing digit is a 0 in front of the hour
+    if len(t.split('Z')[0]) < 6:
+        s = s[:9] + '0' + t
     try:
         year = int(s[0:4])
         month = int(s[4:6])
da4089 commented 9 months ago

@dorchain, I had a quick look at the latest file from this site, and it appears that they have fixed this problem (although all the timestamps are now either midnight or 080000, so it might be a workaround).

Given that this was clearly a bug on their part, and it's now fixed, I think it's best not to clutter the code with this (now not needed) workaround.

Apologies for the delay in responding, and thanks for the report, nonetheless.