Commit 487b9894 authored by Robert Sebille's avatar Robert Sebille
Browse files

workaround refactoring part I

parent 3e62fb44
List errors
AaaaHorodatage
2 : utc_seconds not in range -43200 >= utc_seconds <= +50400 in _convert_utc_seconds2string
2 : utc_seconds not in range -43200 >= utc_seconds <= +50400 in _convert_offset_seconds2string
3 : range error for year, month, day, hour, minute or second input in encode
4 : missing *offset argument in set_utc_local_offset
5 : *offset must be a string or an integer in set_utc_local_offset.
......
......@@ -13,21 +13,28 @@ __Below, in the same directory as this README file__
>>> <new instance> = AaaaHorodatageTools()
>>> <your code>
### Timezones
## Timezones
### Setting your timezone
Your local timezone is stored in _utc_local_offset_ attribute
Default is +7200 seconds, that is to say +02:00; Europe/Brussels summertime
_utc_local_offset_ range: -43200 >= _utc_seconds_ <= +50400
You can use _get_utc_local_offset_ or _set_utc_local_offset_ public methods to get or set it.
#### Timezones sites
### Converting timezone
You can use _ts2utc(ts)_ and _utc2ts(ts)_ methods to convert timestamps from utc to a specific and from a specific timezone or utc. (_utc2ts(ts)_ is currently under construction).
### Converting offset
You can use offset_seconds2string(offset_seconds)_ and utc_string2seconds(offset_string)_ methods to convert offsets from seconds to string and from string to seconds.
### Timezones sites
Some timezones sites can help you to determine tour timezone.
* [24timezones](https://24timezones.com/);
* [Time.is](https://time.is/time_zones)
* [Time_zone](https://en.wikipedia.org/wiki/Time_zone) on Wikipedia.
### Reference epoch
## Reference epoch
the reference epoch of the AaaaHorodatage class stored in _epoch_ class attribute
Default is 1900. Range: 0 <= _epoch_ <= 9999.
......@@ -36,7 +43,7 @@ You can use _get_epoch_ or _set_epoch_ class methods to get or set it.
Please, be consistent with yourself! e.g., you must encode and decode the same timestamp with the same epoch; or the results will be incoherent. It's why this method is a class method.
Remember this: The only way to know what is the reference epoch of a time stamp, is to remember it.
### Help:
## Help:
import aaaa.ahordattools
help(aaaa.ahordattools)
......
......@@ -68,17 +68,17 @@ class AaaaHorodatage:
ljm = property(_get_ljm)
# méthodes
def _utc_seconds2string(self, utc_seconds=0):
if utc_seconds < -43200 or utc_seconds > +50400:
def _offset_seconds2string(self, offset_seconds=0):
if offset_seconds < -43200 or offset_seconds > +50400:
print("Fatal error: utc_seconds not in range -43200 >= utc_seconds\
<= +50400 in _utc_seconds2string")
<= +50400 in _offset_seconds2string")
sys.exit(2)
chaineoffset = "+"
if utc_seconds < 0:
if offset_seconds < 0:
chaineoffset = "-"
abs_utc_seconds = math.fabs(utc_seconds)
heures = int(abs_utc_seconds / (60 * 60))
minutes = int((abs_utc_seconds % 3600) / 60)
abs_offset_seconds = math.fabs(offset_seconds)
heures = int(abs_offset_seconds / (60 * 60))
minutes = int((abs_offset_seconds % 3600) / 60)
if heures < 10:
chaineoffset += "0"
chaineoffset += str(heures) + ":"
......@@ -87,8 +87,8 @@ class AaaaHorodatage:
chaineoffset += str(minutes)
return chaineoffset
def _utc_string2seconds(self, utc_string="+00:00"):
tmp = utc_string.split(":")
def _offset_string2seconds(self, offset_string="+00:00"):
tmp = offset_string.split(":")
retour = int(tmp[0]) * 3600
if retour > 0:
retour += int(tmp[1]) * 60
......@@ -150,7 +150,7 @@ class AaaaHorodatage:
# On ajoute l'offset UTC (local ou Z) sous forme de chaine
self.ts = str(self.ts) + "Z" + self.get_utc_local_offset("string")
if self.utc:
self.ts = self.ts_local2utc(self.ts)
self.ts = self.ts2utc(self.ts)
# print (annee, " bissextile = ", self.bis)
# print (self.ts, " est l'horodatage pour le ", self.jour, "/", \
......@@ -296,7 +296,7 @@ class AaaaHorodatage:
"""
retour = self.utc_local_offset
if typ == "string":
retour = self._utc_seconds2string(self.utc_local_offset)
retour = self._offset_seconds2string(self.utc_local_offset)
return retour
def set_utc_local_offset(self, *offset):
......@@ -317,7 +317,7 @@ class AaaaHorodatage:
sys.exit(5)
offset_candidate = offset[0]
if isinstance(offset[0], str):
offset_candidate = self._utc_string2seconds(offset[0])
offset_candidate = self._offset_string2seconds(offset[0])
if offset_candidate < -43200 or offset_candidate > +50400:
print("Fatal error: utc_local_offset out of rang in ", end="")
print("set_utc_local_offset.")
......@@ -456,20 +456,20 @@ class AaaaHorodatage:
# retour
return self._calcul_decode(typ)
def utc_seconds2string(self, utc_seconds=0):
def offset_seconds2string(self, offset_seconds=0):
"""Return a string, timezone offset in the form +/-HH:MM
utc_seconds = number of seconds, integer.
-43200 >= utc_seconds <= +50400"""
return self._utc_seconds2string(utc_seconds)
return self._offset_seconds2string(offset_seconds)
def utc_string2seconds(self, utc_string="+00:00"):
def offset_string2seconds(self, offset_string="+00:00"):
"""Return a number of seconds (integer)
utc_string: timezone offset in the form +/-HH:MM"""
return self._utc_string2seconds(utc_string)
return self._offset_string2seconds(offset_string)
def ts_local2utc(self, ts):
def ts2utc(self, ts):
"""Convert a local Aaaa timestamp to an UTC."""
ts_list = self.decode("list", ts)
# ts_tmp_list[3] = heure, ts_tmp_list[4] = minutes
......@@ -477,7 +477,7 @@ class AaaaHorodatage:
ts_sec = int(tmp[0])
annee = int(ts_sec % 10000)
ts_sec = int(ts_sec / 10000)
utc_ts = self._utc_string2seconds(tmp[1])
utc_ts = self._offset_string2seconds(tmp[1])
# test pour 31/12 ou 1/1
ts_secondes_extremes = (ts_list[3] * 3600) + (ts_list[3] * 60)
......
......@@ -119,8 +119,8 @@ class AaaaHorodatageTools(AaaaHorodatage):
" does not match offset UTC2" + ts2_split[1] +
"\nProgram halted.")
print("Consider to standardize the 2 timestamps to Z (+00:00)")
print(" using <instance>.ts_local2utc(timestamp1)")
print(" using <instance>.ts_local2utc(timestamp2)")
print(" using <instance>.ts2utc(timestamp1)")
print(" using <instance>.ts2utc(timestamp2)")
sys.exit(51)
# ts2 > ts1 => sens diff = +, sinon -
self.ts1 = int(ts1_split[0])
......
......@@ -75,7 +75,7 @@ list or dict.\nFor exemples with your timestamp above:")
myKbTestTrue))
print("\nI can convert a local ts timestamp in an UTC timestamp too:")
myTsTestTrue = kb.ts_local2utc(myKbtest)
myTsTestTrue = kb.ts2utc(myKbtest)
print("\tI convert local ts " + myKbtest + " to UTC " + myTsTestTrue)
print("\tDecoding this UTC timestamp: ")
print("\tFrom ", kb.decode("string", myKbtest), " to ",
......
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