Commit 7a03d45f authored by Robert Sebille's avatar Robert Sebille
Browse files

Opérateurs de comparaison

parent 0ff856fb
......@@ -50,7 +50,6 @@ Some methods, i call modifiers, can change this attribute; they will be document
NB: encode year > 9999 with an epoch = 1000 can causes long calculations.
## ts_object
### timestamps copy
Shallow copy, but it's enough, here.
......@@ -154,7 +153,7 @@ Consider this tips:
ts3_object = ts2_object.copy()
ts1_object.set_ts_same_epoch_offset(ts_object3)
diff_ts2_ts1 = ts1_object.diffDays("string", ts3_object.get_ts())
del ts3_object
del ts3_object
### + operator
......@@ -186,7 +185,16 @@ Consider this tips:
- To add seconds to a new timestamp instance:
new_ts_object = ts_object.copy()
new_ts_object - seconds
### Comparison operators
ts_object1 == ts_object2
ts_object1 != ts_object2
ts_object1 < ts_object2
ts_object1 <= ts_object2
ts_object1 > ts_object2
ts_object1 >= ts_object2
### Conversion to and from Posix
ts_object.convert_aaaa2posix(aaaa_ts)
......
......@@ -101,6 +101,48 @@ class AaaaHorodatageTools(AaaaHorodatage):
tmp.ts = self.ts
return tmp
def __eq__(self, ts_object):
"""== operator"""
aaaa = self.copy()
aaaa_posix = aaaa.convert_aaaa2posix()
ts_object_posix = ts_object.convert_aaaa2posix()
return aaaa_posix == ts_object_posix
def __ne__(self, ts_object):
"""!= operator"""
aaaa = self.copy()
aaaa_posix = aaaa.convert_aaaa2posix()
ts_object_posix = ts_object.convert_aaaa2posix()
return aaaa_posix != ts_object_posix
def __gt__(self, ts_object):
"""> operator"""
aaaa = self.copy()
aaaa_posix = aaaa.convert_aaaa2posix()
ts_object_posix = ts_object.convert_aaaa2posix()
return aaaa_posix > ts_object_posix
def __ge__(self, ts_object):
""">= operator"""
aaaa = self.copy()
aaaa_posix = aaaa.convert_aaaa2posix()
ts_object_posix = ts_object.convert_aaaa2posix()
return aaaa_posix >= ts_object_posix
def __lt__(self, ts_object):
"""< operator"""
aaaa = self.copy()
aaaa_posix = aaaa.convert_aaaa2posix()
ts_object_posix = ts_object.convert_aaaa2posix()
return aaaa_posix < ts_object_posix
def __le__(self, ts_object):
"""<= operator"""
aaaa = self.copy()
aaaa_posix = aaaa.convert_aaaa2posix()
ts_object_posix = ts_object.convert_aaaa2posix()
return aaaa_posix <= ts_object_posix
def __str__(self):
"""Return the string self.ts"""
return self.get_ts()
......
......@@ -6,9 +6,7 @@
# https://www.python.org/dev/peps/pep-0008/ #
#############################################
import os
import math
import sys
from aaaa.ahordattools import AaaaHorodatageTools
......@@ -133,6 +131,21 @@ if __name__ == "__main__":
rep = False
print("+-----------------------------+")
print("Comparison operators")
print(myDT.decode(), " == ", myKb.decode(), ": ", myDT == myKb)
print(myDT.decode(), " != ", myKb.decode(), ": ", myDT != myKb)
print(myDT.decode(), " < ", myKb.decode(), ": ", myDT < myKb)
print(myDT.decode(), " <= ", myKb.decode(), ": ", myDT <= myKb)
print(myDT.decode(), " > ", myKb.decode(), ": ", myDT > myKb)
print(myDT.decode(), " >= ", myKb.decode(), ": ", myDT >= myKb)
rep = True
while rep:
print("+-----------------------------+")
rep = input("| Press Enter to continue ... |")
rep = False
print("+-----------------------------+")
print("Conversion Aaaa timestamps <> Posix timestamp")
myDT1900.convert2epoch(1900)
myDT1900.tz2utc()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment