Skip to content

Commit

Permalink
fixed accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
evanxg852000 committed Jun 23, 2022
1 parent 73b19e9 commit 1f7b8e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/date_time_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn main() -> tantivy::Result<()> {
for (_score, doc_address) in count_docs {
let retrieved_doc = searcher.doc(doc_address)?;
assert!(matches!(retrieved_doc.get_first(occurred_at),
Some(Value::DateTime(dt)) if dt.precision == DateTimePrecision::Seconds));
Some(Value::DateTime(dt)) if dt.get_precision() == DateTimePrecision::Seconds));
assert_eq!(
schema.to_json(&retrieved_doc),
r#"{"event_type":["double-click"],"occurred_at":["2022-06-22T13:00:00Z"]}"#
Expand Down
12 changes: 11 additions & 1 deletion src/schema/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,22 @@ impl DateTime {
}

/// Converts to the underlying precise timestamp.
/// Seconds, Milliseconds, Microseconds, Nanoseconds.
/// TODO: deprecate or remove
pub const fn into_timestamp(self) -> i64 {
let Self { timestamp, .. } = self;
timestamp
}

/// Returns to the underlying timestamp.
pub fn get_timestamp(&self) -> i64 {
self.timestamp
}

/// Returns the underlying timestamp precision.
pub fn get_precision(&self) -> DateTimePrecision {
self.precision
}

/// Convert to UTC `OffsetDateTime`
pub fn into_utc(self) -> OffsetDateTime {
let Self {
Expand Down

0 comments on commit 1f7b8e4

Please sign in to comment.