Skip to content

Commit c0d37bd

Browse files
committed
Fix seconds inaccuracy for past datetimes
Fixes #152
1 parent db0f836 commit c0d37bd

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixed
66

77
- Fixed inaccuracy of `in_days()` method on DST transitions.
8+
- Fixed seconds inaccuracy for past datetimes.
89

910

1011
## [1.3.0] - 2017-09-25

pendulum/_extensions/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import math
23

34
from ..constants import (
45
EPOCH_YEAR,
@@ -27,7 +28,7 @@ def local_time(unix_time, utc_offset, microseconds):
2728
:rtype: tuple
2829
"""
2930
year = EPOCH_YEAR
30-
seconds = int(unix_time)
31+
seconds = math.floor(unix_time)
3132

3233
# Shift to a base year that is 400-year aligned.
3334
if seconds >= 0:

tests/pendulum_tests/test_construct.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import os
44
import pytz
5+
6+
import pendulum
7+
58
from datetime import datetime, timedelta
69
from dateutil import tz
710
from pendulum import Pendulum, PRE_TRANSITION, POST_TRANSITION
@@ -207,3 +210,8 @@ def test_init_fold_is_honored_if_explicit(self):
207210
d = Pendulum(2013, 3, 31, 2, 30, tzinfo='Europe/Paris', fold=1)
208211
self.assertPendulum(d, 2013, 3, 31, 3, 30)
209212
self.assertEqual(d.fold, 1)
213+
214+
def test_second_inaccuracy_on_past_datetimes(self):
215+
dt = pendulum.create(1901, 12, 13, 0, 0, 0, 555555, tz='US/Central')
216+
217+
self.assertPendulum(dt, 1901, 12, 13, 0, 0, 0, 555555)

0 commit comments

Comments
 (0)