diff --git a/src/io/json/write/serialize.rs b/src/io/json/write/serialize.rs index 205440cb3d..abf845714c 100644 --- a/src/io/json/write/serialize.rs +++ b/src/io/json/write/serialize.rs @@ -1,7 +1,3 @@ -use arrow_array::temporal_conversions::{ - duration_ms_to_duration, duration_ns_to_duration, duration_s_to_duration, - duration_us_to_duration, -}; use chrono::{Duration, NaiveDate, NaiveDateTime}; use lexical_core::ToLexical; use std::io::Write; @@ -12,8 +8,9 @@ use crate::datatypes::{IntegerType, TimeUnit}; use crate::io::iterator::BufStreamingIterator; use crate::offset::Offset; use crate::temporal_conversions::{ - date32_to_date, date64_to_date, timestamp_ms_to_datetime, timestamp_ns_to_datetime, - timestamp_s_to_datetime, timestamp_us_to_datetime, + date32_to_date, date64_to_date, duration_ms_to_duration, duration_ns_to_duration, + duration_s_to_duration, duration_us_to_duration, timestamp_ms_to_datetime, + timestamp_ns_to_datetime, timestamp_s_to_datetime, timestamp_us_to_datetime, }; use crate::util::lexical_to_bytes_mut; use crate::{array::*, datatypes::DataType, types::NativeType}; diff --git a/src/temporal_conversions.rs b/src/temporal_conversions.rs index a76700f444..48f2078a2a 100644 --- a/src/temporal_conversions.rs +++ b/src/temporal_conversions.rs @@ -2,7 +2,7 @@ use chrono::{ format::{parse, Parsed, StrftimeItems}, - Datelike, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime, + Datelike, Duration, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime, }; use crate::error::Result; @@ -66,6 +66,30 @@ pub fn time32s_to_time(v: i32) -> NaiveTime { NaiveTime::from_num_seconds_from_midnight_opt(v as u32, 0).expect("invalid time") } +/// converts a `i64` representing a `duration(s)` to [`Duration`] +#[inline] +pub fn duration_s_to_duration(v: i64) -> Duration { + Duration::seconds(v) +} + +/// converts a `i64` representing a `duration(ms)` to [`Duration`] +#[inline] +pub fn duration_ms_to_duration(v: i64) -> Duration { + Duration::milliseconds(v) +} + +/// converts a `i64` representing a `duration(us)` to [`Duration`] +#[inline] +pub fn duration_us_to_duration(v: i64) -> Duration { + Duration::microseconds(v) +} + +/// converts a `i64` representing a `duration(ns)` to [`Duration`] +#[inline] +pub fn duration_ns_to_duration(v: i64) -> Duration { + Duration::nanoseconds(v) +} + /// converts a `i32` representing a `time32(ms)` to [`NaiveTime`] #[inline] pub fn time32ms_to_time(v: i32) -> NaiveTime {