Commit ed950b17 authored by Robert Sebille's avatar Robert Sebille
Browse files

Adaptation README.md à l'époque embarquée + quelques corrections mineures

parent 2580845c
# 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. _The datetime module is used only to get the server's utc local offset, outside the scope of this project._
This program needs python 3 and modules aaaa.ahordat, aaaa.ahordattools.
__Below, in the same directory as this README file__
## AaaaHorodatage format
[0-9]+AAAAZ+/-HH:MM where [0-9]+ = the number of seconds from the epoch until the date entered, AAAA = the epoch of the timestamp, and Z+/-HH:MM the UTC offset (e.g for CEST summertime: Z+02:00). The timezone and epoch are embedded.
__Below, in the same directory as this README.md file__
## Usage
### In a file.py:
from aaaa.ahordattools import AaaaHorodatageTools
......@@ -13,6 +16,15 @@ __Below, in the same directory as this README file__
>>> <new instance> = AaaaHorodatageTools()
>>> <your code>
### Generate timestamps
encode(d="", utc=False) # possible inputs:
d="": keyboard input
d= list, tuple or dictionary.
utc=False: Local UTC offset encoding (see "Setting your timezone")
utc=True: UTC encoding
decode("typ", ts) typ = "string", "list", "dict" ou "dictionary"
## Timezones
### Setting your timezone
Your local timezone is stored in _utc_local_offset_ attribute
......@@ -21,16 +33,15 @@ _utc_local_offset_ range: -43200 >= _utc_seconds_ <= +50400
You can use public methods to get or set it.
get_utc_local_offset()
set_utc_local_offset(*offset)
get_utc_local_offset(typ="") # typ="": default, seconds (integer); typ="string": "+/-HH:MM"
set_utc_local_offset(*offset) # work with encode() Default +02:00
-43200 >= *offset <= +50400 or '-12:00' >= *offset <= '+14:00'
### Converting timezone
You can use methods to convert timestamp from utc to a specific timezone and from a specific timezone to utc.
tz2utc(ts)
utc2tz(ts, *new_offset)
# -43200 >= *new_offset <= +50400 or '-12:00' >= *new_offset <= '+14:00'
utc2tz(ts, *new_offset) # -43200 >= *new_offset <= +50400 or '-12:00' >= *new_offset <= '+14:00'
### Converting offset
You can use this methods to convert offset from seconds to string and from string to seconds.
......@@ -45,21 +56,38 @@ Some timezones sites can help you to determine tour timezone.
* [Time.is](https://time.is/time_zones)
* [Time_zone](https://en.wikipedia.org/wiki/Time_zone) on Wikipedia.
## Reference epoch
## Epoch
the reference epoch of the AaaaHorodatage class stored in _epoch_ class attribute
Default is 1900. Range: 0 <= _epoch_ <= 9999.
Default is 2000. Range: 1000 <= _epoch_ <= 9999.
The epoch attribute is used for encoding timestamps only. For decoding, the script uses the embedded epoch. Timestamp epoch lesser than epoch class attribute are accepted on decoding.
### Setting epoch
You can use this class methods to get or set it.
get_epoch()
set_epoch(num) # 0 <= epoch <= 9999
set_epoch(num) # 1000 <= epoch <= 9999
### Converting epoch
You can change and adapt the embedded epoch of a timestamp.
convert2epoch(self, ts, epoch) # Convert an embedded epoch to an other. 1000 <= epoch <= 9999
## Operations
Operations relate to timestamps of the same UTC offset and at the same epoch only.
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.
diffDays(self, typ="string", ts1=0, ts2=0) # return ts2 - ts1 in days, hours, minutes, seconds.
Offset UTC timestamp 1 must match offset UTC timestamp 2 and epoch timestamp 1 must match epoch timestamp 2.
Return typ =
- "string": return a string (+/-DDTHH:MM:SS). Default.
- "list": return a list (fixed order).
fixed order: sens_difference, day, hour, minutes, seconds.
- "dict" or "dictionary": return a dict (any order).
ts1 = 0: keyboard input.
ts2 = 0 or none: keyboard input.
ts1 and ts2 = none: keyboard inputs
## Opérations
Encode, decode, difference, ... see Help below
_NB: sum, operator +, operator -, ... are "to do"
### To do
sum, operator +, operator -, ... are "to do"
## Help:
import aaaa.ahordattools
......@@ -69,5 +97,5 @@ _NB: sum, operator +, operator -, ... are "to do"
python3 main.py
You can find some thoughts about algorithms in this [pdf document](https://bit.ly/2seHHvU "Horodatage").
__You can find some thoughts about algorithms in this [pdf document](https://bit.ly/2seHHvU "Horodatage").__
......@@ -6,7 +6,7 @@
Timestamp format = [0-9]+AAAAZ+/-HH:MM where [0-9]+ = the number of
seconds from the epoch until the date entered, AAAA = the epoch of
the timestamp, and Z+/-HH:MM the UTC offset (e.g for CEST,
summertime: Z+02:00). The timezone is embedded therefore.
summertime: Z+02:00). The timezone and epoch are embedded.
Class attribute(s)
- epoch: class reference year of the timestamp (only for encoding).
......
......@@ -7,7 +7,7 @@
Timestamp format = [0-9]+AAAAZ+/-HH:MM where [0-9]+ = the number of
seconds from the epoch until the date entered, AAAA = the epoch of
the timestamp, and Z+/-HH:MM the UTC offset (e.g for CEST,
summertime: Z+02:00). The timezone is embedded therefore.
summertime: Z+02:00). The timezone and epoch are embedded.
Class attribute(s)
- epoch: class reference year of the timestamp (only for encoding).
......@@ -173,6 +173,11 @@ class AaaaHorodatageTools(AaaaHorodatage):
return self.retour
def convert2epoch(self, ts, epoch):
"""Convert an embedded epoch to an other
1000 <= epoch <= 9999
"""
ts = self.decode("list", ts)
ts = self.encode(ts, True)
ts = self.decode("list", ts)
......
......@@ -28,6 +28,7 @@ if __name__ == "__main__":
print("+------+\n| DEMO |\n+------+\n")
k = AaaaHorodatageTools()
print("UTC local offset (seconds): ", k.get_utc_local_offset())
print("UTC local offset (string): ", k.get_utc_local_offset("string"))
date_test = [2001, 1, 1, 1, 5, 0]
......@@ -91,4 +92,23 @@ if __name__ == "__main__":
k.set_epoch(2000)
print("Reset epoch to 2000: ", k.get_epoch())
rep = True
while rep:
print("+-----------------------------+")
rep = input("| Press Enter to continue ... |")
rep = False
print("+-----------------------------+")
print("Get local epoch: ", k.get_epoch())
k.set_epoch(1900)
print("Set local epoch to 1900: ", k.get_epoch())
k.set_epoch(2000)
print("Reset epoch to 2000: ", k.get_epoch())
print("date test, epoch 2000: ", myDT, " = ",
k.decode("string", myDT))
myDT1900 = k.convert2epoch(myDT, 1900)
print("Converting date test to epoch 1900: ", k.convert2epoch(myDT, 1900),
" = ", k.decode("string", myDT))
print("epoch attribute = 2000 not changed: ", k.get_epoch())
print("\n+-------------+\n| Goodbye ... |\n+-------------+\n")
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