@@ -222,34 +222,46 @@ mod relative {
222222 ( "630720000 seconds ago" , 630_720_000 . seconds ( ) ) , // 20 years
223223 ] ;
224224
225- let with_times = cases. map ( |( input, _) | {
225+ let cases_with_times = cases. map ( |( input, _) | {
226226 let time = gix_date:: parse ( input, Some ( now) ) . expect ( "relative time string should parse to a Time" ) ;
227227 ( input, time)
228228 } ) ;
229- assert_eq ! ( with_times. map( |_| Sign :: Plus ) , with_times. map( |( _, time) | time. sign) ) ;
230- assert_eq ! ( with_times. map( |_| 0 ) , with_times. map( |( _, time) | time. offset) ) ;
229+ assert_eq ! (
230+ cases_with_times. map( |( _, time) | time. sign) ,
231+ cases_with_times. map( |_| Sign :: Plus ) ,
232+ "Despite being in the past, the dates produced are positive, as they are still post-epoch"
233+ ) ;
234+ assert_eq ! (
235+ cases_with_times. map( |( _, time) | time. offset) ,
236+ cases_with_times. map( |_| 0 ) ,
237+ "They don't pick up local time"
238+ ) ;
231239
232- let with_expected = cases. map ( |( input, span) | {
233- let expected = Zoned :: try_from ( now)
234- . expect ( "test needs to convert current time to a timestamp" )
235- // account for the loss of precision when creating `Time` with seconds
236- . round (
237- jiff:: ZonedRound :: new ( )
238- . smallest ( jiff:: Unit :: Second )
239- . mode ( jiff:: RoundMode :: Trunc ) ,
240- )
241- . expect ( "test needs to truncate current timestamp to seconds" )
242- . saturating_sub ( span)
243- . timestamp ( ) ;
240+ let expected = cases. map ( |( input, span) | {
241+ let expected = Zoned :: new (
242+ now. try_into ( ) . expect ( "system time is representable" ) ,
243+ // As relative dates are always UTC in Git, we do the same, and must
244+ // compare to UTC as well or else time might be off due to daylight savings, etc.
245+ jiff:: tz:: TimeZone :: UTC ,
246+ )
247+ // account for the loss of precision when creating `Time` with seconds
248+ . round (
249+ jiff:: ZonedRound :: new ( )
250+ . smallest ( jiff:: Unit :: Second )
251+ . mode ( jiff:: RoundMode :: Trunc ) ,
252+ )
253+ . expect ( "test needs to truncate current timestamp to seconds" )
254+ . saturating_sub ( span)
255+ . timestamp ( ) ;
244256
245257 ( input, expected)
246258 } ) ;
247- let with_actual = with_times . map ( |( input, time) | {
259+ let actual = cases_with_times . map ( |( input, time) | {
248260 let actual = jiff:: Timestamp :: from_second ( time. seconds )
249261 . expect ( "seconds obtained from a Time should convert to Timestamp" ) ;
250262 ( input, actual)
251263 } ) ;
252- assert_eq ! ( with_actual , with_expected , "relative times differ" ) ;
264+ assert_eq ! ( actual , expected ) ;
253265 }
254266}
255267
0 commit comments