Skip to content

Commit

Permalink
Merge pull request #163 from spencerkclark/fix-dayofyr
Browse files Browse the repository at this point in the history
Fix dayofyr after timedelta addition issue
  • Loading branch information
jswhit committed Mar 28, 2020
2 parents 3ed852b + 9c9548a commit 9535d9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ cdef tuple add_timedelta(datetime dt, delta, bint (*is_leap)(int), bint julian_g
day += delta_days
delta_days = 0

return (year, month, day, hour, minute, second, microsecond, -1, 1)
return (year, month, day, hour, minute, second, microsecond, -1, -1)

# Add a datetime.timedelta to a cftime.datetime instance with the 360_day calendar.
#
Expand Down Expand Up @@ -1844,7 +1844,7 @@ cdef tuple add_timedelta_360_day(datetime dt, delta):
year += (month - 1) // 12
month = (month - 1) % 12 + 1

return (year, month, day, hour, minute, second, microsecond, -1, 1)
return (year, month, day, hour, minute, second, microsecond, -1, -1)

# Calendar calculations base on calcals.c by David W. Pierce
# http://meteora.ucsd.edu/~pierce/calcalcs
Expand Down
8 changes: 8 additions & 0 deletions test/test_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,5 +1533,13 @@ def test_replace_dayofyr_or_dayofwk_error(date_type, argument):
with pytest.raises(ValueError):
date_type(1, 1, 1).replace(**{argument: 3})


def test_dayofyr_after_timedelta_addition(date_type):
initial_date = date_type(1, 1, 2)
date_after_timedelta_addition = initial_date + timedelta(days=1)
assert initial_date.dayofyr == 2
assert date_after_timedelta_addition.dayofyr == 3


if __name__ == '__main__':
unittest.main()

0 comments on commit 9535d9f

Please sign in to comment.