@@ -969,9 +969,7 @@ requestsHash {}",
969
969
size. pretty( ) ,
970
970
state_root. pretty( ) ,
971
971
timestamp. pretty( ) ,
972
- chrono:: DateTime :: from_timestamp( * timestamp as i64 , 0 )
973
- . expect( "block timestamp in range" )
974
- . to_rfc2822( ) ,
972
+ fmt_timestamp( * timestamp) ,
975
973
withdrawals_root. pretty( ) ,
976
974
total_difficulty. pretty( ) ,
977
975
blob_gas_used. pretty( ) ,
@@ -980,6 +978,24 @@ requestsHash {}",
980
978
)
981
979
}
982
980
981
+ /// Formats the timestamp to string
982
+ ///
983
+ /// Assumes timestamp is seconds, but handles millis if it is too large
984
+ fn fmt_timestamp ( timestamp : u64 ) -> String {
985
+ // Tue Jan 19 2038 03:14:07 GMT+0000
986
+ if timestamp > 2147483647 {
987
+ // assume this is in millis, incorrectly set to millis by a node
988
+ chrono:: DateTime :: from_timestamp_millis ( timestamp as i64 )
989
+ . expect ( "block timestamp in range" )
990
+ . to_rfc3339 ( )
991
+ } else {
992
+ // assume this is still in seconds
993
+ chrono:: DateTime :: from_timestamp ( timestamp as i64 , 0 )
994
+ . expect ( "block timestamp in range" )
995
+ . to_rfc2822 ( )
996
+ }
997
+ }
998
+
983
999
#[ cfg( test) ]
984
1000
mod tests {
985
1001
use super :: * ;
@@ -988,6 +1004,17 @@ mod tests {
988
1004
use similar_asserts:: assert_eq;
989
1005
use std:: str:: FromStr ;
990
1006
1007
+ #[ test]
1008
+ fn format_date_time ( ) {
1009
+ // Fri Aug 29 2025 08:05:38 GMT+0000
1010
+ let timestamp = 1756454738u64 ;
1011
+
1012
+ let datetime = fmt_timestamp ( timestamp) ;
1013
+ assert_eq ! ( datetime, "Fri, 29 Aug 2025 08:05:38 +0000" ) ;
1014
+ let datetime = fmt_timestamp ( timestamp * 1000 ) ;
1015
+ assert_eq ! ( datetime, "2025-08-29T08:05:38+00:00" ) ;
1016
+ }
1017
+
991
1018
#[ test]
992
1019
fn can_format_bytes32 ( ) {
993
1020
let val = hex:: decode ( "7465737400000000000000000000000000000000000000000000000000000000" )
0 commit comments