Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Accessors for Day and higher #478

Merged
merged 9 commits into from
Oct 30, 2024
Merged

Add Accessors for Day and higher #478

merged 9 commits into from
Oct 30, 2024

Conversation

amsingh17
Copy link
Contributor

During a development project, I noticed that I was not able to run Day (or higher) on ZonedDateTime objects. The fix in this PR addresses that issue. Below is a minimum working example to show the issue

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.3 (2023-08-24)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using TimeZones, Dates

julia> x = ZonedDateTime(today(), tz"UTC")
2024-09-23T00:00:00+00:00

julia> Hour(x)
0 hours

julia> Day(x)
ERROR: MethodError: no method matching Day(::ZonedDateTime)

Closest candidates are:
  (::Type{T})(::Period) where T<:Period
   @ Dates /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Dates/src/periods.jl:384
  Day(::Number)
   @ Dates /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Dates/src/types.jl:55
  Day(::AbstractString)
   @ Dates /Applications/Julia-1.9.app/Contents/Resources/julia/share/julia/stdlib/v1.9/Dates/src/periods.jl:21
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[3]:1


Copy link

codecov bot commented Sep 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.57%. Comparing base (2bc8f50) to head (edf1e2a).
Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #478      +/-   ##
==========================================
- Coverage   92.79%   92.57%   -0.23%     
==========================================
  Files          39       38       -1     
  Lines        1818     1831      +13     
==========================================
+ Hits         1687     1695       +8     
- Misses        131      136       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@omus omus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests?

@omus
Copy link
Member

omus commented Sep 25, 2024

I originally added this accessor code when Dates.jl narrowed the types used for these sub-day accessors: 61d8299.

@amsingh17
Copy link
Contributor Author

@omus I've added a block of tests to use the Period of a ZonedDateTime. Open to suggestions on expanding additional coverage. Thanks!

Copy link
Member

@omus omus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to not access the internal fields

test/accessors.jl Outdated Show resolved Hide resolved
Co-authored-by: Curtis Vogt <curtis.vogt@gmail.com>
test/accessors.jl Outdated Show resolved Hide resolved
test/accessors.jl Outdated Show resolved Hide resolved
@omus
Copy link
Member

omus commented Oct 30, 2024

In looking over the code again I realized that part of the original implementation was avoiding defining additional methods where they weren't required. Defining methods for year, month, etc. aren't necessary as they use TimeType so I've refactored the code to define only the necessary accessors and constructor methods. I've also expanded the test suite to ensure that changes to Dates.jl don't break accessor support here.

@omus
Copy link
Member

omus commented Oct 30, 2024

Looks like I'll be dealing with LTS issues before getting this in.

Update: CI WeakDeps failure was just a fluke

@omus omus merged commit 114b222 into JuliaTime:master Oct 30, 2024
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants