pub fn subtract_timestamps(
    lhs: &PrimitiveArray<i64>,
    rhs: &PrimitiveArray<i64>
) -> Result<PrimitiveArray<i64>>
Available on crate feature compute_arithmetics only.
Expand description

Calculates the difference between two timestamps returning an array of type Duration. The timeunit enum is used to scale correctly both arrays; subtracting seconds with seconds, or milliseconds with milliseconds.

Examples

use arrow2::compute::arithmetics::time::subtract_timestamps;
use arrow2::array::PrimitiveArray;
use arrow2::datatypes::{DataType, TimeUnit};
let timestamp_a = PrimitiveArray::from([
    Some(100_010i64),
    Some(200_020i64),
    None,
    Some(300_030i64),
])
.to(DataType::Timestamp(TimeUnit::Second, None));

let timestamp_b = PrimitiveArray::from([
    Some(100_000i64),
    Some(200_000i64),
    None,
    Some(300_000i64),
])
.to(DataType::Timestamp(TimeUnit::Second, None));

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

let result = subtract_timestamps(&timestamp_a, &&timestamp_b).unwrap();
assert_eq!(result, expected);