@@ -337,12 +337,12 @@ pub struct Hour;
337
337
impl Hour {
338
338
#[ inline]
339
339
fn hour_timestamp_micro ( v : i64 ) -> i32 {
340
- ( v / MICROSECONDS_PER_HOUR ) as i32
340
+ v . div_euclid ( MICROSECONDS_PER_HOUR ) as i32
341
341
}
342
342
343
343
#[ inline]
344
344
fn hour_timestamp_nano ( v : i64 ) -> i32 {
345
- ( v / NANOSECONDS_PER_HOUR ) as i32
345
+ v . div_euclid ( NANOSECONDS_PER_HOUR ) as i32
346
346
}
347
347
}
348
348
@@ -2390,18 +2390,8 @@ mod test {
2390
2390
transform : & BoxedTransformFunction ,
2391
2391
expect : Datum ,
2392
2392
) {
2393
- let timestamp = Datum :: timestamp_micros (
2394
- NaiveDateTime :: parse_from_str ( time, "%Y-%m-%d %H:%M:%S.%f" )
2395
- . unwrap ( )
2396
- . and_utc ( )
2397
- . timestamp_micros ( ) ,
2398
- ) ;
2399
- let timestamp_tz = Datum :: timestamptz_micros (
2400
- NaiveDateTime :: parse_from_str ( time, "%Y-%m-%d %H:%M:%S.%f" )
2401
- . unwrap ( )
2402
- . and_utc ( )
2403
- . timestamp_micros ( ) ,
2404
- ) ;
2393
+ let timestamp = Datum :: timestamp_from_str ( time) . unwrap ( ) ;
2394
+ let timestamp_tz = Datum :: timestamptz_from_str ( time. to_owned ( ) + " +00:00" ) . unwrap ( ) ;
2405
2395
let res = transform. transform_literal ( & timestamp) . unwrap ( ) . unwrap ( ) ;
2406
2396
assert_eq ! ( res, expect) ;
2407
2397
let res = transform. transform_literal ( & timestamp_tz) . unwrap ( ) . unwrap ( ) ;
@@ -2432,20 +2422,8 @@ mod test {
2432
2422
transform : & BoxedTransformFunction ,
2433
2423
expect : Datum ,
2434
2424
) {
2435
- let timestamp_ns = Datum :: timestamp_nanos (
2436
- NaiveDateTime :: parse_from_str ( time, "%Y-%m-%d %H:%M:%S.%f" )
2437
- . unwrap ( )
2438
- . and_utc ( )
2439
- . timestamp_nanos_opt ( )
2440
- . unwrap ( ) ,
2441
- ) ;
2442
- let timestamptz_ns = Datum :: timestamptz_nanos (
2443
- NaiveDateTime :: parse_from_str ( time, "%Y-%m-%d %H:%M:%S.%f" )
2444
- . unwrap ( )
2445
- . and_utc ( )
2446
- . timestamp_nanos_opt ( )
2447
- . unwrap ( ) ,
2448
- ) ;
2425
+ let timestamp_ns = Datum :: timestamp_from_str ( time) . unwrap ( ) ;
2426
+ let timestamptz_ns = Datum :: timestamptz_from_str ( time. to_owned ( ) + " +00:00" ) . unwrap ( ) ;
2449
2427
let res = transform. transform_literal ( & timestamp_ns) . unwrap ( ) . unwrap ( ) ;
2450
2428
assert_eq ! ( res, expect) ;
2451
2429
let res = transform
@@ -2485,15 +2463,15 @@ mod test {
2485
2463
& year,
2486
2464
Datum :: int ( 1970 - super :: UNIX_EPOCH_YEAR ) ,
2487
2465
) ;
2488
- test_timestamp_and_tz_transform ( "1969-01-01 00 :00:00.00 " , & year, Datum :: int ( -1 ) ) ;
2466
+ test_timestamp_and_tz_transform ( "1969-01-01T00 :00:00.000000 " , & year, Datum :: int ( -1 ) ) ;
2489
2467
2490
2468
// Test TimestampNanosecond
2491
2469
test_timestamp_ns_and_tz_transform_using_i64 (
2492
2470
186280000000 ,
2493
2471
& year,
2494
2472
Datum :: int ( 1970 - super :: UNIX_EPOCH_YEAR ) ,
2495
2473
) ;
2496
- test_timestamp_ns_and_tz_transform ( "1969-01-01 00 :00:00.00 " , & year, Datum :: int ( -1 ) ) ;
2474
+ test_timestamp_ns_and_tz_transform ( "1969-01-01T00 :00:00.000000 " , & year, Datum :: int ( -1 ) ) ;
2497
2475
}
2498
2476
2499
2477
#[ test]
@@ -2584,21 +2562,21 @@ mod test {
2584
2562
& month,
2585
2563
Datum :: int ( ( 1970 - super :: UNIX_EPOCH_YEAR ) * 12 ) ,
2586
2564
) ;
2587
- test_timestamp_and_tz_transform ( "1969-12-01 23 :00:00.00 " , & month, Datum :: int ( -1 ) ) ;
2588
- test_timestamp_and_tz_transform ( "2017-12-01 00 :00:00.00 " , & month, Datum :: int ( 575 ) ) ;
2589
- test_timestamp_and_tz_transform ( "1970-01-01 00 :00:00.00 " , & month, Datum :: int ( 0 ) ) ;
2590
- test_timestamp_and_tz_transform ( "1969-12-31 00 :00:00.00 " , & month, Datum :: int ( -1 ) ) ;
2565
+ test_timestamp_and_tz_transform ( "1969-12-01T23 :00:00.000000 " , & month, Datum :: int ( -1 ) ) ;
2566
+ test_timestamp_and_tz_transform ( "2017-12-01T00 :00:00.000000 " , & month, Datum :: int ( 575 ) ) ;
2567
+ test_timestamp_and_tz_transform ( "1970-01-01T00 :00:00.000000 " , & month, Datum :: int ( 0 ) ) ;
2568
+ test_timestamp_and_tz_transform ( "1969-12-31T00 :00:00.000000 " , & month, Datum :: int ( -1 ) ) ;
2591
2569
2592
2570
// Test TimestampNanosecond
2593
2571
test_timestamp_ns_and_tz_transform_using_i64 (
2594
2572
186280000000 ,
2595
2573
& month,
2596
2574
Datum :: int ( ( 1970 - super :: UNIX_EPOCH_YEAR ) * 12 ) ,
2597
2575
) ;
2598
- test_timestamp_ns_and_tz_transform ( "1969-12-01 23 :00:00.00 " , & month, Datum :: int ( -1 ) ) ;
2599
- test_timestamp_ns_and_tz_transform ( "2017-12-01 00 :00:00.00 " , & month, Datum :: int ( 575 ) ) ;
2600
- test_timestamp_ns_and_tz_transform ( "1970-01-01 00 :00:00.00 " , & month, Datum :: int ( 0 ) ) ;
2601
- test_timestamp_ns_and_tz_transform ( "1969-12-31 00 :00:00.00 " , & month, Datum :: int ( -1 ) ) ;
2576
+ test_timestamp_ns_and_tz_transform ( "1969-12-01T23 :00:00.000000 " , & month, Datum :: int ( -1 ) ) ;
2577
+ test_timestamp_ns_and_tz_transform ( "2017-12-01T00 :00:00.000000 " , & month, Datum :: int ( 575 ) ) ;
2578
+ test_timestamp_ns_and_tz_transform ( "1970-01-01T00 :00:00.000000 " , & month, Datum :: int ( 0 ) ) ;
2579
+ test_timestamp_ns_and_tz_transform ( "1969-12-31T00 :00:00.000000 " , & month, Datum :: int ( -1 ) ) ;
2602
2580
}
2603
2581
2604
2582
#[ test]
@@ -2689,12 +2667,12 @@ mod test {
2689
2667
// Test TimestampMicrosecond
2690
2668
test_timestamp_and_tz_transform_using_i64 ( 1512151975038194 , & day, Datum :: date ( 17501 ) ) ;
2691
2669
test_timestamp_and_tz_transform_using_i64 ( -115200000000 , & day, Datum :: date ( -2 ) ) ;
2692
- test_timestamp_and_tz_transform ( "2017-12-01 10 :30:42.123 " , & day, Datum :: date ( 17501 ) ) ;
2670
+ test_timestamp_and_tz_transform ( "2017-12-01T10 :30:42.123000 " , & day, Datum :: date ( 17501 ) ) ;
2693
2671
2694
2672
// Test TimestampNanosecond
2695
2673
test_timestamp_ns_and_tz_transform_using_i64 ( 1512151975038194 , & day, Datum :: date ( 17 ) ) ;
2696
2674
test_timestamp_ns_and_tz_transform_using_i64 ( -115200000000 , & day, Datum :: date ( -1 ) ) ;
2697
- test_timestamp_ns_and_tz_transform ( "2017-12-01 10 :30:42.123 " , & day, Datum :: date ( 17501 ) ) ;
2675
+ test_timestamp_ns_and_tz_transform ( "2017-12-01T10 :30:42.123000 " , & day, Datum :: date ( 17501 ) ) ;
2698
2676
}
2699
2677
2700
2678
#[ test]
@@ -2760,14 +2738,23 @@ mod test {
2760
2738
fn test_transform_hours_literal ( ) {
2761
2739
let hour = Box :: new ( super :: Hour ) as BoxedTransformFunction ;
2762
2740
2763
- // Test TimestampMicrosecond
2764
- test_timestamp_and_tz_transform ( "2017-12-01 18:00:00.00" , & hour, Datum :: int ( 420042 ) ) ;
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 ) ) ;
2741
+ test_timestamp_and_tz_transform ( "2017-12-01T18:00:00.000000" , & hour, Datum :: int ( 420042 ) ) ;
2742
+ test_timestamp_and_tz_transform ( "1970-01-01T22:01:01.000000" , & hour, Datum :: int ( 22 ) ) ;
2743
+ test_timestamp_and_tz_transform ( "1969-12-31T23:00:00.000000" , & hour, Datum :: int ( -1 ) ) ;
2744
+ test_timestamp_and_tz_transform ( "1969-12-31T22:01:01.000000" , & hour, Datum :: int ( -2 ) ) ;
2745
+ test_timestamp_and_tz_transform ( "0022-05-01T22:01:01.000000" , & hour, Datum :: int ( -17072906 ) ) ;
2767
2746
2768
2747
// Test TimestampNanosecond
2769
- test_timestamp_ns_and_tz_transform ( "2017-12-01 18:00:00.00" , & hour, Datum :: int ( 420042 ) ) ;
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 ) ) ;
2748
+ test_timestamp_ns_and_tz_transform (
2749
+ "2017-12-01T18:00:00.0000000000" ,
2750
+ & hour,
2751
+ Datum :: int ( 420042 ) ,
2752
+ ) ;
2753
+ test_timestamp_ns_and_tz_transform ( "1969-12-31T23:00:00.0000000000" , & hour, Datum :: int ( -1 ) ) ;
2754
+ test_timestamp_ns_and_tz_transform (
2755
+ "1900-05-01T22:01:01.0000000000" ,
2756
+ & hour,
2757
+ Datum :: int ( -610706 ) ,
2758
+ ) ;
2772
2759
}
2773
2760
}
0 commit comments