2020-09-13 03:41:15 +00:00
|
|
|
use crate::{GQLScalar, InputValueError, InputValueResult, ScalarType, Value};
|
2020-08-31 08:12:12 +00:00
|
|
|
use chrono::{DateTime, FixedOffset, Local, Utc};
|
2020-08-29 20:18:57 +00:00
|
|
|
|
|
|
|
/// Implement the DateTime<FixedOffset> scalar
|
|
|
|
///
|
|
|
|
/// The input/output is a string in RFC3339 format.
|
2020-09-13 03:41:15 +00:00
|
|
|
#[GQLScalar(internal, name = "DateTime")]
|
2020-08-29 20:18:57 +00:00
|
|
|
impl ScalarType for DateTime<FixedOffset> {
|
|
|
|
fn parse(value: Value) -> InputValueResult<Self> {
|
|
|
|
match &value {
|
2020-08-31 08:12:12 +00:00
|
|
|
Value::String(s) => Ok(s.parse::<DateTime<FixedOffset>>()?),
|
|
|
|
_ => Err(InputValueError::ExpectedType(value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_value(&self) -> Value {
|
|
|
|
Value::String(self.to_rfc3339())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Implement the DateTime<Local> scalar
|
|
|
|
///
|
|
|
|
/// The input/output is a string in RFC3339 format.
|
2020-09-13 03:41:15 +00:00
|
|
|
#[GQLScalar(internal, name = "DateTime")]
|
2020-08-31 08:12:12 +00:00
|
|
|
impl ScalarType for DateTime<Local> {
|
|
|
|
fn parse(value: Value) -> InputValueResult<Self> {
|
|
|
|
match &value {
|
|
|
|
Value::String(s) => Ok(s.parse::<DateTime<Local>>()?),
|
2020-08-29 20:18:57 +00:00
|
|
|
_ => Err(InputValueError::ExpectedType(value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn to_value(&self) -> Value {
|
|
|
|
Value::String(self.to_rfc3339())
|
|
|
|
}
|
|
|
|
}
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-03-20 03:56:08 +00:00
|
|
|
/// Implement the DateTime<Utc> scalar
|
|
|
|
///
|
|
|
|
/// The input/output is a string in RFC3339 format.
|
2020-09-13 03:41:15 +00:00
|
|
|
#[GQLScalar(internal, name = "DateTime")]
|
2020-04-27 09:58:10 +00:00
|
|
|
impl ScalarType for DateTime<Utc> {
|
2020-05-11 13:47:24 +00:00
|
|
|
fn parse(value: Value) -> InputValueResult<Self> {
|
2020-06-16 01:46:20 +00:00
|
|
|
match &value {
|
2020-06-16 15:21:05 +00:00
|
|
|
Value::String(s) => Ok(s.parse::<DateTime<Utc>>()?),
|
2020-05-11 13:47:24 +00:00
|
|
|
_ => Err(InputValueError::ExpectedType(value)),
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 10:34:43 +00:00
|
|
|
fn to_value(&self) -> Value {
|
|
|
|
Value::String(self.to_rfc3339())
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
}
|