Skip to content

Commit

Permalink
fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Aug 11, 2024
1 parent 92c0715 commit 0491d5e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
1 change: 1 addition & 0 deletions vegafusion-common/src/data/json_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ mod tests {
let ts_nanos = ts_string
.parse::<chrono::NaiveDateTime>()
.unwrap()
.and_utc()
.timestamp_nanos_opt()
.unwrap();
let ts_micros = ts_nanos / 1000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{NaiveDateTime, TimeZone};
use chrono::{DateTime, TimeZone};
use std::any::Any;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -78,8 +78,9 @@ impl ScalarUDFImpl for DateToUtcTimestampUDF {
// Build naive datetime for time
let seconds = (v as i64) * s_per_day;
let nanoseconds = 0_u32;
let naive_local_datetime = NaiveDateTime::from_timestamp_opt(seconds, nanoseconds)
.expect("invalid or out-of-range datetime");
let naive_local_datetime = DateTime::from_timestamp(seconds, nanoseconds)
.expect("invalid or out-of-range datetime")
.naive_utc();

// Compute UTC date time when naive date time is interpreted in the provided timezone
let local_datetime = tz
Expand Down
10 changes: 5 additions & 5 deletions vegafusion-datafusion-udfs/src/udfs/datetime/format_timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::udfs::datetime::to_utc_timestamp::to_timestamp_ms;
use chrono::NaiveDateTime;
use chrono::DateTime;
use std::any::Any;
use std::sync::Arc;
use vegafusion_common::datafusion_expr::ScalarUDFImpl;
Expand Down Expand Up @@ -100,16 +100,16 @@ impl ScalarUDFImpl for FormatTimestampUDF {

let formatted = Arc::new(StringArray::from_iter(utc_millis_array.iter().map(
|utc_millis| {
utc_millis.map(|utc_millis| {
utc_millis.and_then(|utc_millis| {
// Load as UTC datetime
let utc_seconds = utc_millis / 1_000;
let utc_nanos = (utc_millis % 1_000 * 1_000_000) as u32;
let naive_datetime = NaiveDateTime::from_timestamp_opt(utc_seconds, utc_nanos)
.expect("invalid or out-of-range datetime");
let naive_datetime =
DateTime::from_timestamp(utc_seconds, utc_nanos)?.naive_utc();

// Format as string
let formatted = naive_datetime.format(&format_str);
formatted.to_string()
Some(formatted.to_string())
})
},
))) as ArrayRef;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::NaiveDateTime;
use chrono::DateTime;
use chrono::TimeZone;
use chrono_tz::Tz;
use std::any::Any;
Expand Down Expand Up @@ -113,20 +113,19 @@ pub fn from_utc_timestamp(timestamp_array: ArrayRef, tz: Tz) -> Result<ArrayRef,
timestamp_array
.iter()
.map(|v| {
v.map(|v| {
v.and_then(|v| {
// Build naive datetime for time
let seconds = v / 1000;
let milliseconds = v % 1000;
let nanoseconds = (milliseconds * 1_000_000) as u32;
let naive_utc_datetime =
NaiveDateTime::from_timestamp_opt(seconds, nanoseconds)
.expect("invalid or out-of-range datetime");
DateTime::from_timestamp(seconds, nanoseconds)?.naive_utc();

// Create local datetime, interpreting the naive datetime as utc
let local_datetime = tz.from_utc_datetime(&naive_utc_datetime);
let naive_local_datetime = local_datetime.naive_local();

naive_local_datetime.timestamp_millis()
Some(naive_local_datetime.and_utc().timestamp_millis())
})
})
.collect::<Vec<Option<_>>>(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chrono::TimeZone;
use chrono::{NaiveDateTime, Timelike};
use chrono::Timelike;
use chrono::{DateTime, TimeZone};
use chrono_tz::Tz;
use std::any::Any;
use std::str::FromStr;
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn to_utc_timestamp(timestamp_array: ArrayRef, tz: Tz) -> Result<ArrayRef, D
let milliseconds = v % 1000;
let nanoseconds = (milliseconds * 1_000_000) as u32;
let naive_local_datetime =
NaiveDateTime::from_timestamp_opt(seconds, nanoseconds)?;
DateTime::from_timestamp(seconds, nanoseconds)?.naive_utc();

// Get UTC offset when the naive datetime is considered to be in local time
let local_datetime = if let Some(local_datetime) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::udfs::datetime::from_utc_timestamp::from_utc_timestamp;
use crate::udfs::datetime::to_utc_timestamp::to_timestamp_ms;
use chrono::NaiveDateTime;
use chrono::DateTime;
use std::any::Any;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -110,12 +110,10 @@ impl ScalarUDFImpl for UtcTimestampToStrUDF {
// Load as UTC datetime
let utc_seconds = utc_millis / 1_000;
let utc_nanos = (utc_millis % 1_000 * 1_000_000) as u32;
NaiveDateTime::from_timestamp_opt(utc_seconds, utc_nanos).map(
|naive_datetime| {
let formatted = naive_datetime.format("%Y-%m-%dT%H:%M:%S.%3f");
formatted.to_string()
},
)
DateTime::from_timestamp(utc_seconds, utc_nanos).map(|datetime| {
let formatted = datetime.naive_utc().format("%Y-%m-%dT%H:%M:%S.%3f");
formatted.to_string()
})
})
},
))) as ArrayRef;
Expand Down

0 comments on commit 0491d5e

Please sign in to comment.