Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodbtools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
zodbtools
Commits
5c61fb41
Commit
5c61fb41
authored
Jan 21, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XXX: proto, compare with RFC3339 with nano-seconds
parent
d88e3215
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
9 deletions
+40
-9
prototype/proto.go
prototype/proto.go
+12
-1
prototype/proto.py
prototype/proto.py
+28
-8
No files found.
prototype/proto.go
View file @
5c61fb41
...
...
@@ -68,6 +68,17 @@ func main() {
if
strings
.
Index
(
line
,
"#"
)
!=
0
&&
line
!=
""
{
parts
:=
strings
.
SplitN
(
line
,
" "
,
3
)
reference
:=
parts
[
0
]
// reference can be in RFC3339Nano or RFC3339 format, but
// different implementations does not produce same output
// ie. python outputs 1985-04-12T23:20:50.5200Z
// golang outputs 1985-04-12T23:20:50.50Z
// so we reformat the date.
reference_time
,
err
:=
time
.
Parse
(
time
.
RFC3339Nano
,
reference
)
if
err
!=
nil
{
panic
(
err
.
Error
())
}
reference
=
reference_time
.
Format
(
time
.
RFC3339Nano
)
timespec
:=
parts
[
2
]
preprocessed_timespec
:=
timespec
...
...
@@ -87,7 +98,7 @@ func main() {
}
}
parsed_time
:=
t
.
UTC
()
.
Format
(
time
.
RFC3339
)
parsed_time
:=
t
.
UTC
()
.
Format
(
time
.
RFC3339
Nano
)
if
parsed_time
!=
reference
{
fmt
.
Println
(
"ERROR timespec:"
,
timespec
,
...
...
prototype/proto.py
View file @
5c61fb41
...
...
@@ -10,8 +10,11 @@ import freezegun
# this is golang's time.RFC3339
rfc3339_format
=
"%Y-%m-%dT%H:%M:%SZ"
# this is golang's time.RFC3339Nano
rfc3339nano_format
=
"%Y-%m-%dT%H:%M:%S.%fZ"
parser
=
argparse
.
ArgumentParser
(
description
=
"Prototype script for tidrange parsing"
)
parser
=
argparse
.
ArgumentParser
(
description
=
"Prototype script for tidrange parsing"
)
parser
.
add_argument
(
"--formats"
,
default
=
"./zodbtools/test/testdata/tidrange-formats.txt"
,
...
...
@@ -29,7 +32,11 @@ parser.add_argument(
)
args
=
parser
.
parse_args
()
dateparser_settings
=
{
"TO_TIMEZONE"
:
"UTC"
,
"RETURN_AS_TIMEZONE_AWARE"
:
True
}
dateparser_settings
=
{
"TO_TIMEZONE"
:
"UTC"
,
"RETURN_AS_TIMEZONE_AWARE"
:
True
,
# "STRICT_PARSING": True
}
# process timezone
os
.
environ
[
"TZ"
]
=
args
.
timezone
...
...
@@ -54,16 +61,29 @@ with open(args.formats, "r") as f:
continue
reference
,
_
,
timespec
=
line
.
split
(
" "
,
2
)
# reference can be in RFC3339Nano or RFC3339 format, but
# different implementations does not produce same output
# ie. python outputs 1985-04-12T23:20:50.5200Z
# golang outputs 1985-04-12T23:20:50.50Z
# so we reformat the date.
try
:
reference_time
=
datetime
.
datetime
.
strptime
(
reference
,
rfc3339nano_format
)
except
ValueError
:
reference_time
=
datetime
.
datetime
.
strptime
(
reference
,
rfc3339_format
)
reference
=
reference_time
.
strftime
(
rfc3339nano_format
)
preprocessed_timespec
=
timespec
if
"ago"
in
timespec
:
preprocessed_timespec
=
timespec
.
replace
(
"."
,
" "
).
replace
(
"_"
,
" "
)
preprocessed_timespec
=
timespec
.
replace
(
"."
,
" "
).
replace
(
"_"
,
" "
)
parsed_time
=
dateparser
.
parse
(
preprocessed_timespec
,
settings
=
dateparser_settings
)
preprocessed_timespec
,
settings
=
dateparser_settings
)
if
parsed_time
:
parsed_time
=
parsed_time
.
astimezone
(
pytz
.
utc
).
strftime
(
rfc3339_format
)
if
parsed_time
!=
reference
:
parsed_time
=
parsed_time
.
astimezone
(
pytz
.
utc
).
strftime
(
rfc3339nano_format
)
if
reference
!=
parsed_time
:
print
(
"ERROR timespec:"
,
timespec
,
...
...
@@ -71,5 +91,5 @@ with open(args.formats, "r") as f:
"expected time:"
,
reference
,
"parsed time:"
,
parsed_time
,
parsed_time
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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