@@ -1069,25 +1069,27 @@ end subroutine test_time_comparison_tz
10691069
10701070subroutine test_time_comparison_tz_midnight (error )
10711071 ! ! Tests timezone comparison that crosses midnight:
1072- ! ! 23:00 UTC-05:00 is the same instant as 04:00 UTC
1072+ ! ! 23:00 UTC-05:00 after modulo-24h normalisation maps to
1073+ ! ! 04:00 UTC, which should compare equal to time_type(4,0,0,0,0).
10731074 type (error_type), allocatable , intent (out ) :: error
10741075 type (time_type) :: t1, t2
1075- ! 23:00 UTC-05:00 (UTC ms = 23*3600000 + 5*3600000 = 100800000)
1076- ! 04:00 UTC (UTC ms = 4*3600000 = 14400000)
1077- ! These are not equal as clock-face times on the same day;
1078- ! the comparison is purely by UTC ms since midnight.
1079- ! 23:00-05:00 UTC ms = 28*3600000 = 100800000 (> 24h, no wrap in comparison)
1080- ! 04:00Z UTC ms = 4*3600000 = 14400000
1081- ! They should NOT be equal (different absolute UTC ms values).
1076+ ! time_eq uses time_to_normalized_utc_ms (modulo 86400000 ms).
1077+ ! 23:00 UTC-05:00 raw UTC ms = 100800000
1078+ ! modulo(100800000, 86400000) = 14400000 (04:00 UTC)
1079+ ! 04:00Z raw UTC ms = 14400000
1080+ ! modulo(14400000, 86400000) = 14400000
1081+ ! --> they ARE equal after midnight-wrap normalization.
10821082 t1 = time_type(23 , 0 , 0 , 0 , - 300 ) ! 23:00 UTC-05:00
10831083 t2 = time_type(4 , 0 , 0 , 0 , 0 ) ! 04:00 UTC
1084+ call check(error, t1 == t2, &
1085+ " 23:00-05:00 should equal 04:00Z after midnight-wrap" )
1086+ if (allocated (error)) return
1087+ ! Verify a genuinely different time is NOT equal
1088+ t2 = time_type(5 , 0 , 0 , 0 , 0 ) ! 05:00 UTC
10841089 call check(error, .not. (t1 == t2), &
1085- " 23:00-05:00 and 04:00Z differ in UTC ms (no date wrap) " )
1090+ " 23:00-05:00 should NOT equal 05:00Z " )
10861091 if (allocated (error)) return
1087- ! However, to_utc(t1) should give 04:00 after midnight-wrap
1088- ! (tested separately in test_to_utc_time_midnight).
1089- !
1090- ! Sanity: 06:00-02:00 == 08:00Z (same-day, no crossing)
1092+ ! Same-day sanity: 06:00-02:00 == 08:00Z
10911093 t1 = time_type(6 , 0 , 0 , 0 , - 120 ) ! 06:00 UTC-02:00
10921094 t2 = time_type(8 , 0 , 0 , 0 , 0 ) ! 08:00 UTC
10931095 call check(error, t1 == t2, &
0 commit comments