Skip to content

Commit 9c7604c

Browse files
Ignore microsecond precision when validating shift date duration (#13993)
1 parent a6ad2b8 commit 9c7604c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/elixir/lib/calendar/iso.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ defmodule Calendar.ISO do
17101710
hour: 0,
17111711
minute: 0,
17121712
second: 0,
1713-
microsecond: {0, 0}
1713+
microsecond: {0, _precision}
17141714
}) do
17151715
[
17161716
month: year * 12 + month,

lib/elixir/test/elixir/calendar/date_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ defmodule DateTest do
249249
"cannot shift date by time scale unit. Expected :year, :month, :week, :day",
250250
fn -> Date.shift(~D[2012-02-29], %Duration{second: 86400}) end
251251

252+
# Microsecond precision is ignored
253+
assert Date.shift(~D[2012-02-29], Duration.new!(microsecond: {0, 6})) == ~D[2012-02-29]
254+
255+
assert_raise ArgumentError,
256+
"cannot shift date by time scale unit. Expected :year, :month, :week, :day",
257+
fn -> Date.shift(~D[2012-02-29], %Duration{microsecond: {100, 6}}) end
258+
252259
# Implements calendar callback
253260
assert_raise RuntimeError, "shift_date/4 not implemented", fn ->
254261
date = Calendar.Holocene.date(10000, 01, 01)

0 commit comments

Comments
 (0)