From 33db9911e8671a0d79db079be93c3aa3ff75338e Mon Sep 17 00:00:00 2001 From: tyranron Date: Tue, 3 Dec 2024 18:43:42 +0100 Subject: [PATCH] Allow spaces as separators for `DateTime` scalars as per RFC 3339 (time-rs/time#700) --- juniper/Cargo.toml | 2 +- juniper/src/integrations/bson.rs | 24 +++++++++++++++++++++++- juniper/src/integrations/time.rs | 6 +++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index 451ab8eae..7c31590b7 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -61,7 +61,7 @@ serde = { version = "1.0.122", features = ["derive"] } serde_json = { version = "1.0.18", features = ["std"], default-features = false, optional = true } smartstring = "1.0" static_assertions = "1.1" -time = { version = "0.3.35", features = ["formatting", "macros", "parsing"], optional = true } +time = { version = "0.3.37", features = ["formatting", "macros", "parsing"], optional = true } url = { version = "2.0", optional = true } uuid = { version = "1.3", default-features = false, optional = true } diff --git a/juniper/src/integrations/bson.rs b/juniper/src/integrations/bson.rs index 06957935d..e64a3cf45 100644 --- a/juniper/src/integrations/bson.rs +++ b/juniper/src/integrations/bson.rs @@ -137,6 +137,17 @@ mod date_time_test { .build() .unwrap(), ), + ( + "2014-11-28 21:00:09z", + DateTime::builder() + .year(2014) + .month(11) + .day(28) + .hour(21) + .second(9) + .build() + .unwrap(), + ), ( "2014-11-28T21:00:09+00:00", DateTime::builder() @@ -160,6 +171,18 @@ mod date_time_test { .build() .unwrap(), ), + ( + "2014-11-28 21:00:09.05+09:00", + DateTime::builder() + .year(2014) + .month(11) + .day(28) + .hour(12) + .second(9) + .millisecond(50) + .build() + .unwrap(), + ), ] { let input: InputValue = graphql_input_value!((raw)); let parsed = DateTime::from_input_value(&input); @@ -181,7 +204,6 @@ mod date_time_test { graphql_input_value!("56:34:22"), graphql_input_value!("56:34:22.000"), graphql_input_value!("1996-12-1914:23:43"), - graphql_input_value!("1996-12-19 14:23:43Z"), graphql_input_value!("1996-12-19T14:23:43"), graphql_input_value!("1996-12-19T14:23:43ZZ"), graphql_input_value!("1996-12-19T14:23:43.543"), diff --git a/juniper/src/integrations/time.rs b/juniper/src/integrations/time.rs index 63a3e245f..52b018d0c 100644 --- a/juniper/src/integrations/time.rs +++ b/juniper/src/integrations/time.rs @@ -490,6 +490,7 @@ mod date_time_test { datetime!(2014-11-28 21:00:09 +9), ), ("2014-11-28T21:00:09Z", datetime!(2014-11-28 21:00:09 +0)), + ("2014-11-28 21:00:09z", datetime!(2014-11-28 21:00:09 +0)), ( "2014-11-28T21:00:09+00:00", datetime!(2014-11-28 21:00:09 +0), @@ -498,6 +499,10 @@ mod date_time_test { "2014-11-28T21:00:09.05+09:00", datetime!(2014-11-28 12:00:09.05 +0), ), + ( + "2014-11-28 21:00:09.05+09:00", + datetime!(2014-11-28 12:00:09.05 +0), + ), ] { let input: InputValue = graphql_input_value!((raw)); let parsed = DateTime::from_input_value(&input); @@ -519,7 +524,6 @@ mod date_time_test { graphql_input_value!("56:34:22"), graphql_input_value!("56:34:22.000"), graphql_input_value!("1996-12-1914:23:43"), - graphql_input_value!("1996-12-19 14:23:43Z"), graphql_input_value!("1996-12-19T14:23:43"), graphql_input_value!("1996-12-19T14:23:43ZZ"), graphql_input_value!("1996-12-19T14:23:43.543"),