Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
convert
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jul 27, 2023
1 parent 2c67cfc commit c63cdd6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/io/json/write/serialize.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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};
Expand Down
26 changes: 25 additions & 1 deletion src/temporal_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}

Check warning on line 73 in src/temporal_conversions.rs

View check run for this annotation

Codecov / codecov/patch

src/temporal_conversions.rs#L71-L73

Added lines #L71 - L73 were not covered by tests

/// converts a `i64` representing a `duration(ms)` to [`Duration`]
#[inline]
pub fn duration_ms_to_duration(v: i64) -> Duration {
Duration::milliseconds(v)
}

Check warning on line 79 in src/temporal_conversions.rs

View check run for this annotation

Codecov / codecov/patch

src/temporal_conversions.rs#L77-L79

Added lines #L77 - L79 were not covered by tests

/// converts a `i64` representing a `duration(us)` to [`Duration`]
#[inline]
pub fn duration_us_to_duration(v: i64) -> Duration {
Duration::microseconds(v)
}

Check warning on line 85 in src/temporal_conversions.rs

View check run for this annotation

Codecov / codecov/patch

src/temporal_conversions.rs#L83-L85

Added lines #L83 - L85 were not covered by tests

/// converts a `i64` representing a `duration(ns)` to [`Duration`]
#[inline]
pub fn duration_ns_to_duration(v: i64) -> Duration {
Duration::nanoseconds(v)
}

Check warning on line 91 in src/temporal_conversions.rs

View check run for this annotation

Codecov / codecov/patch

src/temporal_conversions.rs#L89-L91

Added lines #L89 - L91 were not covered by tests

/// converts a `i32` representing a `time32(ms)` to [`NaiveTime`]
#[inline]
pub fn time32ms_to_time(v: i32) -> NaiveTime {
Expand Down

0 comments on commit c63cdd6

Please sign in to comment.