@@ -11,60 +11,40 @@ defmodule Calendar.ISO do
11
11
## ISO 8601 compliance
12
12
13
13
The ISO 8601 specification is feature-rich, but allows applications
14
- to selectively implement most parts of it. The choices Elixir makes here
14
+ to selectively implement most parts of it. The choices Elixir makes
15
15
are catalogued below.
16
16
17
- ### Additions
18
-
19
- ISO 8601 does not allow a whitespace instead of `T` as a separator
20
- between date and times, both when parsing and formatting.
21
- This is a common enough representation, Elixir allows it during parsing.
22
-
23
- The formatting of dates in `NaiveDateTime.to_iso8601/1` and `DateTime.to_iso8601/1`
24
- do produce specification-compliant string representations using the `T` separator.
25
-
26
- #### Examples
27
-
28
- iex> Calendar.ISO.parse_naive_datetime("2015-01-23 23:50:07.0123456")
29
- {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}}
30
- iex> Calendar.ISO.parse_naive_datetime("2015-01-23T23:50:07.0123456")
31
- {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}}
32
-
33
- iex> Calendar.ISO.parse_utc_datetime("2015-01-23 23:50:07.0123456Z")
34
- {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}, 0}
35
- iex> Calendar.ISO.parse_utc_datetime("2015-01-23T23:50:07.0123456Z")
36
- {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}, 0}
37
-
38
17
### Features
39
18
40
19
The standard library supports a minimal set of possible ISO 8601 features.
41
- Specifically, the parser only supports calendar dates, and defaults to
42
- only parsing extended-formatted date/times.
20
+ Specifically, the parser only supports calendar dates and does not support
21
+ ordinal and week formats.
22
+
23
+ By default Elixir only parses extended-formatted date/times. You can opt-in
24
+ to parse basic-formatted date/times.
43
25
44
- You can ask to parse only basic-formatted date/times instead, or both.
45
26
`NaiveDateTime.to_iso8601/2` and `DateTime.to_iso8601/2` allow you to produce
46
27
either basic or extended formatted strings, and `Calendar.strftime/2` allows
47
28
you to format datetimes however else you desire.
48
29
49
- Other optional ISO 8601 features; such as ordinal dates, week dates, and reduced
50
- precision (except for milliseconds); are not supported by the parser or formatters.
51
-
52
- No functions exist to parse ISO 8601 durations or time intervals.
30
+ Elixir does not support reduced accuracy formats (for example, a date without
31
+ the day component) nor decimal precisions in the lowest component (such as
32
+ `10:01:25,5`). No functions exist to parse ISO 8601 durations or time intervals.
53
33
54
34
#### Examples
55
35
56
- Only the extended format is supported in parsing; the basic format is not.
36
+ Elixir expects the extended format by default when parsing:
57
37
58
- iex> Calendar.ISO.parse_naive_datetime("2015-01-23 23 :50:07")
38
+ iex> Calendar.ISO.parse_naive_datetime("2015-01-23T23 :50:07")
59
39
{:ok, {2015, 1, 23, 23, 50, 7, {0, 0}}}
60
- iex> Calendar.ISO.parse_naive_datetime("20150123 235007 ")
40
+ iex> Calendar.ISO.parse_naive_datetime("20150123T235007 ")
61
41
{:error, :invalid_format}
62
42
63
- Parsing can be restricted to basic or extend formats.
43
+ Parsing can be restricted to basic if desired:
64
44
65
- iex> Calendar.ISO.parse_naive_datetime("20150123 235007Z ", :basic)
45
+ iex> Calendar.ISO.parse_naive_datetime("20150123T235007Z ", :basic)
66
46
{:ok, {2015, 1, 23, 23, 50, 7, {0, 0}}}
67
- iex> Calendar.ISO.parse_naive_datetime("20150123 235007Z ", :extended)
47
+ iex> Calendar.ISO.parse_naive_datetime("20150123T235007Z ", :extended)
68
48
{:error, :invalid_format}
69
49
70
50
Only calendar dates are supported in parsing; ordinal and week dates are not.
@@ -78,8 +58,7 @@ defmodule Calendar.ISO do
78
58
iex> Calendar.ISO.parse_date("2015-W016-3")
79
59
{:error, :invalid_format}
80
60
81
- Reduced precision is supported for only milliseconds;
82
- years, months, days, hours, minutes, and seconds must be fully specified.
61
+ Years, months, days, hours, minutes, and seconds must be fully specified:
83
62
84
63
iex> Calendar.ISO.parse_date("2015-04-15")
85
64
{:ok, {2015, 4, 15}}
@@ -122,6 +101,27 @@ defmodule Calendar.ISO do
122
101
iex> Calendar.ISO.parse_utc_datetime("+2015-01-23 23:50:07Z")
123
102
{:ok, {2015, 1, 23, 23, 50, 7, {0, 0}}, 0}
124
103
104
+ ### Additions
105
+
106
+ ISO 8601 does not allow a whitespace instead of `T` as a separator
107
+ between date and times, both when parsing and formatting.
108
+ This is a common enough representation, Elixir allows it during parsing.
109
+
110
+ The formatting of dates in `NaiveDateTime.to_iso8601/1` and `DateTime.to_iso8601/1`
111
+ do produce specification-compliant string representations using the `T` separator.
112
+
113
+ #### Examples
114
+
115
+ iex> Calendar.ISO.parse_naive_datetime("2015-01-23 23:50:07.0123456")
116
+ {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}}
117
+ iex> Calendar.ISO.parse_naive_datetime("2015-01-23T23:50:07.0123456")
118
+ {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}}
119
+
120
+ iex> Calendar.ISO.parse_utc_datetime("2015-01-23 23:50:07.0123456Z")
121
+ {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}, 0}
122
+ iex> Calendar.ISO.parse_utc_datetime("2015-01-23T23:50:07.0123456Z")
123
+ {:ok, {2015, 1, 23, 23, 50, 7, {12345, 6}}, 0}
124
+
125
125
"""
126
126
127
127
@ behaviour Calendar
@@ -1288,9 +1288,7 @@ defmodule Calendar.ISO do
1288
1288
@ doc """
1289
1289
Determines if the date given is valid according to the proleptic Gregorian calendar.
1290
1290
1291
- Note that while ISO 8601 allows times to specify 24:00:00 as the
1292
- zero hour of the next day, this notation is not supported by Elixir.
1293
- Leap seconds are not supported as well by the built-in Calendar.ISO.
1291
+ Leap seconds are not supported by the built-in Calendar.ISO.
1294
1292
1295
1293
## Examples
1296
1294
0 commit comments