Skip to content

Commit

Permalink
metomi#27: parsing: assume local time zone by default
Browse files Browse the repository at this point in the history
  • Loading branch information
benfitzpatrick committed May 1, 2014
1 parent d8f6db9 commit c213030
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 17 additions & 5 deletions isodatetime/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from . import data
from . import dumpers
from . import parser_spec
from . import timezone


class ISO8601SyntaxError(ValueError):
Expand Down Expand Up @@ -127,8 +128,15 @@ class TimePointParser(object):
is not allowed, and must be written as "20000102T011402".
assume_utc (default False) specifies that dates and times without
timezone information should be assumed UTC (Z). Otherwise, these
will be converted to the local timezone.
time zone information should be assumed UTC (Z). If assume_utc and
assume_unknown_time_zone are both False, the local time zone will
be used. If they are both True, assume_utc will take precedence.
assume_unknown_time_zone (default False) specifies that dates and
times without time zone information should be left with an unknown
time zone setting, unless assume_utc is True. If assume_utc and
assume_unknown_time_zone are both False, the local time zone will
be used. If they are both True, assume_utc will take precedence.
dump_format (default None) specifies a default custom dump format
string for TimePoint instances. See data.TimePoint documentation
Expand All @@ -140,11 +148,13 @@ def __init__(self, num_expanded_year_digits=2,
allow_truncated=False,
allow_only_basic=False,
assume_utc=False,
assume_unknown_time_zone=False,
dump_format=None):
self.expanded_year_digits = num_expanded_year_digits
self.allow_truncated = allow_truncated
self.allow_only_basic = allow_only_basic
self.assume_utc = assume_utc
self.assume_unknown_time_zone = assume_unknown_time_zone
self.dump_format = dump_format
self._generate_regexes()

Expand Down Expand Up @@ -474,9 +484,6 @@ def get_info(self, timepoint_string):
timezone_expr = ""
timezone_info = (
self.process_timezone_info(timezone_info))
if self.assume_utc:
timezone_info["time_zone_hour"] = 0
timezone_info["time_zone_minute"] = 0
else:
timezone_expr, timezone_info = self.get_timezone_info(
timezone,
Expand All @@ -496,6 +503,11 @@ def process_timezone_info(self, timezone_info):
if self.assume_utc:
timezone_info["time_zone_hour"] = 0
timezone_info["time_zone_minute"] = 0
elif not self.assume_unknown_time_zone:
utc_hour_offset, utc_minute_offset = (
timezone.get_timezone_for_locale())
timezone_info["time_zone_hour"] = utc_hour_offset
timezone_info["time_zone_minute"] = utc_minute_offset
return timezone_info
if timezone_info.pop("time_zone_sign", "+") == "-":
timezone_info["time_zone_hour"] = (
Expand Down
3 changes: 2 additions & 1 deletion isodatetime/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@ def test_timepoint_dumper(self):

def test_timepoint_parser(self):
"""Test the parsing of date/time expressions."""
parser = parsers.TimePointParser(allow_truncated=True)
parser = parsers.TimePointParser(allow_truncated=True,
assume_unknown_time_zone=True)
for expression, timepoint_kwargs in get_timepointparser_tests(
allow_truncated=True):
timepoint_kwargs = copy.deepcopy(timepoint_kwargs)
Expand Down

0 comments on commit c213030

Please sign in to comment.