@@ -30,8 +30,10 @@ use super::TransformFunction;
30
30
use crate :: spec:: { Datum , PrimitiveLiteral , PrimitiveType } ;
31
31
use crate :: { Error , ErrorKind , Result } ;
32
32
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 ;
35
37
/// Year of unix epoch.
36
38
const UNIX_EPOCH_YEAR : i32 = 1970 ;
37
39
/// One second in micros.
@@ -335,12 +337,12 @@ pub struct Hour;
335
337
impl Hour {
336
338
#[ inline]
337
339
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
339
341
}
340
342
341
343
#[ inline]
342
344
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
344
346
}
345
347
}
346
348
@@ -2761,9 +2763,11 @@ mod test {
2761
2763
// Test TimestampMicrosecond
2762
2764
test_timestamp_and_tz_transform ( "2017-12-01 18:00:00.00" , & hour, Datum :: int ( 420042 ) ) ;
2763
2765
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 ) ) ;
2764
2767
2765
2768
// Test TimestampNanosecond
2766
2769
test_timestamp_ns_and_tz_transform ( "2017-12-01 18:00:00.00" , & hour, Datum :: int ( 420042 ) ) ;
2767
2770
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 ) ) ;
2768
2772
}
2769
2773
}
0 commit comments