async-graphql/src/scalars/chrono_tz.rs

23 lines
478 B
Rust
Raw Normal View History

2020-03-27 01:03:30 +00:00
use crate::{impl_scalar_internal, Result, Scalar, Value};
use chrono_tz::Tz;
use std::str::FromStr;
impl Scalar for Tz {
fn type_name() -> &'static str {
"TimeZone"
}
fn parse(value: &Value) -> Option<Self> {
match value {
Value::String(s) => Some(Tz::from_str(&s).ok()?),
_ => None,
}
}
fn to_json(&self) -> Result<serde_json::Value> {
Ok(Tz::name(self).into())
}
}
impl_scalar_internal!(Tz);