Commit ba2dbac0 authored by Jérome Perrin's avatar Jérome Perrin

XXX proto: fix timezone handling

parent efc292d3
...@@ -24,7 +24,7 @@ var ( ...@@ -24,7 +24,7 @@ var (
) )
func main() { 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(&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.StringVar(&relative_time_base, "relative-time-base", "2009-08-30T19:20:00Z", "Consider relative time as relative to this RFC3339 formatted time")
flag.Parse() flag.Parse()
...@@ -43,7 +43,7 @@ func main() { ...@@ -43,7 +43,7 @@ func main() {
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }
relative_time_base_time = t relative_time_base_time = t.In(time.Local)
} }
// initialize when library // initialize when library
...@@ -74,7 +74,7 @@ func main() { ...@@ -74,7 +74,7 @@ func main() {
if strings.Contains(timespec, "ago") { if strings.Contains(timespec, "ago") {
preprocessed_timespec = preprocessor.Replace(timespec) preprocessed_timespec = preprocessor.Replace(timespec)
} }
t, err := dateparse.ParseLocal(preprocessed_timespec) t, err := dateparse.ParseAny(preprocessed_timespec)
if err != nil { if err != nil {
r, err := w.Parse(preprocessed_timespec, relative_time_base_time) r, err := w.Parse(preprocessed_timespec, relative_time_base_time)
if err != nil { if err != nil {
...@@ -93,7 +93,8 @@ func main() { ...@@ -93,7 +93,8 @@ func main() {
"ERROR timespec:", timespec, "ERROR timespec:", timespec,
/* "( preprocessed as", preprocessed_timespec, ")", */ /* "( preprocessed as", preprocessed_timespec, ")", */
"expected time:", reference, "expected time:", reference,
"parsed time:", parsed_time) "parsed time:", parsed_time,
)
} }
} }
......
from __future__ import print_function
import argparse import argparse
import datetime import datetime
import os import os
...@@ -6,6 +7,7 @@ import time ...@@ -6,6 +7,7 @@ import time
import dateparser import dateparser
import pytz import pytz
# this is golang's time.RFC3339
rfc3339_format = "%Y-%m-%dT%H:%M:%SZ" rfc3339_format = "%Y-%m-%dT%H:%M:%SZ"
parser = argparse.ArgumentParser(description="Prototype script for tidrange parsing") parser = argparse.ArgumentParser(description="Prototype script for tidrange parsing")
...@@ -16,7 +18,7 @@ parser.add_argument( ...@@ -16,7 +18,7 @@ parser.add_argument(
) )
parser.add_argument( parser.add_argument(
"--timezone", "--timezone",
default="UTC", default="Europe/Paris",
help="Timezone aka `America/Los_Angeles` formatted time-zone", help="Timezone aka `America/Los_Angeles` formatted time-zone",
) )
parser.add_argument( parser.add_argument(
...@@ -26,7 +28,7 @@ parser.add_argument( ...@@ -26,7 +28,7 @@ parser.add_argument(
) )
args = parser.parse_args() args = parser.parse_args()
dateparser_settings = {"TO_TIMEZONE": "UTC"} dateparser_settings = {"TO_TIMEZONE": "UTC", "RETURN_AS_TIMEZONE_AWARE": True}
# process timezone # process timezone
os.environ["TZ"] = args.timezone os.environ["TZ"] = args.timezone
...@@ -37,8 +39,8 @@ if args.relative_time_base and args.relative_time_base != "now": ...@@ -37,8 +39,8 @@ if args.relative_time_base and args.relative_time_base != "now":
dateparser_settings["RELATIVE_BASE"] = datetime.datetime.strptime( dateparser_settings["RELATIVE_BASE"] = datetime.datetime.strptime(
args.relative_time_base, rfc3339_format args.relative_time_base, rfc3339_format
).replace( ).replace(
tzinfo=pytz.utc tzinfo=pytz.utc # the Z in our format means UTC
) # the Z in our format means UTC ).astimezone(pytz.timezone(args.timezone))
with open(args.formats, "r") as f: with open(args.formats, "r") as f:
for line in f: for line in f:
......
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