Skip to content

Commit

Permalink
twiq: Add firestore_rpc::helper::value_from_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Oct 29, 2022
1 parent 58fd892 commit 44cde52
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions twiq/crates/db/src/firestore_rpc.rs
Expand Up @@ -51,6 +51,12 @@ pub mod helper {
}
}

pub fn value_from_timestamp(t: Timestamp) -> Value {
Value {
value_type: Some(ValueType::TimestampValue(t)),
}
}

// panic if value_type is not integer
pub fn value_into_i64_unchecked(value: &Value) -> i64 {
match value.value_type {
Expand Down Expand Up @@ -153,6 +159,18 @@ pub mod helper {
);
}

#[test]
fn value_from_timestamp_test() -> anyhow::Result<()> {
let timestamp = Timestamp::from_str("2020-01-02T15:04:05Z")?;
assert_eq!(
value_from_timestamp(timestamp.clone()),
Value {
value_type: Some(ValueType::TimestampValue(timestamp))
}
);
Ok(())
}

#[test]
fn value_into_i64_unchecked_test() {
assert_eq!(
Expand Down

0 comments on commit 44cde52

Please sign in to comment.