Skip to content

Commit 0408d10

Browse files
author
Cyril Gandon
committed
fix(datetime): correct divisor in civil_from_days (1461 → 1460)
Fixing #1189
1 parent 4c8521d commit 0408d10

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/datetime/stdlib_datetime.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ pure subroutine civil_from_days(z, y, m, d)
682682
end if
683683
era = int(era64)
684684
doe = int(zz - era64 * 146097_int64)
685-
yoe = (doe - doe/1461 + doe/36524 &
685+
yoe = (doe - doe/1460 + doe/36524 &
686686
- doe/146096) / 365
687687
y = yoe + era * 400
688688
doy = doe - (365*yoe + yoe/4 - yoe/100)

test/datetime/test_datetime.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,19 @@ subroutine test_dt_plus_td(error)
274274
call check(error, res%day == 18, &
275275
"td + dt day should be 18 (commutative)")
276276
if (allocated(error)) return
277+
278+
dt = datetime_type(year=1996, month=2, day=28)
279+
td = timedelta(days=1)
280+
res = td + dt
281+
call check(error, res%year == 1996, &
282+
"dt + td year should be 1996")
283+
if (allocated(error)) return
284+
call check(error, res%month == 2, &
285+
"dt + td month should be 2")
286+
if (allocated(error)) return
287+
call check(error, res%day == 29, &
288+
"dt + td day should be 29")
289+
if (allocated(error)) return
277290
end subroutine test_dt_plus_td
278291

279292
subroutine test_dt_minus_td(error)

0 commit comments

Comments
 (0)