@@ -11,60 +11,40 @@ defmodule Calendar.ISO do
1111 ## ISO 8601 compliance
1212
1313 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
1515 are catalogued below.
1616
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-
3817 ### Features
3918
4019 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.
4325
44- You can ask to parse only basic-formatted date/times instead, or both.
4526 `NaiveDateTime.to_iso8601/2` and `DateTime.to_iso8601/2` allow you to produce
4627 either basic or extended formatted strings, and `Calendar.strftime/2` allows
4728 you to format datetimes however else you desire.
4829
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.
5333
5434 #### Examples
5535
56- Only the extended format is supported in parsing; the basic format is not.
36+ Elixir expects the extended format by default when parsing:
5737
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")
5939 {: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 ")
6141 {:error, :invalid_format}
6242
63- Parsing can be restricted to basic or extend formats.
43+ Parsing can be restricted to basic if desired:
6444
65- iex> Calendar.ISO.parse_naive_datetime("20150123 235007Z ", :basic)
45+ iex> Calendar.ISO.parse_naive_datetime("20150123T235007Z ", :basic)
6646 {: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)
6848 {:error, :invalid_format}
6949
7050 Only calendar dates are supported in parsing; ordinal and week dates are not.
@@ -78,8 +58,7 @@ defmodule Calendar.ISO do
7858 iex> Calendar.ISO.parse_date("2015-W016-3")
7959 {:error, :invalid_format}
8060
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:
8362
8463 iex> Calendar.ISO.parse_date("2015-04-15")
8564 {:ok, {2015, 4, 15}}
@@ -122,6 +101,27 @@ defmodule Calendar.ISO do
122101 iex> Calendar.ISO.parse_utc_datetime("+2015-01-23 23:50:07Z")
123102 {:ok, {2015, 1, 23, 23, 50, 7, {0, 0}}, 0}
124103
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+
125125 """
126126
127127 @ behaviour Calendar
@@ -1288,9 +1288,7 @@ defmodule Calendar.ISO do
12881288 @ doc """
12891289 Determines if the date given is valid according to the proleptic Gregorian calendar.
12901290
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.
12941292
12951293 ## Examples
12961294
0 commit comments