Commit 92cbc83e authored by Robert Sebille's avatar Robert Sebille
Browse files

Complément de doc et quelques aménagements mineurs

parent 69112b3b
# AaaaHorodatage
This program is under GNU General Public License, version 3, see LICENCE text file.<br />
This program needs python 3 and modules datetime, aaaa.ahordat, aaaa.ahordattools
This program needs python 3 and modules datetime, aaaa.ahordat, aaaa.ahordattools. _The datetime module is used only to get the server's utc local offset, outside the scope of this project._
__Below, in the same directory as this README file__
## Usage
......@@ -20,3 +20,6 @@ __Below, in the same directory as this README file__
## Short demo
python3 main.py
You can find some thoughts on algorithms in this [pdf document](https://bit.ly/2seHHvU "Horodatage").
......@@ -3,10 +3,10 @@
"""Encoding and decoding module for timestamps of AaaaHorodatage class.
Timestamp format = SAAAAZ+/-HH:MM where S = the number of seconds
from the epoch until the date entered, AAAA = the year of the timestamp,
and Z+/-HH:MM the UTC offset (e.g for CEST, summertime: Z+02:00).
The timezone is embedded therefore.
Timestamp format = [0-9]*AAAAZ+/-HH:MM where [0-9]* = the number of
seconds from the epoch until the date entered, AAAA = the year of the
timestamp, and Z+/-HH:MM the UTC offset (e.g for CEST, summertime:
Z+02:00). The timezone is embedded therefore.
Class attribute(s)
- epoch: class reference year of the timestamp.
......@@ -57,7 +57,7 @@ class AaaaHorodatage:
self.utc_server_offset =\
math.ceil(datetime.timestamp(datetime.now()) -
datetime.timestamp(datetime.utcnow()))
# self.utc_server_offset = 8100
# self.utc_server_offset = -8100
# private
# Liste nombre de jours par mois, moins décembre et année non bissextile
self._ljm = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
......@@ -163,7 +163,7 @@ class AaaaHorodatage:
def _calcul_decode(self, typ):
"""Decode the timestamp."""
# Largage du timestamp
# Récupération et largage du timestamp
self.utc = self.ts.split("Z")
self.ts = int(self.utc[0])
self.utc = str(self.utc[1])
......@@ -267,14 +267,22 @@ class AaaaHorodatage:
or the results will be incoherent. It's why this method is a
class method.
+--- Please, remember this: --------------------------+
| The only way to know what is the reference epoch of |
| a time stamp, is to remember it |
+-----------------------------------------------------+
"""
if num >= 0 and num < 10000:
cls.epoch = int(num)
print("epoch is now set to", str(cls.get_epoch()))
print("""+--- Please, remember this: --------------------------+
| The only way to know what is the reference epoch of |
| a time stamp, is to remember it |
+-----------------------------------------------------+""")
else:
print("Error: ", cls.__class__.__name__, ".set_epoch(0 ... 9999)\
= ", str(num), ". ", cls.__class__.__name__,
".epoch now set to ", cls.epoch,
sep="")
print("Error: set_epoch(0 ... 9999) = ", str(num), ". ",
"epoch now set to ", cls.epoch, ".", sep="")
set_epoch = classmethod(set_epoch)
......@@ -437,24 +445,24 @@ class AaaaHorodatage:
def ts_local2utc(self, ts):
"""Convert a local Aaaa timestamp to an UTC."""
ts_tmp_list = self.decode("list", ts)
ts_list = self.decode("list", ts)
# ts_tmp_list[3] = heure, ts_tmp_list[4] = minutes
tmp = ts.split("Z")
ts_tmp = int(tmp[0])
an_tmp = int(ts_tmp % 10000)
ts_tmp = int(ts_tmp / 10000)
utc_tmp = self._utc_string2seconds(tmp[1])
ts_sec = int(tmp[0])
annee = int(ts_sec % 10000)
ts_sec = int(ts_sec / 10000)
utc_ts = self._utc_string2seconds(tmp[1])
# test pour 31/12 ou 1/1
ts_secondes_extremes = (ts_tmp_list[3] * 3600) + (ts_tmp_list[3] * 60)
if utc_tmp < 0 and (ts_secondes_extremes + int(math.fabs(utc_tmp))) >\
ts_secondes_extremes = (ts_list[3] * 3600) + (ts_list[3] * 60)
if utc_ts < 0 and (ts_secondes_extremes + int(math.fabs(utc_ts))) >\
86400:
an_tmp += 1
if utc_tmp > 0 and (ts_secondes_extremes - int(math.fabs(utc_tmp))) < 0:
an_tmp -= 1
annee += 1
if utc_ts > 0 and (ts_secondes_extremes - int(math.fabs(utc_ts))) < 0:
annee -= 1
ts_tmp -= utc_tmp
return str(ts_tmp) + str(an_tmp) + "Z+00:00"
ts_sec -= utc_ts
return str(ts_sec) + str(annee) + "Z+00:00"
if __name__ == "__main__":
# Pour tester le module ...
......
......@@ -4,10 +4,10 @@
"""Tools for timestamps of AaaaHorodatage class, Child class of
AaaaHorodatage.
Timestamp format = SAAAAZ+/-HH:MM where S = the number of seconds
from the epoch until the date entered, AAAA = the year of the timestamp,
and Z+/-HH:MM the UTC offset (e.g for CEST, summertime: Z+02:00)
The timezone is embedded therefore.
Timestamp format = [0-9]*AAAAZ+/-HH:MM where [0-9]* = the number of
seconds from the epoch until the date entered, AAAA = the year of the
timestamp, and Z+/-HH:MM the UTC offset (e.g for CEST, summertime:
Z+02:00). The timezone is embedded therefore.
Class attribute(s)
- epoch: class reference year of the timestamp.
......@@ -111,7 +111,7 @@ class AaaaHorodatageTools(AaaaHorodatage):
# if arg
# to do
# Récupération des timestamp
# Récupération des timestamp et test des offset utc
ts1_split = self.ts1.split("Z")
ts2_split = self.ts2.split("Z")
if ts1_split[1] != ts2_split[1]:
......
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