@@ -352,8 +352,14 @@ impl fmt::Display for Timestamp {
352
352
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
353
353
write ! (
354
354
f,
355
- "{}-{:02}-{:02} {:02}:{:02}:{:02}" ,
356
- self . year, self . month, self . day, self . hour, self . minute, self . second
355
+ "{}{:04}-{:02}-{:02} {:02}:{:02}:{:02}" ,
356
+ if self . year < 0 { "-" } else { "" } ,
357
+ self . year. abs( ) ,
358
+ self . month,
359
+ self . day,
360
+ self . hour,
361
+ self . minute,
362
+ self . second
357
363
) ?;
358
364
match self . precision {
359
365
1 => write ! ( f, ".{:01}" , self . nanosecond / 100000000 ) ?,
@@ -556,18 +562,20 @@ mod tests {
556
562
assert_eq ! ( ts. to_string( ) , "2012-03-04 05:06:07.890123456 -08:45" ) ;
557
563
ts. precision = 0 ;
558
564
assert_eq ! ( ts. to_string( ) , "2012-03-04 05:06:07 -08:45" ) ;
565
+ ts. year = 3 ;
566
+ assert_eq ! ( ts. to_string( ) , "0003-03-04 05:06:07 -08:45" ) ;
559
567
ts. year = -123 ;
560
- assert_eq ! ( ts. to_string( ) , "-123 -03-04 05:06:07 -08:45" ) ;
568
+ assert_eq ! ( ts. to_string( ) , "-0123 -03-04 05:06:07 -08:45" ) ;
561
569
let mut ts = ts. and_tz_offset ( -3600 - 1800 ) ?;
562
570
assert_eq ! ( ts. tz_hour_offset, -1 ) ;
563
571
assert_eq ! ( ts. tz_minute_offset, -30 ) ;
564
- assert_eq ! ( ts. to_string( ) , "-123 -03-04 05:06:07 -01:30" ) ;
572
+ assert_eq ! ( ts. to_string( ) , "-0123 -03-04 05:06:07 -01:30" ) ;
565
573
ts. tz_hour_offset = 0 ;
566
- assert_eq ! ( ts. to_string( ) , "-123 -03-04 05:06:07 -00:30" ) ;
574
+ assert_eq ! ( ts. to_string( ) , "-0123 -03-04 05:06:07 -00:30" ) ;
567
575
ts. tz_minute_offset = 30 ;
568
- assert_eq ! ( ts. to_string( ) , "-123 -03-04 05:06:07 +00:30" ) ;
576
+ assert_eq ! ( ts. to_string( ) , "-0123 -03-04 05:06:07 +00:30" ) ;
569
577
ts. tz_minute_offset = 0 ;
570
- assert_eq ! ( ts. to_string( ) , "-123 -03-04 05:06:07 +00:00" ) ;
578
+ assert_eq ! ( ts. to_string( ) , "-0123 -03-04 05:06:07 +00:00" ) ;
571
579
Ok ( ( ) )
572
580
}
573
581
0 commit comments