2020-04-27 09:58:10 +00:00
|
|
|
use crate::{Result, ScalarType, Value};
|
|
|
|
use async_graphql_derive::Scalar;
|
2020-03-27 01:03:30 +00:00
|
|
|
use chrono_tz::Tz;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
2020-04-27 09:58:10 +00:00
|
|
|
#[Scalar(internal)]
|
|
|
|
impl ScalarType for Tz {
|
2020-03-27 01:03:30 +00:00
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|