pub fn subtract_duration<T>(
    time: &PrimitiveArray<T>,
    duration: &PrimitiveArray<i64>
) -> PrimitiveArray<T> where
    f64: AsPrimitive<T>,
    T: NativeType + Sub<T, Output = T>, 
Available on crate feature compute_arithmetics only.
Expand description

Subtract a duration to a time array (Timestamp, Time and Date). The timeunit enum is used to scale correctly both arrays; adding seconds with seconds, or milliseconds with milliseconds.

Examples

use arrow2::compute::arithmetics::time::subtract_duration;
use arrow2::array::PrimitiveArray;
use arrow2::datatypes::{DataType, TimeUnit};

let timestamp = PrimitiveArray::from([
    Some(100000i64),
    Some(200000i64),
    None,
    Some(300000i64),
])
.to(DataType::Timestamp(
    TimeUnit::Second,
    Some("America/New_York".to_string()),
));

let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)])
    .to(DataType::Duration(TimeUnit::Second));

let result = subtract_duration(&timestamp, &duration);
let expected = PrimitiveArray::from([
    Some(99990i64),
    Some(199980i64),
    None,
    Some(299970i64),
])
.to(DataType::Timestamp(
    TimeUnit::Second,
    Some("America/New_York".to_string()),
));

assert_eq!(result, expected);