mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-07 17:42:55 +00:00
* add aggregation support for date type fixes #1332 * serialize key_as_string as rfc3339 in date histogram * update docs * enable date for range aggregation
19 lines
629 B
Rust
19 lines
629 B
Rust
use time::format_description::well_known::Rfc3339;
|
|
use time::OffsetDateTime;
|
|
|
|
use crate::TantivyError;
|
|
|
|
pub(crate) fn format_date(val: i64) -> crate::Result<String> {
|
|
let datetime =
|
|
OffsetDateTime::from_unix_timestamp_nanos(1_000 * (val as i128)).map_err(|err| {
|
|
TantivyError::InvalidArgument(format!(
|
|
"Could not convert {:?} to OffsetDateTime, err {:?}",
|
|
val, err
|
|
))
|
|
})?;
|
|
let key_as_string = datetime
|
|
.format(&Rfc3339)
|
|
.map_err(|_err| TantivyError::InvalidArgument("Could not serialize date".to_string()))?;
|
|
Ok(key_as_string)
|
|
}
|