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
ba2dbac0
Commit
ba2dbac0
authored
Jan 12, 2019
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XXX proto: fix timezone handling
parent
efc292d3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
prototype/proto.go
prototype/proto.go
+5
-4
prototype/proto.py
prototype/proto.py
+6
-4
No files found.
prototype/proto.go
View file @
ba2dbac0
...
...
@@ -24,7 +24,7 @@ var (
)
func
main
()
{
flag
.
StringVar
(
&
timezone
,
"timezone"
,
"
UTC
"
,
"Timezone aka `America/Los_Angeles` formatted time-zone"
)
flag
.
StringVar
(
&
timezone
,
"timezone"
,
"
Europe/Paris
"
,
"Timezone aka `America/Los_Angeles` formatted time-zone"
)
flag
.
StringVar
(
&
filename
,
"formats"
,
"./zodbtools/test/testdata/tidrange-formats.txt"
,
"Path of tidrange-formats.txt"
)
flag
.
StringVar
(
&
relative_time_base
,
"relative-time-base"
,
"2009-08-30T19:20:00Z"
,
"Consider relative time as relative to this RFC3339 formatted time"
)
flag
.
Parse
()
...
...
@@ -43,7 +43,7 @@ func main() {
if
err
!=
nil
{
panic
(
err
.
Error
())
}
relative_time_base_time
=
t
relative_time_base_time
=
t
.
In
(
time
.
Local
)
}
// initialize when library
...
...
@@ -74,7 +74,7 @@ func main() {
if
strings
.
Contains
(
timespec
,
"ago"
)
{
preprocessed_timespec
=
preprocessor
.
Replace
(
timespec
)
}
t
,
err
:=
dateparse
.
Parse
Local
(
preprocessed_timespec
)
t
,
err
:=
dateparse
.
Parse
Any
(
preprocessed_timespec
)
if
err
!=
nil
{
r
,
err
:=
w
.
Parse
(
preprocessed_timespec
,
relative_time_base_time
)
if
err
!=
nil
{
...
...
@@ -93,7 +93,8 @@ func main() {
"ERROR timespec:"
,
timespec
,
/* "( preprocessed as", preprocessed_timespec, ")", */
"expected time:"
,
reference
,
"parsed time:"
,
parsed_time
)
"parsed time:"
,
parsed_time
,
)
}
}
...
...
prototype/proto.py
View file @
ba2dbac0
from
__future__
import
print_function
import
argparse
import
datetime
import
os
...
...
@@ -6,6 +7,7 @@ import time
import
dateparser
import
pytz
# this is golang's time.RFC3339
rfc3339_format
=
"%Y-%m-%dT%H:%M:%SZ"
parser
=
argparse
.
ArgumentParser
(
description
=
"Prototype script for tidrange parsing"
)
...
...
@@ -16,7 +18,7 @@ parser.add_argument(
)
parser
.
add_argument
(
"--timezone"
,
default
=
"
UTC
"
,
default
=
"
Europe/Paris
"
,
help
=
"Timezone aka `America/Los_Angeles` formatted time-zone"
,
)
parser
.
add_argument
(
...
...
@@ -26,7 +28,7 @@ parser.add_argument(
)
args
=
parser
.
parse_args
()
dateparser_settings
=
{
"TO_TIMEZONE"
:
"UTC"
}
dateparser_settings
=
{
"TO_TIMEZONE"
:
"UTC"
,
"RETURN_AS_TIMEZONE_AWARE"
:
True
}
# process timezone
os
.
environ
[
"TZ"
]
=
args
.
timezone
...
...
@@ -37,8 +39,8 @@ if args.relative_time_base and args.relative_time_base != "now":
dateparser_settings
[
"RELATIVE_BASE"
]
=
datetime
.
datetime
.
strptime
(
args
.
relative_time_base
,
rfc3339_format
).
replace
(
tzinfo
=
pytz
.
utc
)
# the Z in our format means UTC
tzinfo
=
pytz
.
utc
# the Z in our format means UTC
)
.
astimezone
(
pytz
.
timezone
(
args
.
timezone
))
with
open
(
args
.
formats
,
"r"
)
as
f
:
for
line
in
f
:
...
...
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