Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 29, 2025

The MIN constants for Iso8601, Rfc2822, and UnixSeconds currently point to UNIX_EPOCH, but jiff supports timestamps back to approximately year -9999.

Changes

  • Iso8601::MIN and Rfc2822::MIN: Now use Timestamp::MIN (1 January -9999 00:00:00 UTC) instead of UNIX_EPOCH
  • UnixSeconds::MIN: Changed to use SignedDuration internally and now aligns with other formats (1 January -9999 00:00:00 UTC)
  • New constants: Added UNIX_EPOCH to all three types for explicit epoch representation (1 January 1970 00:00:00 UTC)
  • Type change: UnixSeconds now uses SignedDuration internally instead of Duration to support timestamps before the Unix epoch
  • API encapsulation: SignedDuration is kept internal - only Duration is exposed in the public API via TryFrom<Duration>
  • Test coverage: Added parse_min tests for all three formats to validate MIN constant behavior

Breaking Changes

  • UnixSeconds::from_secs() now accepts i64 instead of u64
  • UnixSeconds::to_secs() now returns i64 instead of u64
  • UnixSeconds::MIN now represents year -9999 instead of Unix epoch
  • JSON serialization of UnixSeconds now uses signed integers (i64)
  • Removed TryFrom<SignedDuration> (jiff type is no longer exposed)
  • Added TryFrom<Duration> (accepts only positive durations from epoch)

Behavior Notes

All MIN/MAX/UNIX_EPOCH values are now aligned across all three formats:

// All MIN values are now equal (year -9999)
assert_eq!(Iso8601::from(Rfc2822::MIN), Iso8601::MIN);
assert_eq!(UnixSeconds::from(Iso8601::MIN), UnixSeconds::MIN);

// All MAX values remain equal (year 9999)
assert_eq!(Iso8601::from(UnixSeconds::MAX), Iso8601::MAX);

// All UNIX_EPOCH values are equal (1970-01-01)
assert_eq!(Iso8601::from(UnixSeconds::UNIX_EPOCH), Iso8601::UNIX_EPOCH);

Use UNIX_EPOCH when you need a timestamp guaranteed to be formattable/parseable across all formats. Use MIN/MAX to represent the full range supported by jiff.

To create UnixSeconds values, use:

  • UnixSeconds::from_secs(i64) for positive or negative second values
  • UnixSeconds::try_from(Duration) for positive durations only
  • UnixSeconds::try_from(SystemTime) for system time conversions
  • Conversions from Iso8601 or Rfc2822 types
Original prompt

This section details on the original issue you should resolve

<issue_title>tick: refine the MIN, MAX values for timestamps in fmt module</issue_title>
<issue_description>The tick crate exposes the following formats for SystemTime:

  • Iso8601
  • Rfc2822
  • UnixSeconds

All formats above expose MIN and MAX values. Currently, the MIN points to UNIX_EPOCH while the underlying jiff crate that we are using for parsing and serialization allows even lower min values.

Make the following changes across all 3 formats:

  • Update the MIN field value to refer to a MIN value as defined by jiff
  • Introduce UNIX_EPOCH field that that refers to UNICH epoch

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI changed the title [WIP] Refine MIN and MAX values for timestamps in fmt module Expose jiff's MIN timestamp and add UNIX_EPOCH constants to fmt types Dec 29, 2025
Copilot AI requested a review from martintmk December 29, 2025 13:24
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (04bc1b7) to head (2c53275).

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.
📢 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.


/// The smallest value that can be represented by `Iso8601`.
///
/// This represents the minimum timestamp supported by the underlying jiff library,
Copy link
Member

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.

Copy link
Contributor Author

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.

Copilot AI and others added 2 commits December 29, 2025 13:36
- 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]>
Copilot AI changed the title Expose jiff's MIN timestamp and add UNIX_EPOCH constants to fmt types Align MIN/MAX/UNIX_EPOCH values across all fmt types using SignedDuration Dec 29, 2025
Copilot AI requested a review from martintmk December 29, 2025 13:40
}

#[test]
fn parse_max() {
Copy link
Member

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)

Copy link
Contributor Author

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.

}

impl TryFrom<Duration> for UnixSeconds {
impl TryFrom<SignedDuration> for UnixSeconds {
Copy link
Member

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 SignedDuration which we do not want to expose.
  • We want to only keep impl TryFrom<Duration> for UnixSeconds which will only ever produce UNixSeconds after UNIX epoch

Copy link
Contributor Author

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]>
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.

tick: refine the MIN, MAX values for timestamps in fmt module

3 participants