Skip to content

Commit 38dc925

Browse files
committed
Fixes instantiation of Transitions with negative timestamps on Windows
1 parent 95ab67d commit 38dc925

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pendulum/tz/transition.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from datetime import datetime
3+
from datetime import datetime, timedelta
44

55

66
class Transition(object):
@@ -16,6 +16,8 @@ class Transition(object):
1616
- the local time after the transition.
1717
"""
1818

19+
_epoch = datetime.utcfromtimestamp(0)
20+
1921
def __init__(self, unix_time,
2022
transition_type_index, pre_time, time,
2123
pre_transition_type_index):
@@ -41,7 +43,9 @@ def __init__(self, unix_time,
4143
self._transition_type_index = transition_type_index
4244
self._pre_time = pre_time
4345
self._time = time
44-
self._utc_time = datetime.utcfromtimestamp(unix_time)
46+
# We can't directly make datetime.utcfromtimestamp(unix_time)
47+
# since it will fail on Windows for negative timestamps.
48+
self._utc_time = self._epoch + timedelta(seconds=unix_time)
4549
self._pre_transition_type_index = pre_transition_type_index
4650

4751
@property

0 commit comments

Comments
 (0)