File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,6 +45,16 @@ const MICROS_MASK: i128 = 0xFFFFFFFFFFFFFFFF;
4545/// Mask for extracting the middle 32 bits (days or months).
4646const DAYS_MONTHS_MASK : i128 = 0xFFFFFFFF ;
4747
48+ // 9999-12-30T22:00:00.999999Z
49+ const TIMESTAMP_MAX : i64 = 253402207200999999 ;
50+ // -009999-01-02T01:59:59Z
51+ const TIMESTAMP_MIN : i64 = -377705023201000000 ;
52+
53+ // required by jiff
54+ fn clamp_ts ( ts : i64 ) -> i64 {
55+ ts. clamp ( TIMESTAMP_MIN , TIMESTAMP_MAX )
56+ }
57+
4858impl months_days_micros {
4959 #[ inline]
5060 pub fn months ( & self ) -> i32 {
101111 match array. as_any ( ) . downcast_ref :: < Decimal128Array > ( ) {
102112 Some ( array) => {
103113 let v = array. value ( seq) ;
104- let unix_ts = v as u64 as i64 ;
114+ let unix_ts = clamp_ts ( v as u64 as i64 ) ;
105115 let offset = ( v >> 64 ) as i32 ;
106116 let offset = tz:: Offset :: from_seconds ( offset) . map_err ( |e| {
107117 Error :: Parsing ( format ! ( "invalid offset: {offset}, {e}" ) )
343353 ) )
344354 . into ( ) ) ;
345355 }
346- let ts = array. value ( seq) ;
356+ let ts = clamp_ts ( array. value ( seq) ) ;
347357 match tz {
348358 None => {
349359 let timestamp = Timestamp :: from_microsecond ( ts) . map_err ( |e| {
You can’t perform that action at this time.
0 commit comments