Skip to content

Commit 2946bd6

Browse files
committed
Fix parsing of partial time
1 parent 6ee68b9 commit 2946bd6

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Fixed the `weeks` property for negative `Period` instances.
88
- Fixed `start_of()` methods not setting microseconds to 0.
99
- Fixed errors on some systems when retrieving timezone from clock files.
10+
- Fix parsing of partial time.
1011

1112

1213
## [2.0.1] - 2018-05-10

pendulum/parsing/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Time (optional)
2929
'(?P<time>'
3030
' (?P<timesep>\ )?' # Separator (space)
31-
' (?P<hour>\d{1,2}):(?P<minute>\d{1,2})?:(?P<second>\d{1,2})?' # HH:mm:ss (optional mm and ss)
31+
' (?P<hour>\d{1,2}):(?P<minute>\d{1,2})?(?::(?P<second>\d{1,2}))?' # HH:mm:ss (optional mm and ss)
3232
# Subsecond part (optional)
3333
' (?P<subsecondsection>'
3434
' (?:[.|,])' # Subsecond separator (optional)
@@ -171,7 +171,10 @@ def _parse_common(text, **options):
171171

172172
minute = int(m.group('minute'))
173173

174-
second = int(m.group('second'))
174+
if m.group('second'):
175+
second = int(m.group('second'))
176+
else:
177+
second = 0
175178

176179
# Grabbing subseconds, if any
177180
microsecond = 0

tests/test_parsing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ def test_parse_exact():
6666
assert isinstance(dt, pendulum.Time)
6767
assert_time(dt, 12, 34, 56, 123456)
6868

69+
text = '13:00'
70+
71+
dt = pendulum.parse(text, exact=True)
72+
73+
assert isinstance(dt, pendulum.Time)
74+
assert_time(dt, 13, 0, 0)
75+
6976

7077
def test_parse_duration():
7178
text = 'P2Y3M4DT5H6M7S'

0 commit comments

Comments
 (0)