Skip to content

Commit 3725bb4

Browse files
committed
Add YearMonth scalar
1 parent 64615c9 commit 3725bb4

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!-- cspell:ignore ayushvora10 -->
2+
3+
# YearMonth — GraphQL Custom Scalar
4+
5+
"Author - ayushvora10"
6+
7+
"Date - 2024-07-27"
8+
9+
**License and Copyright**
10+
11+
Copyright © GraphQL contributors. This specification is licensed under
12+
[OWFa 1.0](https://www.openwebfoundation.org/the-agreements/the-owf-1-0-agreements-granted-claims/owfa-1-0).
13+
14+
# Overview
15+
16+
This string-based scalar represents a specific month of a specific year (not just any month) following ISO 8601.
17+
18+
The pattern is “YYYY-MM” with “YYYY” representing the year and “MM” the month.
19+
20+
This can be used for records that are monthly in nature. Eg. a monthly sales forecast.
21+
22+
# Name
23+
24+
`YearMonth` inspired by [Java](https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html)
25+
26+
Or `ISO8601YearMonth`
27+
Or just `Month`?
28+
`ISO8601Month`?
29+
30+
# Result spec
31+
32+
The result must be an ISO 8601 extended format string with just the year and month: “YYYY-MM”
33+
34+
## Valid examples
35+
36+
| String | Explanation |
37+
| -------- | ------- |
38+
| `2024-07` | Representing July 2024 |
39+
| `2024-12` | Representing December 2024 |
40+
| `0999-01` | Representing January of the year 999 |
41+
42+
## Invalid examples
43+
44+
| String | Explanation |
45+
| -------- | ------- |
46+
| `2024-7` | Zero-padding missing on the month, should be 2024-07 |
47+
| `24-07` | Truncated representations on year (YY instead of YYYY) are not recommended by ISO and can be confusing |
48+
| `2024-07-01` | Full date is not expected, precision must only be up to month |
49+
| `2024-07-01T00:00:00Z` | Full date-time is not expected, precision must only be up to month |
50+
| `07-2024` | Should be YYYY-MM, not the other way |
51+
| `2024-00` | Month must be 1-indexed, not 0-indexed: Jan = 01, Dec = 12 |
52+
| `202407` | Hyphen missing; ISO recommends the “basic format (one without hyphens) should be avoided in plain text” |
53+
| `2024/07` | Slash instead of hyphen |
54+
| `2024` | Incomplete - month missing |
55+
| `2024-Jul` | No strings allowed |
56+
| `+2024-07` | No prefix (or postfix) symbols or characters allowed |
57+
58+
# Input spec
59+
60+
For input, _any valid ISO 8601 string_ is allowed.
61+
62+
## Valid examples
63+
64+
| String | Explanation |
65+
| -------- | ------- |
66+
| `2024-07` | Representing July 2024 |
67+
| `2024-07-13` | Still representing July 2024 - the implementation can ignore the date as needed |
68+
| `2024-07-13T16:23:58Z` | Still representing July 2024 - the implementation can ignore everything beyond month as needed |
69+
| `2024` | Just year is valid ISO and must be treated as January of that year |
70+
71+
## Invalid examples
72+
73+
| String | Explanation |
74+
| -------- | ------- |
75+
| `2024-July` | Invalid ISO |
76+
77+
# References
78+
79+
- [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
80+
List external references, other background information etc.

0 commit comments

Comments
 (0)