@@ -28,10 +28,11 @@ use arrow::datatypes::DataType::{
2828} ;
2929use arrow:: datatypes:: TimeUnit :: { Microsecond , Millisecond , Nanosecond , Second } ;
3030use arrow:: datatypes:: {
31- DataType , Date32Type , Date64Type , Field , FieldRef , IntervalUnit as ArrowIntervalUnit ,
32- TimeUnit ,
31+ ArrowTimestampType , DataType , Date32Type , Date64Type , Field , FieldRef ,
32+ IntervalUnit as ArrowIntervalUnit , TimeUnit , TimestampMicrosecondType ,
33+ TimestampMillisecondType , TimestampNanosecondType , TimestampSecondType ,
3334} ;
34- use chrono:: { Datelike , NaiveDate , TimeZone , Utc } ;
35+ use chrono:: { Datelike , NaiveDate } ;
3536use datafusion_common:: types:: { NativeType , logical_date} ;
3637
3738use datafusion_common:: {
@@ -337,37 +338,32 @@ fn date_to_scalar(date: NaiveDate, target_type: &DataType) -> Option<ScalarValue
337338
338339 Timestamp ( unit, tz_opt) => {
339340 let naive_midnight = date. and_hms_opt ( 0 , 0 , 0 ) ?;
340-
341- let utc_dt = if let Some ( tz_str) = tz_opt {
342- let tz: Tz = tz_str. parse ( ) . ok ( ) ?;
343-
344- let local = tz. from_local_datetime ( & naive_midnight) ;
345-
346- let local_dt = match local {
347- chrono:: offset:: LocalResult :: Single ( dt) => dt,
348- chrono:: offset:: LocalResult :: Ambiguous ( dt1, _dt2) => dt1,
349- chrono:: offset:: LocalResult :: None => local. earliest ( ) ?,
350- } ;
351-
352- local_dt. with_timezone ( & Utc )
353- } else {
354- Utc . from_utc_datetime ( & naive_midnight)
355- } ;
341+ let tz: Option < Tz > = tz_opt. clone ( ) . and_then ( |s| s. parse ( ) . ok ( ) ) ;
356342
357343 match unit {
358- Second => {
359- ScalarValue :: TimestampSecond ( Some ( utc_dt. timestamp ( ) ) , tz_opt. clone ( ) )
360- }
344+ Second => ScalarValue :: TimestampSecond (
345+ TimestampSecondType :: from_naive_datetime ( naive_midnight, tz. as_ref ( ) ) ,
346+ tz_opt. clone ( ) ,
347+ ) ,
361348 Millisecond => ScalarValue :: TimestampMillisecond (
362- Some ( utc_dt. timestamp_millis ( ) ) ,
349+ TimestampMillisecondType :: from_naive_datetime (
350+ naive_midnight,
351+ tz. as_ref ( ) ,
352+ ) ,
363353 tz_opt. clone ( ) ,
364354 ) ,
365355 Microsecond => ScalarValue :: TimestampMicrosecond (
366- Some ( utc_dt. timestamp_micros ( ) ) ,
356+ TimestampMicrosecondType :: from_naive_datetime (
357+ naive_midnight,
358+ tz. as_ref ( ) ,
359+ ) ,
367360 tz_opt. clone ( ) ,
368361 ) ,
369362 Nanosecond => ScalarValue :: TimestampNanosecond (
370- Some ( utc_dt. timestamp_nanos_opt ( ) ?) ,
363+ TimestampNanosecondType :: from_naive_datetime (
364+ naive_midnight,
365+ tz. as_ref ( ) ,
366+ ) ,
371367 tz_opt. clone ( ) ,
372368 ) ,
373369 }
0 commit comments