isodatetime icon indicating copy to clipboard operation
isodatetime copied to clipboard

Erroneous bounds checking for day of month when using truncated year of decade

Open MetRonnie opened this issue 10 months ago • 0 comments

Cannot create what ought to be a valid truncated TimePoint:

>>> TimePoint(year=2, month_of_year=2, day_of_month=29, truncated=True, truncated_property='year_of_decade')
...
BadInputError: Invalid input (out of bounds): day_of_month: 29

But year of decade = 2 could be a leap year, for example 2012.

Solution

  • Year of decade: 29th Feb is valid if year of decade is divisible by 2
  • Year of century: 29th Feb is valid if year of century is divisible by 4

If fixed, would expect:

>>> trunc_args = {'truncated': True, 'truncated_property': 'year_of_decade'}
>>> TimePoint(year=2, month_of_year=2, day_of_month=29, **trunc_args) + TimePoint(year=2007)
<metomi.isodatetime.data.TimePoint: 2012-02-29T00:00:00Z>

MetRonnie avatar Apr 30 '25 13:04 MetRonnie