Commit 0ff856fb authored by Robert Sebille's avatar Robert Sebille
Browse files

simplification conversion vers posix

parent 407f5467
......@@ -18,11 +18,11 @@ AaaaHorodatage
AaaaHorodatageTools
51 : offset UTC timestamp 1 does not match offset UTC timestamp 2 in diffTs
52 : epoch timestamp 1 does not match epoch timestamp 2 in diffDays
51: offset UTC timestamp 1 does not match offset UTC timestamp 2 in diffTs
52: epoch timestamp 1 does not match epoch timestamp 2 in diffDays
53: number of seconds to substract to big in __sub__(seconds=0).
Substraction < <ts_epoch>-01-01 epoch of the timestamp. Program halted.")
54: aaaa_ts must be an UTC timestamp in convert_utc2posix(aaaa_ts).
Substraction < <ts_epoch>-01-01 epoch of the timestamp. Program halted.")
others
42: existential error 101010. System halted.
......
......@@ -189,11 +189,10 @@ Consider this tips:
### Conversion to and from Posix
ts_object.convert_aaaa_utc2posix(aaaa_ts)
Return a Posix timestamp from an Aaaa timestamp
Aaaa timestamp must be at UTC.
ts_object.convert_aaaa2posix(aaaa_ts)
Return a Posix timestamp (UTC) from an Aaaa timestamp
ts_object.convert_posix2aaaa_utc(posix_ts):
ts_object.convert_posix2aaaa(posix_ts):
Return an Aaaa timestamp from a Posix timestamp
update self.ts
posix_ts will be considered at UTC time.
......
......@@ -281,27 +281,19 @@ class AaaaHorodatageTools(AaaaHorodatage):
"""Convert days + hours + minutes + seconds in seconds"""
return d * self._get_nb_sec_par_jour() + h * 3600 + m * 60 + s
def convert_aaaa_utc2posix(self):
"""Return a Posix timestamp from an Aaaa timestamp
Aaaa timestamp must be at UTC.
"""
def convert_aaaa2posix(self):
"""Return a Posix timestamp (UTC) from an Aaaa timestamp"""
aaaa_ts = self.copy()
aaaa_ts.convert2epoch(1970)
aaaa_ts.tz2utc()
#self.ts = save_local_ts
tmp = aaaa_ts.get_ts().split("Z")
offset_ts_str = tmp[1]
offset_ts_int = self._offset_string2seconds(offset_ts_str)
if offset_ts_int != 0:
print("Fatal error 54: aaaa_ts must be an UTC timestamp in \
convert_utc2posix(self, aaaa_ts)\nprogram halted.")
ts_sec = int(tmp[0])
ts_sec = int(ts_sec / 10000)
return ts_sec
def convert_posix2aaaa_utc(self, posix_ts):
def convert_posix2aaaa(self, posix_ts):
"""Return an Aaaa timestamp from a Posix timestamp
self.ts is updated
......
......@@ -134,18 +134,20 @@ if __name__ == "__main__":
print("+-----------------------------+")
print("Conversion Aaaa timestamps <> Posix timestamp")
myDT1900.convert2epoch(1900)
myDT1900.tz2utc()
print("Remember date test set above to tz UTC and")
print(" ", myDTutc, " = ",
myDTutc.decode())
print(" ", myDT1900, " = ",
myDT1900.decode())
print("I can convert it to a posix timestamp, because it's UTC")
myPosix = myDTutc.convert_aaaa_utc2posix()
myPosix = myDT1900.convert_aaaa2posix()
print("Its posix timestamp is: ", str(myPosix))
print("You can verify it on http://www.unixtime.fr/, choosing UTC time.")
print("My date is unchanged: ", myDTutc, " = ",
myDTutc.decode())
myDTutc.convert_posix2aaaa_utc(myPosix)
print("My date is unchanged: ", myDT1900, " = ",
myDT1900.decode())
myDT1900.convert_posix2aaaa(myPosix)
print("And now, I reconvert ", str(myPosix), " to a Aaaa timestamp ")
print("with epoch unix = 1970 ", myDTutc, " = ", myDTutc.decode())
print("with epoch unix = 1970 ", myDT1900, " = ", myDT1900.decode())
print()
s = AaaaHorodatageTools("server")
......
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