Skip to content

Commit

Permalink
Fixes #50
Browse files Browse the repository at this point in the history
Add strict-mode handling for parsing DATE-TIME, and ignore leading
spaces if not strict.
  • Loading branch information
da4089 committed Aug 12, 2024
1 parent e59d9f5 commit 5bf5f08
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
23 changes: 23 additions & 0 deletions test_files/vobject_0050.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

BEGIN:VCALENDAR
PRODID:-//Force.com Labs//iCalendar Export//EN
VERSION:2.0
METHOD: REQUEST
CALSCALE:GREGORIAN
BEGIN:VEVENT
STATUS:CONFIRMED
ORGANIZER;CN=Wells Fargo and Company:mailto:appointments@wellsfargo.com
UID:appointments@wellsfargo.com
LOCATION:POJOAQUE
CREATED:20240812T192015Z
DTSTART:20240812T213000Z
DTEND: 20240812T223000Z
TRANSP:OPAQUE
DURATION:PT60M
SUMMARY:Personal: Open a new account
DTSTAMP:20240812T192015Z
LAST-MODIFIED:20240812T192015Z
SEQUENCE:0
DESCRIPTION:Personal: Open a new account
END:VEVENT
END:VCALENDAR
11 changes: 11 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,17 @@ def test_recurrence_offset_naive(self):
self.assertEqual(dates[1], datetime.datetime(2013, 1, 24, 0, 0))
self.assertEqual(dates[-1], datetime.datetime(2013, 3, 28, 0, 0))

def test_issue50(self):
"""
Ensure leading spaces in a DATE-TIME value are ignored when not in
strict mode.
See https://github.com/py-vobject/vobject/issues/50
"""
test_file = get_test_file("vobject_0050.ics")
cal = base.readOne(test_file)
self.assertEqual(datetime.datetime(2024, 8, 12, 22, 30, tzinfo=tzutc()), cal.vevent.dtend.value)


class TestChangeTZ(unittest.TestCase):
"""
Expand Down
5 changes: 4 additions & 1 deletion vobject/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,10 +1726,13 @@ def stringToDate(s):
return datetime.date(year, month, day)


def stringToDateTime(s, tzinfo=None):
def stringToDateTime(s, tzinfo=None, strict=False):
"""
Returns datetime.datetime object.
"""
if not strict:
s = s.strip()

try:
year = int(s[0:4])
month = int(s[4:6])
Expand Down

0 comments on commit 5bf5f08

Please sign in to comment.