Skip to content

Commit 5a912e1

Browse files
committed
Fix date2longstring rounding issue with seconds overstepped to 60
1 parent 5e4600f commit 5a912e1

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/astro/slam_time.f90

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -572,22 +572,22 @@ end function date2string
572572
character(len=LEN_TIME_STRING_LONG) function date2longstring(date)
573573

574574
type(time_t), intent(in) :: date
575+
type(time_t) :: tmp_date
575576
real(dp) :: second_fraction
576577

577578
! Handle the leading zero issue for floating point numbers (only for the seconds)
578-
second_fraction = nint((date%second-int(date%second))*1E6)*1E-6
579-
if (second_fraction > 0.999999d0) then
580-
! Round to
581-
second_fraction = 0.0d0
582-
! Create an intermediate adjusted date with seconds increased by 1
583-
write(date2longstring,'(i4,2("-",i2.2),"T",2(i2.2,":"),(i2.2,f0.6),"Z")') &
584-
date%year, date%month, date%day, date%hour, &
585-
date%minute, int(date%second) + 1 , second_fraction
586-
else
587-
write(date2longstring,'(i4,2("-",i2.2),"T",2(i2.2,":"),(i2.2,f0.6),"Z")') &
588-
date%year, date%month, date%day, date%hour, &
589-
date%minute, int(date%second), second_fraction
579+
second_fraction = anint((date%second-int(date%second))*1.0d6)/1.0d6
580+
tmp_date%mjd = date%mjd
581+
call mjd2gd(tmp_date)
582+
if (second_fraction > 0.999999d0) then
583+
! Handle rounding to the next second using mjd2gd subroutine
584+
second_fraction = 0.0d0
585+
tmp_date%mjd = date%mjd + 1E-6/sec_per_day
586+
call mjd2gd(tmp_date)
590587
end if
588+
write(date2longstring,'(i4,2("-",i2.2),"T",2(i2.2,":"),i2.2,f0.6),"Z")') &
589+
tmp_date%year, tmp_date%month, tmp_date%day, tmp_date%hour, &
590+
tmp_date%minute, int(tmp_date%second), second_fraction
591591

592592
return
593593

0 commit comments

Comments
 (0)