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
0ff856fb
Commit
0ff856fb
authored
Jun 13, 2018
by
Robert Sebille
Browse files
simplification conversion vers posix
parent
407f5467
Changes
4
Hide whitespace changes
Inline
Side-by-side
ERRORLIST
View file @
0ff856fb
...
...
@@ -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.
...
...
README.md
View file @
0ff856fb
...
...
@@ -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.
...
...
aaaa/ahordattools.py
View file @
0ff856fb
...
...
@@ -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)
\n
program 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
...
...
main.py
View file @
0ff856fb
...
...
@@ -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
(
" "
,
myDT
utc
,
" = "
,
myDT
utc
.
decode
())
print
(
" "
,
myDT
1900
,
" = "
,
myDT
1900
.
decode
())
print
(
"I can convert it to a posix timestamp, because it's UTC"
)
myPosix
=
myDT
utc
.
convert_aaaa
_utc
2posix
()
myPosix
=
myDT
1900
.
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: "
,
myDT
utc
,
" = "
,
myDT
utc
.
decode
())
myDT
utc
.
convert_posix2aaaa
_utc
(
myPosix
)
print
(
"My date is unchanged: "
,
myDT
1900
,
" = "
,
myDT
1900
.
decode
())
myDT
1900
.
convert_posix2aaaa
(
myPosix
)
print
(
"And now, I reconvert "
,
str
(
myPosix
),
" to a Aaaa timestamp "
)
print
(
"with epoch unix = 1970 "
,
myDT
utc
,
" = "
,
myDT
utc
.
decode
())
print
(
"with epoch unix = 1970 "
,
myDT
1900
,
" = "
,
myDT
1900
.
decode
())
print
()
s
=
AaaaHorodatageTools
(
"server"
)
...
...
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