Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Robert Sebille
AaaaHorodatage
Commits
17616b8a
Commit
17616b8a
authored
Jun 09, 2018
by
Robert Sebille
Browse files
Mise à jour doc + demo
parent
327987fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
17616b8a
...
...
@@ -23,7 +23,10 @@ __Below, in the same directory as this README.md file__
d= list, tuple or dictionary.
utc=False: Local UTC offset encoding (see "Setting your timezone")
utc=True: UTC encoding
self.ts is updated
decode("typ", ts) typ = "string", "list", "dict" ou "dictionary"
ts = timestamp: I will use ts, self.ts will not be modified.
ts = none or "": I will use self.ts.
NB: encode year > 9999 with an epoch = 1000 can causes long calculations.
...
...
@@ -42,8 +45,13 @@ You can use public methods to get or set it.
### 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'
tz2utc(ts) # self.ts is updated
ts = timestamp: I will use ts, self.ts is updated with ts.
ts = none or "": I will use self.ts. It will be updated.
utc2tz(ts, *new_offset) # -43200 >= *new_offset <= +50400 or
'-12:00' >= *new_offset <= '+14:00'. self.ts is updated
ts = timestamp: I will use ts, self.ts is updated with ts.
ts = "": I will use self.ts. It will be updated.
### Converting offset
You can use this methods to convert offset from seconds to string and from string to seconds.
...
...
@@ -72,7 +80,7 @@ You can use this class methods to get or set it.
### 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
convert2epoch(self, ts, epoch) # Convert an embedded epoch to an other. 1000 <= epoch <= 9999
. self.ts is updated.
## Operations
Operations relate to timestamps of the same UTC offset and at the same epoch only.
...
...
@@ -87,6 +95,11 @@ Operations relate to timestamps of the same UTC offset and at the same epoch onl
ts1 = 0: keyboard input.
ts2 = 0 or none: keyboard input.
ts1 and ts2 = none: keyboard inputs
+ operator: new_ts = ts + nb_seconds
Add nb_seconds at timestamp to new_timestamp
Tips: use dhms2second(d=0, h=0, m=0, s=0) method to
convert days + hours + minutes + seconds in seconds
### To do
sum, operator +, operator -, ... are "to do"
...
...
aaaa/ahordat.py
View file @
17616b8a
...
...
@@ -487,21 +487,28 @@ class AaaaHorodatage:
"""Return a string, timezone offset in the form +/-HH:MM
utc_seconds = number of seconds, integer.
-43200 >= utc_seconds <= +50400"""
-43200 >= utc_seconds <= +50400
"""
return
self
.
_offset_seconds2string
(
offset_seconds
)
def
offset_string2seconds
(
self
,
offset_string
=
"+00:00"
):
"""Return a number of seconds (integer)
utc_string: timezone offset in the form +/-HH:MM"""
utc_string: timezone offset in the form +/-HH:MM
"""
return
self
.
_offset_string2seconds
(
offset_string
)
def
tz2utc
(
self
,
ts
):
"""Convert
a
timestamp to an UTC.
def
tz2utc
(
self
,
ts
=
""
):
"""Convert
the
timestamp
ts
to an UTC.
ts > epoch
ts = timestamp: I will use ts, self.ts is updated with ts.
ts = none or "": I will use self.ts. It will be updated.
"""
if
ts
==
""
:
ts
=
self
.
ts
ts_list
=
self
.
decode
(
"list"
,
ts
)
# ts_tmp_list[3] = heure, ts_tmp_list[4] = minutes
tmp
=
ts
.
split
(
"Z"
)
...
...
@@ -519,13 +526,17 @@ class AaaaHorodatage:
return
self
.
ts
def
utc2tz
(
self
,
ts
,
*
new_offset
):
def
utc2tz
(
self
,
ts
=
""
,
*
new_offset
):
"""Convert a timestamp UTC to an other timezone.
Avalaible inputs:
- Number of seconds (-43200 >= *new_offset <= +50400)
- String (+/-HH:MM) ("-12:00" >= *new_offset <= "+14:00")
ts = timestamp: I will use ts, self.ts is updated with ts.
ts = "": I will use self.ts. It will be updated.
"""
if
len
(
new_offset
)
<
1
:
print
(
"Fatal error 7: missing *new_offset argument in "
,
end
=
""
)
...
...
@@ -546,6 +557,8 @@ class AaaaHorodatage:
print
(
"or '-12:00' >= *new_offset <= '+14:00'."
)
sys
.
exit
(
9
)
if
ts
==
""
:
ts
=
self
.
ts
ts_list
=
self
.
decode
(
"list"
,
ts
)
# ts_tmp_list[3] = heure, ts_tmp_list[4] = minutes
tmp
=
ts
.
split
(
"Z"
)
...
...
aaaa/ahordattools.py
View file @
17616b8a
...
...
@@ -79,6 +79,9 @@ class AaaaHorodatageTools(AaaaHorodatage):
AaaaHorodatage
.
__init__
(
self
)
# Special #
def
__str__
(
self
):
return
self
.
get_ts
()
def
__add__
(
self
,
seconds
=
0
):
"""Add seconds to timestamps
...
...
@@ -191,6 +194,7 @@ class AaaaHorodatageTools(AaaaHorodatage):
"""Convert an embedded epoch to an other
1000 <= epoch <= 9999
self.ts is updated
"""
ts
=
self
.
decode
(
"list"
,
ts
)
...
...
@@ -200,7 +204,8 @@ class AaaaHorodatageTools(AaaaHorodatage):
self
.
set_epoch
(
epoch
)
ts
=
self
.
encode
(
ts
)
self
.
set_epoch
(
save_epoch
)
return
ts
self
.
ts
=
ts
return
self
.
ts
def
dhms2seconds
(
self
,
d
=
0
,
h
=
0
,
m
=
0
,
s
=
0
):
"""Convert days + hours + minutes + seconds in seconds"""
...
...
main.py
View file @
17616b8a
...
...
@@ -76,6 +76,9 @@ if __name__ == "__main__":
print
(
"You have encoded: "
,
k
.
decode
(
"string"
,
myKb
))
print
(
"You minus me: "
,
k
.
diffDays
(
"string"
,
myDT
,
myKb
))
print
(
"Me minus you: "
,
k
.
diffDays
(
"string"
,
myKb
,
myDT
))
print
(
"And now: "
,
k
.
decode
(),
" + 1T01:10:20"
)
k2
=
k
+
k
.
dhms2seconds
(
1
,
1
,
10
,
20
)
print
(
" = "
,
k2
.
decode
())
print
(
"
\n
Play attention to epoch ..."
)
rep
=
True
...
...
@@ -115,6 +118,5 @@ if __name__ == "__main__":
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
(
k
.
__dict__
)
print
(
"
\n
+-------------+
\n
| Goodbye ... |
\n
+-------------+
\n
"
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment