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

Fix truncated timepoint addition bug #234

Open MetRonnie opened 1 year ago

MetRonnie commented 1 year ago

Closes #80 Closes #212

Built on #203

MetRonnie commented 1 year ago

Note this does not fix https://github.com/cylc/cylc-flow/issues/2382, presumably that is still a bug in cylc-flow

MetRonnie commented 1 year ago

Actually which should the behaviour be?

2019-01-15 + --01-15 = ?
  1. 2019-01-15 - same point (current behaviour)
  2. 2020-01-15 - next matching point (what I think it should be)
MetRonnie commented 1 year ago

Need to investigate Cylc unit test failure with this branch

tests/unit/cycling/test_iso8601.py::test_cug - ValueError: Invalid month of year 1 or day of month None
MetRonnie commented 1 year ago

Actually which should the behaviour be?

2019-01-15 + --01-15 = ?
  1. 2019-01-15 - same point (current behaviour)
  2. 2020-01-15 - next matching point (what I think it should be)

I think we have to maintain the current behaviour to avoid breaking next() in Cylc workflows - see https://github.com/cylc/cylc-flow/pull/5777

(Technically we could change the behaviour here and add a workaround in Cylc, but that's more effort)

MetRonnie commented 11 months ago

Decision on 2019-01-15 + --01-15 (with greater clarity and precision):

The behaviour is to be:

2019-01-15T00:00:00 + --01-15
>>> 2019-01-15T00:00:00  # same datetime (we are exactly at midnight)

2019-01-15T00:00:01 + --01-15
>>> 2020-01-15T00:00:00  # next year 

This is because a truncated datetime should assume 0 for any unspecified time units, and 1 for any unspecified date units lower than what has been specified.

MetRonnie commented 7 months ago

No worries, this has not been a top priority at the moment