summaryrefslogtreecommitdiff
path: root/src/dates.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-08-30 15:43:40 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-08-30 15:43:40 +0200
commite118a43c9ba1719be403d6e7a0f8c610319c144c (patch)
treea4a8146e66335e81603c9788935173ff8f2db5c6 /src/dates.rs
parentc11d902f7e37e5bbd5565bf7353e459c793ade52 (diff)
Use timestamp for `created_at` field
Diffstat (limited to 'src/dates.rs')
-rw-r--r--src/dates.rs36
1 files changed, 0 insertions, 36 deletions
diff --git a/src/dates.rs b/src/dates.rs
deleted file mode 100644
index 9c007e9..0000000
--- a/src/dates.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use async_graphql::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
-use chrono::{DateTime, Utc};
-use serde::{Deserialize, Serialize};
-
-#[derive(Serialize, Deserialize, Debug, Clone)]
-/// A DateTime used as GraphQL type
-pub struct GraphQLDate(pub DateTime<Utc>);
-
-impl From<DateTime<Utc>> for GraphQLDate {
- fn from(dt: DateTime<Utc>) -> Self {
- GraphQLDate(dt)
- }
-}
-
-impl From<GraphQLDate> for DateTime<Utc> {
- fn from(my_dt: GraphQLDate) -> Self {
- my_dt.0
- }
-}
-
-#[Scalar]
-impl ScalarType for GraphQLDate {
- fn parse(value: Value) -> InputValueResult<Self> {
- if let Value::String(s) = &value {
- DateTime::parse_from_rfc3339(s)
- .map(|dt| GraphQLDate(dt.with_timezone(&Utc)))
- .map_err(|e| InputValueError::custom(format!("Invalid DateTime: {}", e)))
- } else {
- Err(InputValueError::expected_type(value))
- }
- }
-
- fn to_value(&self) -> Value {
- Value::String(self.0.to_rfc3339())
- }
-}