Merge pull request #27 from IcanDivideBy0/bson_utcdatetime

Add bson::UtcDateTime support
This commit is contained in:
Sunli 2020-04-25 09:10:22 +08:00 committed by GitHub
commit 03d98993f7

View File

@ -1,5 +1,6 @@
use crate::{impl_scalar_internal, Result, Scalar, Value};
use bson::oid::ObjectId;
use bson::{oid::ObjectId, UtcDateTime};
use chrono::{DateTime, Utc};
impl Scalar for ObjectId {
fn type_name() -> &'static str {
@ -19,3 +20,19 @@ impl Scalar for ObjectId {
}
impl_scalar_internal!(ObjectId);
impl Scalar for UtcDateTime {
fn type_name() -> &'static str {
"DateTime"
}
fn parse(value: &Value) -> Option<Self> {
DateTime::<Utc>::parse(value).map(UtcDateTime::from)
}
fn to_json(&self) -> Result<serde_json::Value> {
(**self).to_json()
}
}
impl_scalar_internal!(UtcDateTime);