Skip to content

Commit fb1531f

Browse files
sgollLegNeato
andauthored
Add Jiff date/time types Zoned/TimeZone (#1278)
* Enable support for Jiff's Zoned type * Enable support for Jiff's TimeZone type * Remove unnecessary feature flag `jiff-tz` * Avoid panic and allow offset-only time zones to be returned * Add ZonedDateTime and TimeZone to integration test * Split TimeZone into TimeZone and UTCOffset for Jiff integration * Fix capitalization of `UtcOffset` * Provide TimeZoneOrUtcOffset integration for jiff::tz::TimeZone * Adjust documentation for newtypes and `TimeZoneOrUtcOffset` * Use `jiff::tz::Offset` directly in `UtcOffset` newtype * Remove unnecessary newtype for `UtcOffset` scalar * Fix parsing of fixed offsets from `TimeZoneOrUtcOffset` scalar * Add unrelated missing link to books page on scalars * State necessity for newtype in scalars table in book * Remove redundant `alloc` feature, is included in `std` * Implement `Display` for TimeZone newtype * Rename error enum variant to clarify meaning * Use concise wording in description of TimeZone Co-authored-by: Christian Legnitto <[email protected]> * Revert extra notes column in scalar table * Add link to documentation of newtype `TimeZone` * Remove unused duplicate link reference * Sort links and group links from the same crate together --------- Co-authored-by: Christian Legnitto <[email protected]>
1 parent eb2079b commit fb1531f

File tree

4 files changed

+848
-42
lines changed

4 files changed

+848
-42
lines changed

book/src/types/scalars.md

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,29 +385,35 @@ mod date_scalar {
385385

386386
[Juniper] provides out-of-the-box [GraphQL scalar][0] implementations for some very common [Rust] crates. The types from these crates will be usable in your schemas automatically after enabling the correspondent self-titled [Cargo feature].
387387

388-
| [Rust] type | [GraphQL] scalar | [Cargo feature] |
389-
|-----------------------------|-------------------|------------------|
390-
| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] |
391-
| [`bson::oid::ObjectId`] | [`ObjectID`] | [`bson`] |
392-
| [`bson::DateTime`] | [`DateTime`] | [`bson`] |
393-
| [`chrono::NaiveDate`] | [`LocalDate`] | [`chrono`] |
394-
| [`chrono::NaiveTime`] | [`LocalTime`] | [`chrono`] |
395-
| [`chrono::NaiveDateTime`] | [`LocalDateTime`] | [`chrono`] |
396-
| [`chrono::DateTime`] | [`DateTime`] | [`chrono`] |
397-
| [`chrono_tz::Tz`] | [`TimeZone`] | [`chrono-tz`] |
398-
| [`rust_decimal::Decimal`] | `Decimal` | [`rust_decimal`] |
399-
| [`jiff::civil::Date`] | [`LocalDate`] | [`jiff`] |
400-
| [`jiff::civil::Time`] | [`LocalTime`] | [`jiff`] |
401-
| [`jiff::civil::DateTime`] | [`LocalDateTime`] | [`jiff`] |
402-
| [`jiff::Timestamp`] | [`DateTime`] | [`jiff`] |
403-
| [`jiff::Span`] | [`Duration`] | [`jiff`] |
404-
| [`time::Date`] | [`LocalDate`] | [`time`] |
405-
| [`time::Time`] | [`LocalTime`] | [`time`] |
406-
| [`time::PrimitiveDateTime`] | [`LocalDateTime`] | [`time`] |
407-
| [`time::OffsetDateTime`] | [`DateTime`] | [`time`] |
408-
| [`time::UtcOffset`] | [`UtcOffset`] | [`time`] |
409-
| [`url::Url`] | [`URL`] | [`url`] |
410-
| [`uuid::Uuid`] | [`UUID`] | [`uuid`] |
388+
| [Rust] type | [GraphQL] scalar | [Cargo feature] |
389+
|-----------------------------|-----------------------|------------------|
390+
| [`bigdecimal::BigDecimal`] | `BigDecimal` | [`bigdecimal`] |
391+
| [`bson::oid::ObjectId`] | [`ObjectID`] | [`bson`] |
392+
| [`bson::DateTime`] | [`DateTime`] | [`bson`] |
393+
| [`chrono::NaiveDate`] | [`LocalDate`] | [`chrono`] |
394+
| [`chrono::NaiveTime`] | [`LocalTime`] | [`chrono`] |
395+
| [`chrono::NaiveDateTime`] | [`LocalDateTime`] | [`chrono`] |
396+
| [`chrono::DateTime`] | [`DateTime`] | [`chrono`] |
397+
| [`chrono_tz::Tz`] | [`TimeZone`] | [`chrono-tz`] |
398+
| [`rust_decimal::Decimal`] | `Decimal` | [`rust_decimal`] |
399+
| [`jiff::civil::Date`] | [`LocalDate`] | [`jiff`] |
400+
| [`jiff::civil::Time`] | [`LocalTime`] | [`jiff`] |
401+
| [`jiff::civil::DateTime`] | [`LocalDateTime`] | [`jiff`] |
402+
| [`jiff::Timestamp`] | [`DateTime`] | [`jiff`] |
403+
| [`jiff::Zoned`] | `ZonedDateTime` | [`jiff`] |
404+
| [`jiff::tz::TimeZone`] | `TimeZoneOrUtcOffset` | [`jiff`] |
405+
| [`jiff::tz::TimeZone`] | [`TimeZone`] [^n1] | [`jiff`] |
406+
| [`jiff::tz::Offset`] | [`UtcOffset`] | [`jiff`] |
407+
| [`jiff::Span`] | [`Duration`] | [`jiff`] |
408+
| [`time::Date`] | [`LocalDate`] | [`time`] |
409+
| [`time::Time`] | [`LocalTime`] | [`time`] |
410+
| [`time::PrimitiveDateTime`] | [`LocalDateTime`] | [`time`] |
411+
| [`time::OffsetDateTime`] | [`DateTime`] | [`time`] |
412+
| [`time::UtcOffset`] | [`UtcOffset`] | [`time`] |
413+
| [`url::Url`] | [`URL`] | [`url`] |
414+
| [`uuid::Uuid`] | [`UUID`] | [`uuid`] |
415+
416+
[^n1]: Conversion supported via newtype [`integrations::jiff::TimeZone`][10].
411417

412418

413419

@@ -425,7 +431,6 @@ mod date_scalar {
425431
[`chrono-tz`]: https://docs.rs/chrono-tz
426432
[`chrono_tz::Tz`]: https://docs.rs/chrono-tz/latest/chrono_tz/enum.Tz.html
427433
[`DateTime`]: https://graphql-scalars.dev/docs/scalars/date-time
428-
[`Decimal`]: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html
429434
[`Duration`]: https://graphql-scalars.dev/docs/scalars/duration
430435
[`ID`]: https://spec.graphql.org/October2021#sec-ID
431436
[`jiff`]: https://docs.rs/jiff
@@ -434,11 +439,15 @@ mod date_scalar {
434439
[`jiff::civil::Time`]: https://docs.rs/jiff/latest/jiff/civil/struct.Time.html
435440
[`jiff::Span`]: https://docs.rs/jiff/latest/jiff/struct.Span.html
436441
[`jiff::Timestamp`]: https://docs.rs/jiff/latest/jiff/struct.Timestamp.html
442+
[`jiff::tz::Offset`]: https://docs.rs/jiff/latest/jiff/tz/struct.Offset.html
443+
[`jiff::tz::TimeZone`]: https://docs.rs/jiff/latest/jiff/tz/struct.TimeZone.html
444+
[`jiff::Zoned`]: https://docs.rs/jiff/latest/jiff/struct.Zoned.html
437445
[`LocalDate`]: https://graphql-scalars.dev/docs/scalars/local-date
438446
[`LocalDateTime`]: https://graphql-scalars.dev/docs/scalars/local-date-time
439447
[`LocalTime`]: https://graphql-scalars.dev/docs/scalars/local-time
440448
[`ObjectID`]: https://the-guild.dev/graphql/scalars/docs/scalars/object-id
441449
[`rust_decimal`]: https://docs.rs/rust_decimal
450+
[`rust_decimal::Decimal`]: https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html
442451
[`ScalarValue`]: https://docs.rs/juniper/0.16.1/juniper/trait.ScalarValue.html
443452
[`serde`]: https://docs.rs/serde
444453
[`time`]: https://docs.rs/time
@@ -472,3 +481,4 @@ mod date_scalar {
472481
[7]: https://spec.graphql.org/October2021#sec-Value-Resolution
473482
[8]: https://docs.rs/juniper/0.16.1/juniper/derive.GraphQLScalar.html
474483
[9]: https://docs.rs/juniper/0.16.1/juniper/attr.graphql_scalar.html
484+
[10]: https://docs.rs/juniper/0.16.1/juniper/integrations/jiff/struct.TimeZone.html

juniper/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
3434

3535
### Added
3636

37-
- [`jiff` crate] integration behind `jiff` [Cargo feature]: ([#1271], [#1270])
37+
- [`jiff` crate] integration behind `jiff` [Cargo feature]: ([#1271], [#1278], [#1270])
3838
- `jiff::civil::Date` as `LocalDate` scalar.
3939
- `jiff::civil::Time` as `LocalTime` scalar.
4040
- `jiff::civil::DateTime` as `LocalDateTime` scalar. ([#1275])
4141
- `jiff::Timestamp` as `DateTime` scalar.
42+
- `jiff::Zoned` as `ZonedDateTime` scalar.
43+
- `jiff::tz::TimeZone` as `TimeZoneOrUtcOffset` scalar.
44+
- `jiff::tz::Offset` as `UtcOffset` scalar.
4245
- `jiff::Span` as `Duration` scalar.
4346

4447
### Changed
@@ -51,6 +54,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
5154
[#1272]: /../../pull/1272
5255
[#1275]: /../../pull/1275
5356
[#1277]: /../../pull/1277
57+
[#1278]: /../../pull/1278
58+
[#1279]: /../../pull/1279
5459
[#1281]: /../../pull/1281
5560

5661

juniper/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fnv = "1.0.5"
5353
futures = { version = "0.3.22", features = ["alloc"], default-features = false }
5454
graphql-parser = { version = "0.4", optional = true }
5555
indexmap = { version = "2.0", features = ["serde"] }
56-
jiff = { version = "0.1.5", features = ["alloc"], default-features = false, optional = true }
56+
jiff = { version = "0.1.5", features = ["std"], default-features = false, optional = true }
5757
juniper_codegen = { version = "0.16.0", path = "../juniper_codegen" }
5858
rust_decimal = { version = "1.20", default-features = false, optional = true }
5959
ryu = { version = "1.0", optional = true }
@@ -78,6 +78,7 @@ void = { version = "1.0.2", optional = true }
7878
[dev-dependencies]
7979
bencher = "0.1.2"
8080
chrono = { version = "0.4.30", features = ["alloc"], default-features = false }
81+
jiff = { version = "0.1.5", features = ["tzdb-bundle-always"], default-features = false }
8182
pretty_assertions = "1.0.0"
8283
serde_json = "1.0.18"
8384
serial_test = "3.0"

0 commit comments

Comments
 (0)