kopia lustrzana https://github.com/collective/icalendar
Merge pull request #450 from collective/issue-318-skip-value-parameter-for-default-date-time
Remove VALUE=DATE-TIME from DTSTART, DTEND, DTSTAMPpull/486/head
commit
5dae2a48b4
|
@ -11,6 +11,9 @@ Minor changes:
|
|||
Ref: #473
|
||||
Fixes: #472
|
||||
[jacadzaca]
|
||||
- Make datetime value shorter by removing the value parameter where possible.
|
||||
Fixes: #318
|
||||
[jacadzaca], [niccokunzmann]
|
||||
|
||||
Breaking changes:
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ identifier (if applicable) are automatically added here::
|
|||
|
||||
>>> lines = event.to_ical().splitlines()
|
||||
>>> assert (
|
||||
... b"DTSTART;TZID=Europe/Vienna;VALUE=DATE-TIME:20101010T100000"
|
||||
... b"DTSTART;TZID=Europe/Vienna:20101010T100000"
|
||||
... in lines)
|
||||
|
||||
|
||||
|
@ -314,7 +314,7 @@ Write to disk::
|
|||
>>> directory = tempfile.mkdtemp()
|
||||
>>> f = open(os.path.join(directory, 'example.ics'), 'wb')
|
||||
>>> f.write(cal.to_ical())
|
||||
570
|
||||
522
|
||||
>>> f.close()
|
||||
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ class vDDDTypes:
|
|||
raise ValueError('You must use datetime, date, timedelta, '
|
||||
'time or tuple (for periods)')
|
||||
if isinstance(dt, datetime):
|
||||
self.params = Parameters({'value': 'DATE-TIME'})
|
||||
self.params = Parameters()
|
||||
elif isinstance(dt, date):
|
||||
self.params = Parameters({'value': 'DATE'})
|
||||
elif isinstance(dt, time):
|
||||
|
@ -297,12 +297,10 @@ class vDDDTypes:
|
|||
elif isinstance(dt, tuple):
|
||||
self.params = Parameters({'value': 'PERIOD'})
|
||||
|
||||
if (isinstance(dt, datetime) or isinstance(dt, time))\
|
||||
and getattr(dt, 'tzinfo', False):
|
||||
tzinfo = dt.tzinfo
|
||||
tzid = tzid_from_dt(dt)
|
||||
if tzid != 'UTC':
|
||||
self.params.update({'TZID': tzid})
|
||||
tzid = tzid_from_dt(dt) if isinstance(dt, (datetime, time)) else None
|
||||
if not tzid is None and tzid != 'UTC':
|
||||
self.params.update({'TZID': tzid})
|
||||
|
||||
self.dt = dt
|
||||
|
||||
def to_ical(self):
|
||||
|
|
|
@ -6,16 +6,16 @@ X-WR-CALNAME:äöü ÄÖÜ €
|
|||
X-WR-RELCALID:12345
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Non-ASCII Test: ÄÖÜ äöü €
|
||||
DTSTART;VALUE=DATE-TIME:20101010T100000Z
|
||||
DTEND;VALUE=DATE-TIME:20101010T120000Z
|
||||
DTSTART:20101010T100000Z
|
||||
DTEND:20101010T120000Z
|
||||
UID:123456
|
||||
CREATED;VALUE=DATE-TIME:20101010T000000Z
|
||||
CREATED:20101010T000000Z
|
||||
DESCRIPTION:icalendar should be able to de/serialize non-ascii.
|
||||
LOCATION:Tribstrül
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:åäö
|
||||
DTSTART;VALUE=DATE-TIME:20101010T000000Z
|
||||
DTSTART:20101010T000000Z
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DESCRIPTION:äöüßÄÖÜ
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
"""Some parameters are specified as default by the RFC 5545.
|
||||
|
||||
These tests make sure that these parameter values are not added to the
|
||||
properties.
|
||||
|
||||
Example:
|
||||
|
||||
DTSTART;VALUE=DATE-TIME:20190616T050000Z
|
||||
equals DTSTART:20190616T050000Z
|
||||
"""
|
||||
import pytest
|
||||
from icalendar import Event
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@pytest.mark.parametrize("attr", [
|
||||
"DTSTART",
|
||||
"DTEND",
|
||||
"DTSTAMP",
|
||||
])
|
||||
def test_datetime_in_event(attr):
|
||||
"""Check that the "VALUE=DATE-TIME" is absent because not needed."""
|
||||
event = Event()
|
||||
event.add(attr, datetime(2022, 10, 13, 9, 16, 42))
|
||||
ics = event.to_ical()
|
||||
assert b"VALUE=DATE-TIME" not in ics
|
||||
|
|
@ -124,8 +124,8 @@ def test_timezones_to_ical_is_inverse_of_from_ical(timezones):
|
|||
assert timezone.to_ical() == timezone.raw_ics
|
||||
|
||||
@pytest.mark.parametrize('date, expected_output', [
|
||||
(datetime(2012, 7, 16, 0, 0, 0), b'DTSTART;VALUE=DATE-TIME:20120716T000000Z'),
|
||||
(datetime(2021, 11, 17, 15, 9, 15), b'DTSTART;VALUE=DATE-TIME:20211117T150915Z')
|
||||
(datetime(2012, 7, 16, 0, 0, 0), b'DTSTART:20120716T000000Z'),
|
||||
(datetime(2021, 11, 17, 15, 9, 15), b'DTSTART:20211117T150915Z')
|
||||
])
|
||||
def test_no_tzid_when_utc(utc, date, expected_output):
|
||||
'''Issue #58 - TZID on UTC DATE-TIMEs
|
||||
|
|
|
@ -149,21 +149,21 @@ class TestTimezoned(unittest.TestCase):
|
|||
test_out = test_out.decode('utf-8')
|
||||
|
||||
vtimezone_lines = "BEGIN:VTIMEZONE|TZID:Europe/Vienna|X-LIC-LOCATION:"
|
||||
"Europe/Vienna|BEGIN:STANDARD|DTSTART;VALUE=DATE-TIME:19701025T03"
|
||||
"Europe/Vienna|BEGIN:STANDARD|DTSTART:19701025T03"
|
||||
"0000|RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10|RRULE:FREQ=YEARLY;B"
|
||||
"YDAY=-1SU;BYMONTH=3|TZNAME:CET|TZOFFSETFROM:+0200|TZOFFSETTO:+01"
|
||||
"00|END:STANDARD|BEGIN:DAYLIGHT|DTSTART;VALUE=DATE-TIME:19700329T"
|
||||
"00|END:STANDARD|BEGIN:DAYLIGHT|DTSTART:19700329T"
|
||||
"020000|TZNAME:CEST|TZOFFSETFROM:+0100|TZOFFSETTO:+0200|END:DAYLI"
|
||||
"GHT|END:VTIMEZONE"
|
||||
self.assertTrue(vtimezone_lines in test_out)
|
||||
|
||||
test_str = "DTSTART;TZID=Europe/Vienna;VALUE=DATE-TIME:20120213T100000"
|
||||
test_str = "DTSTART;TZID=Europe/Vienna:20120213T100000"
|
||||
self.assertTrue(test_str in test_out)
|
||||
self.assertTrue("ATTENDEE:sepp" in test_out)
|
||||
|
||||
# ical standard expects DTSTAMP and CREATED in UTC
|
||||
self.assertTrue("DTSTAMP;VALUE=DATE-TIME:20101010T081010Z" in test_out)
|
||||
self.assertTrue("CREATED;VALUE=DATE-TIME:20101010T081010Z" in test_out)
|
||||
self.assertTrue("DTSTAMP:20101010T081010Z" in test_out)
|
||||
self.assertTrue("CREATED:20101010T081010Z" in test_out)
|
||||
|
||||
def test_create_to_ical_zoneinfo(self):
|
||||
cal = icalendar.Calendar()
|
||||
|
@ -232,21 +232,21 @@ class TestTimezoned(unittest.TestCase):
|
|||
test_out = test_out.decode('utf-8')
|
||||
|
||||
vtimezone_lines = "BEGIN:VTIMEZONE|TZID:Europe/Vienna|X-LIC-LOCATION:"
|
||||
"Europe/Vienna|BEGIN:STANDARD|DTSTART;VALUE=DATE-TIME:19701025T03"
|
||||
"Europe/Vienna|BEGIN:STANDARD|DTSTART:19701025T03"
|
||||
"0000|RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10|RRULE:FREQ=YEARLY;B"
|
||||
"YDAY=-1SU;BYMONTH=3|TZNAME:CET|TZOFFSETFROM:+0200|TZOFFSETTO:+01"
|
||||
"00|END:STANDARD|BEGIN:DAYLIGHT|DTSTART;VALUE=DATE-TIME:19700329T"
|
||||
"00|END:STANDARD|BEGIN:DAYLIGHT|DTSTART:19700329T"
|
||||
"020000|TZNAME:CEST|TZOFFSETFROM:+0100|TZOFFSETTO:+0200|END:DAYLI"
|
||||
"GHT|END:VTIMEZONE"
|
||||
self.assertTrue(vtimezone_lines in test_out)
|
||||
|
||||
test_str = "DTSTART;TZID=Europe/Vienna;VALUE=DATE-TIME:20120213T100000"
|
||||
test_str = "DTSTART;TZID=Europe/Vienna:20120213T100000"
|
||||
self.assertTrue(test_str in test_out)
|
||||
self.assertTrue("ATTENDEE:sepp" in test_out)
|
||||
|
||||
# ical standard expects DTSTAMP and CREATED in UTC
|
||||
self.assertTrue("DTSTAMP;VALUE=DATE-TIME:20101010T081010Z" in test_out)
|
||||
self.assertTrue("CREATED;VALUE=DATE-TIME:20101010T081010Z" in test_out)
|
||||
self.assertTrue("DTSTAMP:20101010T081010Z" in test_out)
|
||||
self.assertTrue("CREATED:20101010T081010Z" in test_out)
|
||||
|
||||
|
||||
def test_tzinfo_dateutil(self):
|
||||
|
|
|
@ -227,12 +227,12 @@ class TestCalComponent(unittest.TestCase):
|
|||
|
||||
lines = comp.to_ical().splitlines()
|
||||
self.assertTrue(
|
||||
b"DTSTART;TZID=Europe/Vienna;VALUE=DATE-TIME:20101010T100000"
|
||||
b"DTSTART;TZID=Europe/Vienna:20101010T100000"
|
||||
in lines)
|
||||
self.assertTrue(b"CREATED;VALUE=DATE-TIME:20101010T120000Z" in lines)
|
||||
self.assertTrue(b"DTSTAMP;VALUE=DATE-TIME:20101010T120000Z" in lines)
|
||||
self.assertTrue(b"CREATED:20101010T120000Z" in lines)
|
||||
self.assertTrue(b"DTSTAMP:20101010T120000Z" in lines)
|
||||
self.assertTrue(
|
||||
b"LAST-MODIFIED;VALUE=DATE-TIME:20101010T160000Z" in lines
|
||||
b"LAST-MODIFIED:20101010T160000Z" in lines
|
||||
)
|
||||
|
||||
def test_cal_Component_add_no_reencode(self):
|
||||
|
@ -388,7 +388,7 @@ class TestCal(unittest.TestCase):
|
|||
self.assertEqual(
|
||||
cal.subcomponents[0].to_ical(),
|
||||
b'BEGIN:VEVENT\r\nSUMMARY:Python meeting about calendaring\r\n'
|
||||
+ b'DTSTART;VALUE=DATE-TIME:20050404T080000\r\nUID:42\r\n'
|
||||
+ b'DTSTART:20050404T080000\r\nUID:42\r\n'
|
||||
+ b'END:VEVENT\r\n')
|
||||
|
||||
# Write to disc
|
||||
|
|
Ładowanie…
Reference in New Issue