diff --git a/ext/AccessorsDatesExt.jl b/ext/AccessorsDatesExt.jl index 392f527..9f9787c 100644 --- a/ext/AccessorsDatesExt.jl +++ b/ext/AccessorsDatesExt.jl @@ -16,9 +16,9 @@ set(x::Time, ::typeof(Dates.value), y) = @set x.instant.value = y set(x::Date, ::typeof(year), y) = Date(y, month(x), day(x)) set(x::Date, ::typeof(month), y) = Date(year(x), y, day(x)) set(x::Date, ::typeof(day), y) = Date(year(x), month(x), y) -set(x::Date, ::typeof(yearmonth), y::NTuple{2}) = Date(y..., day(x)) -set(x::Date, ::typeof(monthday), y::NTuple{2}) = Date(year(x), y...) -set(x::Date, ::typeof(yearmonthday), y::NTuple{3}) = Date(y...) +set(x::Date, ::typeof(yearmonth), y::NTuple{2, Any}) = Date(y..., day(x)) +set(x::Date, ::typeof(monthday), y::NTuple{2, Any}) = Date(year(x), y...) +set(x::Date, ::typeof(yearmonthday), y::NTuple{3, Any}) = Date(y...) set(x::Date, ::typeof(dayofweek), y) = firstdayofweek(x) + Day(y - 1) set(x::Time, ::typeof(hour), y) = Time(y, minute(x), second(x), millisecond(x), microsecond(x), nanosecond(x)) diff --git a/test/test_functionlenses.jl b/test/test_functionlenses.jl index 9ebdfc2..3157ae4 100644 --- a/test/test_functionlenses.jl +++ b/test/test_functionlenses.jl @@ -337,9 +337,9 @@ end test_getset_laws(lens, Time(1, 2, 3, 4, 5, 6), rand(0:23), rand(0:23)) end @testset for x in [DateTime(2020, 1, 2, 3, 4, 5, 6), Date(2020, 1, 2)] - test_getset_laws(yearmonth, x, (rand(1:5000), rand(1:12)), (rand(1:5000), rand(1:12))) - test_getset_laws(monthday, x, (rand(1:12), rand(1:28)), (rand(1:12), rand(1:28))) - test_getset_laws(yearmonthday, x, (rand(1:5000), rand(1:12), rand(1:28)), (rand(1:5000), rand(1:12), rand(1:28))) + test_getset_laws(yearmonth, x, (rand(1:5000), rand(1:12) |> Int8), (rand(1:5000), rand(1:12))) + test_getset_laws(monthday, x, (rand(1:12), rand(1:28) |> Int8), (rand(1:12), rand(1:28))) + test_getset_laws(yearmonthday, x, (rand(1:5000), rand(1:12) |> Int8, rand(1:28)), (rand(1:5000), rand(1:12), rand(1:28))) end @testset for x in [DateTime(2020, 1, 2, 3, 4, 5, 6), Date(2020, 1, 2), Time(1, 2, 3, 4, 5, 6)]