Skip to content

Commit

Permalink
fix: cli does not support DURATION collective#354
Browse files Browse the repository at this point in the history
  • Loading branch information
mamico committed Oct 7, 2022
1 parent 514fb1b commit 7a8d584
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
Minor changes:

- removed deprecated test checks [tuergeist]
- Fix: cli does not support DURATION #354 [mamico]

Breaking changes:

Expand Down
1 change: 1 addition & 0 deletions docs/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ icalendar contributors
- Robert Spralja <robert.spralja@gmail.com>
- Maurits van Rees <maurits@vanrees.org>
- jacadzaca <vitouejj@gmail.com>
- Mauro Amico <mauro.amico@gmail.com>

Find out who contributed::

Expand Down
16 changes: 11 additions & 5 deletions src/icalendar/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ def view(event):
description = '\n'.join(map(lambda s: s.rjust(len(s) + 5), description))

start = event.decoded('dtstart')
end = event.decoded('dtend', default=start)
duration = end - start
start = start.astimezone(start.tzinfo).strftime('%c')
end = end.astimezone(end.tzinfo).strftime('%c')
if 'duration' in event:
end = event.decoded('dtend', default=start + event.decoded('duration'))
else:
end = event.decoded('dtend', default=start)
duration = event.decoded('duration', default=end - start)
if isinstance(start, datetime):
start = start.astimezone(start.tzinfo)
start = start.strftime('%c')
if isinstance(end, datetime):
end = end.astimezone(end.tzinfo)
end = end.strftime('%c')

return f""" Organizer: {organizer}
Attendees:
Expand Down Expand Up @@ -78,4 +85,3 @@ def main():

if __name__ == '__main__':
main()

18 changes: 18 additions & 0 deletions src/icalendar/tests/test_cli_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
LOCATION:New Amsterdam, 1010 Test Street
DESCRIPTION:Test Description\\nThis one is multiline
END:VEVENT
BEGIN:VEVENT
UID:1
SUMMARY:TEST
DTSTART:20220511
DURATION:P5D
END:VEVENT
END:VCALENDAR
'''

Expand Down Expand Up @@ -57,6 +63,18 @@
Test Description
This one is multiline
Organizer:
Attendees:
Summary : TEST
Starts : Wed May 11 00:00:00 2022
End : Mon May 16 00:00:00 2022
Duration : 5 days, 0:00:00
Location :
Comment :
Description:
'''

class CLIToolTest(unittest.TestCase):
Expand Down

0 comments on commit 7a8d584

Please sign in to comment.