From 7bfd2ad41ab33f35cd41de3d7ae9ec99b4352962 Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Mon, 23 Sep 2024 15:15:02 -0400 Subject: [PATCH 1/8] add accessors for Day and higher --- src/accessors.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/accessors.jl b/src/accessors.jl index 56df4dcb..b77c8858 100644 --- a/src/accessors.jl +++ b/src/accessors.jl @@ -1,4 +1,4 @@ -using Dates: Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond +using Dates: Quarter, Year, Month, Day, Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond """ timezone(::ZonedDateTime) -> TimeZone @@ -9,7 +9,7 @@ timezone(zdt::ZonedDateTime) = zdt.timezone Dates.days(zdt::ZonedDateTime) = days(DateTime(zdt)) -for period in (:Hour, :Minute, :Second, :Millisecond) +for period in (:Quarter, :Year, :Month, :Day, :Hour, :Minute, :Second, :Millisecond) accessor = Symbol(lowercase(string(period))) @eval begin Dates.$accessor(zdt::ZonedDateTime) = $accessor(DateTime(zdt)) From 5c76b0d570ed1ad1d2c4745b96b6b939873a4a0e Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Mon, 23 Sep 2024 17:05:38 -0400 Subject: [PATCH 2/8] add Week as an option as well --- src/accessors.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/accessors.jl b/src/accessors.jl index b77c8858..b5ce8a73 100644 --- a/src/accessors.jl +++ b/src/accessors.jl @@ -1,4 +1,4 @@ -using Dates: Quarter, Year, Month, Day, Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond +using Dates: Quarter, Year, Month, Week, Day, Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond """ timezone(::ZonedDateTime) -> TimeZone @@ -9,7 +9,7 @@ timezone(zdt::ZonedDateTime) = zdt.timezone Dates.days(zdt::ZonedDateTime) = days(DateTime(zdt)) -for period in (:Quarter, :Year, :Month, :Day, :Hour, :Minute, :Second, :Millisecond) +for period in (:Quarter, :Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond) accessor = Symbol(lowercase(string(period))) @eval begin Dates.$accessor(zdt::ZonedDateTime) = $accessor(DateTime(zdt)) From 72120f13cc03baf4667df825729f1ab37605c87c Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Wed, 25 Sep 2024 09:26:19 -0400 Subject: [PATCH 3/8] Year is larger than Quarter --- src/accessors.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/accessors.jl b/src/accessors.jl index b5ce8a73..9a03529f 100644 --- a/src/accessors.jl +++ b/src/accessors.jl @@ -1,4 +1,4 @@ -using Dates: Quarter, Year, Month, Week, Day, Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond +using Dates: Year, Quarter, Month, Week, Day, Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond """ timezone(::ZonedDateTime) -> TimeZone @@ -9,7 +9,7 @@ timezone(zdt::ZonedDateTime) = zdt.timezone Dates.days(zdt::ZonedDateTime) = days(DateTime(zdt)) -for period in (:Quarter, :Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond) +for period in (:Year, :Quarter, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond) accessor = Symbol(lowercase(string(period))) @eval begin Dates.$accessor(zdt::ZonedDateTime) = $accessor(DateTime(zdt)) From 52e7edb1f5f3dba0195c869c6892591f50f29c8c Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Wed, 25 Sep 2024 12:07:42 -0400 Subject: [PATCH 4/8] add tests for Period of ZonedDateTime --- test/accessors.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/accessors.jl b/test/accessors.jl index b65db109..a075ab5a 100644 --- a/test/accessors.jl +++ b/test/accessors.jl @@ -26,6 +26,13 @@ zdt = ZonedDateTime(DateTime(2014,6,12,23,59,58,57), fixed) @test Dates.monthday(zdt) == (6, 12) @test Dates.yearmonthday(zdt) == (2014, 6, 12) +# Also ensure that we can access the Period of ZonedDateTime +@test Dates.Year(zdt).value == 2014 +@test Dates.Month(zdt).value == 6 +@test Dates.Week(zdt).value == 24 +@test Dates.Day(zdt).value == 12 +@test Dates.Hour(zdt).value == 23 + # Vectorized accessors # Note: fill is used to test for size and equality. n = 10 From 150083037b4279efab3743566e15fe36a4cf5e82 Mon Sep 17 00:00:00 2001 From: Amit Singh <37706454+amsingh17@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:46:46 -0400 Subject: [PATCH 5/8] Update tests from PR suggestions Co-authored-by: Curtis Vogt --- test/accessors.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/accessors.jl b/test/accessors.jl index a075ab5a..7c2a58f7 100644 --- a/test/accessors.jl +++ b/test/accessors.jl @@ -27,11 +27,15 @@ zdt = ZonedDateTime(DateTime(2014,6,12,23,59,58,57), fixed) @test Dates.yearmonthday(zdt) == (2014, 6, 12) # Also ensure that we can access the Period of ZonedDateTime -@test Dates.Year(zdt).value == 2014 -@test Dates.Month(zdt).value == 6 -@test Dates.Week(zdt).value == 24 -@test Dates.Day(zdt).value == 12 -@test Dates.Hour(zdt).value == 23 +@test Dates.Year(zdt) == Dates.Year(2014) +@test Dates.Quarter(zdt) == Dates.Quarter(2) +@test Dates.Month(zdt) == Dates.Month(6) +@test Dates.Week(zdt) == Dates.Week(24) +@test Dates.Day(zdt) == Dates.Day(12) +@test Dates.Hour(zdt) == Dates.Hour(23) +@test Dates.Minute(zdt) == Dates.Hour(59) +@test Dates.Second(zdt) == Dates.Hour(58) +@test Dates.Millisecond(zdt) == Dates.Hour(57) # Vectorized accessors # Note: fill is used to test for size and equality. From 5449e1882ae777f61a03ba454ecdb5d8780f848d Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Wed, 25 Sep 2024 11:50:25 -0500 Subject: [PATCH 6/8] Update test/accessors.jl --- test/accessors.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/accessors.jl b/test/accessors.jl index 7c2a58f7..f03d99e3 100644 --- a/test/accessors.jl +++ b/test/accessors.jl @@ -33,8 +33,8 @@ zdt = ZonedDateTime(DateTime(2014,6,12,23,59,58,57), fixed) @test Dates.Week(zdt) == Dates.Week(24) @test Dates.Day(zdt) == Dates.Day(12) @test Dates.Hour(zdt) == Dates.Hour(23) -@test Dates.Minute(zdt) == Dates.Hour(59) -@test Dates.Second(zdt) == Dates.Hour(58) +@test Dates.Minute(zdt) == Dates.Minute(59) +@test Dates.Second(zdt) == Dates.Second(58) @test Dates.Millisecond(zdt) == Dates.Hour(57) # Vectorized accessors From 1c414a8e38668d93ff2dcc8b123b48382b8d5920 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Wed, 25 Sep 2024 11:50:44 -0500 Subject: [PATCH 7/8] Update test/accessors.jl --- test/accessors.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/accessors.jl b/test/accessors.jl index f03d99e3..7a186201 100644 --- a/test/accessors.jl +++ b/test/accessors.jl @@ -35,7 +35,7 @@ zdt = ZonedDateTime(DateTime(2014,6,12,23,59,58,57), fixed) @test Dates.Hour(zdt) == Dates.Hour(23) @test Dates.Minute(zdt) == Dates.Minute(59) @test Dates.Second(zdt) == Dates.Second(58) -@test Dates.Millisecond(zdt) == Dates.Hour(57) +@test Dates.Millisecond(zdt) == Dates.Millisecond(57) # Vectorized accessors # Note: fill is used to test for size and equality. From 1729ae141cb8aafbf2c96a9938e019a21b05c6d9 Mon Sep 17 00:00:00 2001 From: Amit Singh Date: Wed, 25 Sep 2024 15:56:59 -0400 Subject: [PATCH 8/8] Accessor and period names differ for Quarter --- src/accessors.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/accessors.jl b/src/accessors.jl index 9a03529f..119a883f 100644 --- a/src/accessors.jl +++ b/src/accessors.jl @@ -1,4 +1,4 @@ -using Dates: Year, Quarter, Month, Week, Day, Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond +using Dates: Year, Month, Week, Day, Hour, Minute, Second, Millisecond, days, hour, minute, second, millisecond """ timezone(::ZonedDateTime) -> TimeZone @@ -9,7 +9,7 @@ timezone(zdt::ZonedDateTime) = zdt.timezone Dates.days(zdt::ZonedDateTime) = days(DateTime(zdt)) -for period in (:Year, :Quarter, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond) +for period in (:Year, :Month, :Week, :Day, :Hour, :Minute, :Second, :Millisecond) accessor = Symbol(lowercase(string(period))) @eval begin Dates.$accessor(zdt::ZonedDateTime) = $accessor(DateTime(zdt)) @@ -17,6 +17,9 @@ for period in (:Year, :Quarter, :Month, :Week, :Day, :Hour, :Minute, :Second, :M end end +Dates.quarter(zdt::ZonedDateTime) = Dates.quarterofyear(DateTime(zdt)) +Dates.Quarter(zdt::ZonedDateTime) = Dates.Quarter(quarterofyear(zdt)) + Base.eps(::ZonedDateTime) = Millisecond(1)