1.1 --- a/imiptools/dates.py Sun Jan 31 17:18:54 2016 +0100
1.2 +++ b/imiptools/dates.py Sun Feb 07 23:35:20 2016 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Date processing functions.
1.6
1.7 -Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -89,6 +89,19 @@
1.13 else:
1.14 return None
1.15
1.16 +def format_duration(td):
1.17 +
1.18 + "Format the timedelta 'td' as an iCalendar-compatible string."
1.19 +
1.20 + if not td:
1.21 + return None
1.22 + else:
1.23 + day_portion = td.days and "%dD" % td.days or ""
1.24 + time_portion = td.seconds and "T%dS" % td.seconds or ""
1.25 + if not day_portion and not time_portion:
1.26 + time_portion = "T0S"
1.27 + return "P%s%s" % (day_portion, time_portion)
1.28 +
1.29 # Parsing of datetime and related information.
1.30
1.31 def get_datetime(value, attr=None):