Skip to content

Commit d066583

Browse files
author
José Valim
committed
Handle years more than 9999 when printing, closes #8368
1 parent d98d8e0 commit d066583

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

Diff for: lib/elixir/lib/calendar/date.ex

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ defmodule Date do
248248
Parses the extended "Dates" format described by
249249
[ISO 8601:2004](https://en.wikipedia.org/wiki/ISO_8601).
250250
251+
The year parsed by this function is limited to four digits.
252+
251253
## Examples
252254
253255
iex> Date.from_iso8601("2015-01-23")

Diff for: lib/elixir/lib/calendar/datetime.ex

+3-4
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,9 @@ defmodule DateTime do
461461
As specified in the standard, the separator "T" may be omitted if
462462
desired as there is no ambiguity within this function.
463463
464-
Time representations with reduced accuracy are not supported.
465-
466-
Note that while ISO 8601 allows datetimes to specify 24:00:00 as the
467-
zero hour of the next day, this notation is not supported by Elixir.
464+
The year parsed by this function is limited to four digits and,
465+
while ISO 8601 allows datetimes to specify 24:00:00 as the zero
466+
hour of the next day, this notation is not supported by Elixir.
468467
469468
## Examples
470469

Diff for: lib/elixir/lib/calendar/iso.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ defmodule Calendar.ISO do
566566

567567
defp zero_pad(val, count) when val >= 0 do
568568
num = Integer.to_string(val)
569-
:binary.copy("0", count - byte_size(num)) <> num
569+
:binary.copy("0", max(count - byte_size(num), 0)) <> num
570570
end
571571

572572
defp zero_pad(val, count) do

Diff for: lib/elixir/lib/calendar/naive_datetime.ex

+3-4
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,9 @@ defmodule NaiveDateTime do
511511
As specified in the standard, the separator "T" may be omitted if
512512
desired as there is no ambiguity within this function.
513513
514-
Time representations with reduced accuracy are not supported.
515-
516-
Note that while ISO 8601 allows datetimes to specify 24:00:00 as the
517-
zero hour of the next day, this notation is not supported by Elixir.
514+
The year parsed by this function is limited to four digits and,
515+
while ISO 8601 allows datetimes to specify 24:00:00 as the zero
516+
hour of the next day, this notation is not supported by Elixir.
518517
519518
## Examples
520519

Diff for: lib/elixir/test/elixir/calendar/iso_test.exs

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ defmodule Calendar.ISOTest do
3535
end
3636
end
3737

38+
describe "date_to_iso8601/4" do
39+
test "handles years > 9999" do
40+
assert Calendar.ISO.date_to_iso8601(10000, 1, 1, :basic) == "100000101"
41+
assert Calendar.ISO.date_to_iso8601(10000, 1, 1, :extended) == "10000-01-01"
42+
end
43+
end
44+
3845
defp iso_day_roundtrip(year, month, day) do
3946
iso_days = Calendar.ISO.date_to_iso_days(year, month, day)
4047
Calendar.ISO.date_from_iso_days(iso_days)

0 commit comments

Comments
 (0)