metomi / isodatetime

:date: :watch: Python ISO 8601 date time parser and data model/manipulation utilities
GNU Lesser General Public License v3.0
37 stars 20 forks source link

Inconsistency between truncated dates and truncated times #212

Open MetRonnie opened 2 years ago

MetRonnie commented 2 years ago

When adding a truncated TimePoint to a regular TimePoint, if the truncated one specifies a date, all units smaller than the ones provided are not taken into account, whereas if it specifies a time, the smaller units are implicitly zero.

>>> parser = TimePointParser(allow_truncated=True)
>>> regular = parser.parse("2010-08-08T15:40:13Z")
>>> truncated_date = parser.parse("--10")  # month = 10 (October)
>>> regular + truncated_date
<metomi.isodatetime.data.TimePoint: 2010-10-08T15:40:13Z>

Note how the day of month and time from the regular TimePoint are retained

>>> truncated_time = parser.parse("T19")
>>> regular + truncated_time
<metomi.isodatetime.data.TimePoint: 2010-08-08T19:00:00Z>

Note how the minutes and seconds have gone to zero, as if they were taken from the truncated TimePoint which is assumed to be equivalent to T19:00:00.

To me, it seems debatable which is the correct approach for addition of regular and truncated TimePoints, but at least the approach should be consistent.