Skip to content

Migrate from time to jiff library#297

Closed
Copilot wants to merge 12 commits intomainfrom
copilot/convert-time-library-to-jiff
Closed

Migrate from time to jiff library#297
Copilot wants to merge 12 commits intomainfrom
copilot/convert-time-library-to-jiff

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 8, 2026

Replaces time crate (v0.3) with jiff (v0.2.19) for cleaner time handling APIs and better timezone semantics.

Key API Changes

Types:

  • OffsetDateTimeTimestamp (always UTC, no offset confusion)
  • UtcOffsetTimeZone

Methods:

  • .unix_timestamp().as_second()
  • .nanosecond().subsec_nanosecond()
  • OffsetDateTime::now_utc()Timestamp::now()

Benefits

  • Explicit UTC semantics (Timestamp is always UTC)
  • Built-in serde support without feature flags
  • Handles pre-epoch times correctly
  • Cleaner timezone API: TimeZone::system() vs UtcOffset::current_local_offset()

Files Modified

  • Core: src/unix_time.rs (simplified from 79 to 11 lines)
  • Time handling: src/{band,entry,change}.rs, src/index/entry.rs, src/source/entry.rs
  • Transport: src/transport/{local,sftp,s3}.rs
  • Display: src/{show,bin/conserve,restore}.rs
  • Tests: tests/{old_archives,s3_integration}.rs

All modified files formatted with cargo fmt (import ordering, line breaks).

Original prompt

Could you draft a PR that converts from using the time library to using the newer jiff, and assess if that's cleaner or simpler?


💡 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 and others added 3 commits February 8, 2026 17:59
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert from time library to jiff for improved clarity Migrate from time to jiff for cleaner date/time handling Feb 8, 2026
Copilot AI requested a review from sourcefrog February 8, 2026 18:08
Comment thread src/unix_time.rs Outdated
}

#[allow(unused)] // really unused at present, but might be useful
pub(crate) trait ToOffsetDateTime {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot maybe just delete this now, unless it's actually used?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot actually please see if more of this file can be reduced or deleted?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Simplified in commit 26345ae. Removed all three traits (ToTimestamp, ToFileTime, FromUnixAndNanos) and replaced with:

  • Simple helper functions for the two needed conversions
  • jiff's built-in Timestamp::try_from(SystemTime) for SystemTime conversions

The file went from 79 lines to 18 lines.

… built-in conversions

Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Comment thread src/unix_time.rs Outdated
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copilot AI changed the title Migrate from time to jiff for cleaner date/time handling Add code formatting and pre-commit guidelines Feb 8, 2026
Copilot stopped work on behalf of sourcefrog due to an error February 8, 2026 19:30
AGENTS.md will be in a separate PR focused on contributor guidelines.
This PR should focus only on the jiff migration and code formatting.
Copilot AI changed the title Add code formatting and pre-commit guidelines Migrate from time to jiff library Feb 8, 2026
@sourcefrog
Copy link
Copy Markdown
Owner

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 2 commits April 16, 2026 14:21
…pilot/convert-time-library-to-jiff

Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
- Updated restore.rs to use .to_file_time() method instead of function
- Added std::time::Duration import for tests in transport/local.rs
- Fixed unused imports in source.rs, transport/local.rs, and transport/s3.rs

Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Apr 16, 2026

@copilot resolve the merge conflicts in this pull request

Resolved in commit aa7bbf7. Merged with main branch and fixed conflicts by using the ToFileTime trait approach and updating method calls in restore.rs. All 144 library tests pass.

@sourcefrog sourcefrog marked this pull request as ready for review April 16, 2026 14:39
Copilot AI review requested due to automatic review settings April 16, 2026 14:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the codebase’s time handling from the time crate to jiff, updating timestamp/duration operations and adjusting dependencies to align with the new time API.

Changes:

  • Update backup duration calculations to use jiff::Timestamp/jiff::Span instead of subtraction on time types.
  • Adjust tests to use jiff span calculations for elapsed time assertions.
  • Remove the time feature flag from tracing-subscriber configuration in Cargo.toml.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/show.rs Switches displayed backup-duration computation to jiff spans and converts to std::time::Duration for formatting.
src/band.rs Updates a timing-related test to compute elapsed time via jiff::Timestamp::since.
Cargo.toml Removes tracing-subscriber’s explicit time feature from the feature list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/show.rs
Comment on lines +96 to +103
let span = end_time.since(info.start_time).unwrap();
// Convert jiff::Span to std::time::Duration
match span.total(jiff::Unit::Nanosecond) {
Ok(total_nanos) if total_nanos >= 0.0 => {
let duration = std::time::Duration::from_nanos(total_nanos as u64);
duration_to_hms(duration).into()
}
_ => Cow::Borrowed("negative"),
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

end_time.since(info.start_time).unwrap() can panic if the span computation fails (e.g., corrupted metadata, out-of-range timestamps, or any error case since reports). Since this is user-facing output, handle the Err case and fall back to something like "unknown"/"negative" instead of panicking.

Suggested change
let span = end_time.since(info.start_time).unwrap();
// Convert jiff::Span to std::time::Duration
match span.total(jiff::Unit::Nanosecond) {
Ok(total_nanos) if total_nanos >= 0.0 => {
let duration = std::time::Duration::from_nanos(total_nanos as u64);
duration_to_hms(duration).into()
}
_ => Cow::Borrowed("negative"),
match end_time.since(info.start_time) {
Ok(span) => {
// Convert jiff::Span to std::time::Duration
match span.total(jiff::Unit::Nanosecond) {
Ok(total_nanos) if total_nanos >= 0.0 => {
let duration =
std::time::Duration::from_nanos(total_nanos as u64);
duration_to_hms(duration).into()
}
_ => Cow::Borrowed("negative"),
}
}
Err(_) => Cow::Borrowed("unknown"),

Copilot uses AI. Check for mistakes.
Comment thread src/show.rs
Comment on lines +97 to +103
// Convert jiff::Span to std::time::Duration
match span.total(jiff::Unit::Nanosecond) {
Ok(total_nanos) if total_nanos >= 0.0 => {
let duration = std::time::Duration::from_nanos(total_nanos as u64);
duration_to_hms(duration).into()
}
_ => Cow::Borrowed("negative"),
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

Converting Span to Duration via span.total(Unit::Nanosecond) (a float) and as u64 is lossy (truncation) and can silently saturate on out-of-range values. Prefer an integer-based conversion (or a TryFrom/helper provided by jiff for converting to std::time::Duration) and explicitly handle negative/out-of-range spans instead of relying on float casts.

Suggested change
// Convert jiff::Span to std::time::Duration
match span.total(jiff::Unit::Nanosecond) {
Ok(total_nanos) if total_nanos >= 0.0 => {
let duration = std::time::Duration::from_nanos(total_nanos as u64);
duration_to_hms(duration).into()
}
_ => Cow::Borrowed("negative"),
match std::time::Duration::try_from(span) {
Ok(duration) => duration_to_hms(duration).into(),
Err(_) => Cow::Borrowed("negative"),

Copilot uses AI. Check for mistakes.
@sourcefrog
Copy link
Copy Markdown
Owner

Done elsewhere

@sourcefrog sourcefrog closed this Apr 16, 2026
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.

3 participants