@@ -30,8 +30,10 @@ use super::TransformFunction;
3030use crate :: spec:: { Datum , PrimitiveLiteral , PrimitiveType } ;
3131use crate :: { Error , ErrorKind , Result } ;
3232
33- /// Hour in one second.
34- const HOUR_PER_SECOND : f64 = 1.0_f64 / 3600.0_f64 ;
33+ /// Microseconds in one hour.
34+ const MICROSECONDS_PER_HOUR : i64 = 3_600_000_000 ;
35+ /// Nanoseconds in one hour.
36+ const NANOSECONDS_PER_HOUR : i64 = 3_600_000_000_000 ;
3537/// Year of unix epoch.
3638const UNIX_EPOCH_YEAR : i32 = 1970 ;
3739/// One second in micros.
@@ -335,12 +337,12 @@ pub struct Hour;
335337impl Hour {
336338 #[ inline]
337339 fn hour_timestamp_micro ( v : i64 ) -> i32 {
338- ( v as f64 / 1000.0 / 1000.0 * HOUR_PER_SECOND ) as i32
340+ ( v / MICROSECONDS_PER_HOUR ) as i32
339341 }
340342
341343 #[ inline]
342344 fn hour_timestamp_nano ( v : i64 ) -> i32 {
343- ( v as f64 / 1_000_000.0 / 1000.0 * HOUR_PER_SECOND ) as i32
345+ ( v / NANOSECONDS_PER_HOUR ) as i32
344346 }
345347}
346348
@@ -2761,9 +2763,11 @@ mod test {
27612763 // Test TimestampMicrosecond
27622764 test_timestamp_and_tz_transform ( "2017-12-01 18:00:00.00" , & hour, Datum :: int ( 420042 ) ) ;
27632765 test_timestamp_and_tz_transform ( "1969-12-31 23:00:00.00" , & hour, Datum :: int ( -1 ) ) ;
2766+ test_timestamp_and_tz_transform ( "0022-05-01 22:01:01.00" , & hour, Datum :: int ( -17072905 ) ) ;
27642767
27652768 // Test TimestampNanosecond
27662769 test_timestamp_ns_and_tz_transform ( "2017-12-01 18:00:00.00" , & hour, Datum :: int ( 420042 ) ) ;
27672770 test_timestamp_ns_and_tz_transform ( "1969-12-31 23:00:00.00" , & hour, Datum :: int ( -1 ) ) ;
2771+ test_timestamp_ns_and_tz_transform ( "1900-05-01 22:01:01.00" , & hour, Datum :: int ( -610705 ) ) ;
27682772 }
27692773}
0 commit comments