Skip to content

Add first and last day of year methods#770

Closed
PacificBird wants to merge 1 commit intotime-rs:mainfrom
PacificBird:start_and_end_of_year
Closed

Add first and last day of year methods#770
PacificBird wants to merge 1 commit intotime-rs:mainfrom
PacificBird:start_and_end_of_year

Conversation

@PacificBird
Copy link

Simple convenience methods for getting the start of the first and last days of the year for Date, PrimitiveDateTime, and OffsetDateTime. This is an easy ergonomics boost for the library, and is an infallible operation that is currently considered fallible with the existing API (using replace_ordinal).

I didn't make a separate test file for these, but since the doc-tests cover the gamut of the operation I hope that's okay. If there actually are more cases and you'd like a test suite let me know.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 0% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.8%. Comparing base (ac010e8) to head (9554c41).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
time/src/date.rs 0.0% 12 Missing ⚠️
time/src/offset_date_time.rs 0.0% 12 Missing ⚠️
time/src/primitive_date_time.rs 0.0% 12 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #770     +/-   ##
=======================================
- Coverage   94.2%   93.8%   -0.4%     
=======================================
  Files         96      97      +1     
  Lines      10732   11172    +440     
=======================================
+ Hits       10107   10475    +368     
- Misses       625     697     +72     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhpratt
Copy link
Member

jhpratt commented Feb 27, 2026

As stated in the "contributing" section of the README, it's best to open issues before working on an implementation. To put it simply, this is far from an ideal API because it's a method rather than an inherent function. Changing the time to midnight doesn't make any sense, either.

I would be open to something like start_of_year and end_of_year, but those would necessarily be fallible to handle validating the year range. For something infallible, the year validation would have to occur another way. I have plans to introduce new types, but that's not my top priority at the moment.

@jhpratt jhpratt closed this Feb 27, 2026
@jhpratt jhpratt added C-feature-request Category: a new feature (not already implemented) A-core Area: anything not otherwise covered labels Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-core Area: anything not otherwise covered C-feature-request Category: a new feature (not already implemented)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants