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

Adds 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::add_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 = add_duration(&timestamp, &duration);
let expected = PrimitiveArray::from([
    Some(100010i64),
    Some(200020i64),
    None,
    Some(300030i64),
])
.to(DataType::Timestamp(
    TimeUnit::Second,
    Some("America/New_York".to_string()),
));

assert_eq!(result, expected);