Skip to content

Commit

Permalink
Merge pull request arrow-py#308 from bjmc/fixes-307
Browse files Browse the repository at this point in the history
Adds support for tz offsets without minutes
  • Loading branch information
andrewelkins committed Mar 23, 2016
2 parents a7d00b7 + bdf4d86 commit 397994f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Features
- Time zone-aware & UTC by default
- Provides super-simple creation options for many common input scenarios
- Updated .replace method with support for relative offsets, including weeks
- Formats and parses strings, including ISO-8601-formatted strings automatically
- Formats and parses strings automatically
- Partial support for ISO-8601
- Timezone conversion
- Timestamp available as a property
- Generates time spans, ranges, floors and ceilings in timeframes from year to microsecond
Expand Down
6 changes: 4 additions & 2 deletions arrow/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DateTimeParser(object):
_ONE_OR_TWO_DIGIT_RE = re.compile('\d{1,2}')
_FOUR_DIGIT_RE = re.compile('\d{4}')
_TWO_DIGIT_RE = re.compile('\d{2}')
_TZ_RE = re.compile('[+\-]?\d{2}:?\d{2}')
_TZ_RE = re.compile('[+\-]?\d{2}:?(\d{2})?')
_TZ_NAME_RE = re.compile('\w[\w+\-/]+')


Expand Down Expand Up @@ -290,7 +290,7 @@ def _choice_re(choices, flags=0):

class TzinfoParser(object):

_TZINFO_RE = re.compile('([+\-])?(\d\d):?(\d\d)')
_TZINFO_RE = re.compile('([+\-])?(\d\d):?(\d\d)?')

@classmethod
def parse(cls, string):
Expand All @@ -309,6 +309,8 @@ def parse(cls, string):

if iso_match:
sign, hours, minutes = iso_match.groups()
if minutes is None:
minutes = 0
seconds = int(hours) * 3600 + int(minutes) * 60

if sign == '-':
Expand Down
5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Features
- Time zone-aware & UTC by default
- Provides super-simple creation options for many common input scenarios
- Updated .replace method with support for relative offsets, including weeks
- Formats and parses strings, including ISO-8601-formatted strings automatically
- Formats and parses strings automatically
- Partial ISO-8601 support
- Timezone conversion
- Timestamp available as a property
- Generates time spans, ranges, floors and ceilings in time frames from year to microsecond
Expand Down Expand Up @@ -145,7 +146,7 @@ Search a date in a string:
>>> arrow.get('June was born in May 1980', 'MMMM YYYY')
<Arrow [1980-05-01T00:00:00+00:00]>
Many ISO-8601 compliant strings are recognized and parsed without a format string:
Some ISO-8601 compliant strings are recognized and parsed without a format string:

>>> arrow.get('2013-09-30T15:34:00.000-07:00')
<Arrow [2013-09-30T15:34:00-07:00]>
Expand Down
5 changes: 5 additions & 0 deletions tests/parser_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def test_parse_pm(self):
assertEqual(self.parser.parse('12 pm', 'H A'), expected)
assertEqual(self.parser.parse('12 pm', 'h A'), expected)

def test_parse_tz_hours_only(self):
expected = datetime(2025, 10, 17, 5, 30, 10, tzinfo=tz.tzoffset(None, 0))
parsed = self.parser.parse('2025-10-17 05:30:10+00', 'YYYY-MM-DD HH:mm:ssZ')
assertEqual(parsed, expected)

def test_parse_tz_zz(self):

expected = datetime(2013, 1, 1, tzinfo=tz.tzoffset(None, -7 * 3600))
Expand Down

0 comments on commit 397994f

Please sign in to comment.