Skip to content

Cannot subtract truncated TimePoint from regular TimePoint #211

@MetRonnie

Description

@MetRonnie

It is possible to add a truncated TimePoint to a regular one (although that has a bug: #80). However, when trying to subtract a truncated TimePoint from a regular one:

File ~/metomi/isodatetime/data.py:1700, in TimePoint.__sub__(self, other)
   1698 def __sub__(self, other):
   1699     if isinstance(other, TimePoint):
-> 1700         if other > self:

File ~/metomi/isodatetime/data.py:1693, in TimePoint.__gt__(self, other)
   1692 def __gt__(self, other: "TimePoint") -> bool:
-> 1693     return self._cmp(other, "gt")

File ~/metomi/isodatetime/data.py:1659, in TimePoint._cmp(self, other, op)
   1657     return NotImplemented
   1658 if self._truncated != other._truncated:
-> 1659     raise ValueError(
   1660         "Cannot compare truncated to non-truncated "
   1661         "TimePoint: {0}, {1}".format(self, other))

ValueError: Cannot compare truncated to non-truncated TimePoint: -17T1200Z, 2022-04-20T11:12:00+01:00

But it should be possible to do this. Cylc has its own implementation: https://github.com/cylc/cylc-flow/blob/5361c428d7e4ad9faa6152cdf2c59f259077fbee/cylc/flow/cycling/iso8601.py#L747

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions