-
Notifications
You must be signed in to change notification settings - Fork 12
Align MIN/MAX/UNIX_EPOCH values across all fmt types using SignedDuration #168
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: martintmk <[email protected]>
Co-authored-by: martintmk <[email protected]>
Co-authored-by: martintmk <[email protected]>
Co-authored-by: martintmk <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #168 +/- ##
=======================================
Coverage 100.0% 100.0%
=======================================
Files 90 90
Lines 6497 6506 +9
=======================================
+ Hits 6497 6506 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
crates/tick/src/fmt/iso_8601.rs
Outdated
|
|
||
| /// The smallest value that can be represented by `Iso8601`. | ||
| /// | ||
| /// This represents the minimum timestamp supported by the underlying jiff library, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't mention jiff, use the same format for the MAX value, just mention the actual MIN value. Apply the same approach to all formats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated MIN documentation to match MAX format (just stating the actual value without mentioning jiff). Applied across all formats in commit e9dc454.
- Changed UnixSeconds to use SignedDuration instead of Duration - Updated MIN to match Iso8601/Rfc2822 MIN (-9999-01-01) - Simplified MIN documentation to match MAX format - Removed to_unix_epoch_duration() helper methods - All MIN/MAX/UNIX_EPOCH values now aligned across formats - Updated tests to work with signed values Co-authored-by: martintmk <[email protected]>
Co-authored-by: martintmk <[email protected]>
| } | ||
|
|
||
| #[test] | ||
| fn parse_max() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add parse_min (for all formats)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added parse_min tests for all three formats (Iso8601, Rfc2822, UnixSeconds) in commit 9212ac6.
crates/tick/src/fmt/unix_seconds.rs
Outdated
| } | ||
|
|
||
| impl TryFrom<Duration> for UnixSeconds { | ||
| impl TryFrom<SignedDuration> for UnixSeconds { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Hide this method, this exposes jiff
SignedDurationwhich we do not want to expose. - We want to only keep
impl TryFrom<Duration> for UnixSecondswhich will only ever produce UNixSeconds after UNIX epoch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hidden TryFrom by replacing it with TryFrom and a private helper method. Only Duration (not SignedDuration) is now exposed in the public API in commit 9212ac6.
- Replaced TryFrom<SignedDuration> with TryFrom<Duration> to avoid exposing jiff types - Added private try_from_signed_duration helper method - Added parse_min tests for all three formats (Iso8601, Rfc2822, UnixSeconds) - Updated tests to use Duration instead of SignedDuration - All 125 tests passing Co-authored-by: martintmk <[email protected]>
The MIN constants for
Iso8601,Rfc2822, andUnixSecondscurrently point toUNIX_EPOCH, but jiff supports timestamps back to approximately year -9999.Changes
Iso8601::MINandRfc2822::MIN: Now useTimestamp::MIN(1 January -9999 00:00:00 UTC) instead ofUNIX_EPOCHUnixSeconds::MIN: Changed to useSignedDurationinternally and now aligns with other formats (1 January -9999 00:00:00 UTC)UNIX_EPOCHto all three types for explicit epoch representation (1 January 1970 00:00:00 UTC)UnixSecondsnow usesSignedDurationinternally instead ofDurationto support timestamps before the Unix epochSignedDurationis kept internal - onlyDurationis exposed in the public API viaTryFrom<Duration>parse_mintests for all three formats to validate MIN constant behaviorBreaking Changes
UnixSeconds::from_secs()now acceptsi64instead ofu64UnixSeconds::to_secs()now returnsi64instead ofu64UnixSeconds::MINnow represents year -9999 instead of Unix epochUnixSecondsnow uses signed integers (i64)TryFrom<SignedDuration>(jiff type is no longer exposed)TryFrom<Duration>(accepts only positive durations from epoch)Behavior Notes
All MIN/MAX/UNIX_EPOCH values are now aligned across all three formats:
Use
UNIX_EPOCHwhen you need a timestamp guaranteed to be formattable/parseable across all formats. UseMIN/MAXto represent the full range supported by jiff.To create
UnixSecondsvalues, use:UnixSeconds::from_secs(i64)for positive or negative second valuesUnixSeconds::try_from(Duration)for positive durations onlyUnixSeconds::try_from(SystemTime)for system time conversionsIso8601orRfc2822typesOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.