@@ -440,7 +440,6 @@ impl Neg for months_days_micros {
440440 }
441441}
442442
443- /// The in-memory representation of the MonthDayNano variant of the "Interval" logical type.
444443#[ derive(
445444 Debug ,
446445 Copy ,
@@ -460,12 +459,12 @@ pub struct timestamp_tz(pub i128);
460459
461460impl Hash for timestamp_tz {
462461 fn hash < H : Hasher > ( & self , state : & mut H ) {
463- self . total_micros ( ) . hash ( state)
462+ self . timestamp ( ) . hash ( state)
464463 }
465464}
466465impl PartialEq for timestamp_tz {
467466 fn eq ( & self , other : & Self ) -> bool {
468- self . total_micros ( ) == other. total_micros ( )
467+ self . timestamp ( ) == other. timestamp ( )
469468 }
470469}
471470impl PartialOrd for timestamp_tz {
@@ -476,17 +475,18 @@ impl PartialOrd for timestamp_tz {
476475
477476impl Ord for timestamp_tz {
478477 fn cmp ( & self , other : & Self ) -> Ordering {
479- let total_micros = self . total_micros ( ) ;
480- let other_micros = other. total_micros ( ) ;
481- total_micros . cmp ( & other_micros)
478+ let timestamp = self . timestamp ( ) ;
479+ let other_micros = other. timestamp ( ) ;
480+ timestamp . cmp ( & other_micros)
482481 }
483482}
484483
485484impl timestamp_tz {
486485 pub const MICROS_PER_SECOND : i64 = 1_000_000 ;
487486
487+ #[ inline]
488488 pub fn new ( timestamp : i64 , offset : i32 ) -> Self {
489- let ts = timestamp as u64 as i128 ; // <- 中间加一次 u64 屏蔽符号位
489+ let ts = timestamp as u64 as i128 ;
490490 let off = ( offset as i128 ) << 64 ;
491491 Self ( off | ts)
492492 }
@@ -507,32 +507,19 @@ impl timestamp_tz {
507507 }
508508
509509 #[ inline]
510- pub fn hours_offset ( & self ) -> i8 {
511- ( self . seconds_offset ( ) / 3600 ) as i8
510+ pub fn micros_offset_inner ( seconds : i64 ) -> Option < i64 > {
511+ seconds . checked_mul ( Self :: MICROS_PER_SECOND )
512512 }
513513
514514 #[ inline]
515- pub fn total_micros ( & self ) -> i64 {
516- self . try_total_micros ( ) . unwrap_or_else ( || {
517- error ! (
518- "interval is out of range: timestamp={}, offset={}" ,
519- self . timestamp( ) ,
520- self . seconds_offset( )
521- ) ;
522- 0
523- } )
524- }
525-
526- #[ inline]
527- pub fn try_total_micros ( & self ) -> Option < i64 > {
528- let offset_micros = self . micros_offset ( ) ?;
529- self . timestamp ( ) . checked_sub ( offset_micros)
515+ pub fn hours_offset ( & self ) -> i8 {
516+ ( self . seconds_offset ( ) / 3600 ) as i8
530517 }
531518}
532519
533520impl Display for timestamp_tz {
534521 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
535- let timestamp = Timestamp :: from_microsecond ( self . total_micros ( ) ) . unwrap ( ) ;
522+ let timestamp = Timestamp :: from_microsecond ( self . timestamp ( ) ) . unwrap ( ) ;
536523
537524 let offset = tz:: Offset :: from_seconds ( self . seconds_offset ( ) ) . unwrap ( ) ;
538525 let string = strtime:: format (
0 commit comments