sot / chandra_time

Convert between various time formats relevant to Chandra.
https://sot.github.io/Chandra.Time
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Add comparison of DateTime() #20

Open jeanconn opened 9 years ago

jeanconn commented 9 years ago

It would perhaps be safer if full comparison operators were supported without explicitly casting to a type.

In [55]: d.date
Out[55]: '2015:167:17:53:01.588'

In [56]: m.date
Out[56]: '2015:168:17:53:10.701'

In [57]: d > m
Out[57]: True

In [58]: d.secs > m.secs
Out[58]: False
taldcroft commented 9 years ago

:+1:

It is scary that this meaningless comparison gives a result.

jeanconn commented 9 years ago

Yes, support or an error would be great

taldcroft commented 9 years ago

Some variation on:

def __ge__(self, other):
    if not isinstance(other, DateTime):
        other = DateTime(other)
    return self - other >= 0