mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-25 13:36:41 +00:00
switch to jiff from chrono (#6205)
This PR migrates uv's use of `chrono` to `jiff`. I did most of this work a while back as one of my tests to ensure Jiff could actually be used in a real world project. I decided to revive this because I noticed that `reqwest-retry` dropped its Chrono dependency, which is I believe the only other thing requiring Chrono in uv. (Although, we use a fork of `reqwest-middleware` at present, and that hasn't been updated to latest upstream yet. I wasn't quite sure of the process we have for that.) In course of doing this, I actually made two changes to uv: First is that the lock file now writes an RFC 3339 timestamp for `exclude-newer`. Previously, we were using Chrono's `Display` implementation for this which is a non-standard but "human readable" format. I think the right thing to do here is an RFC 3339 timestamp. Second is that, in addition to an RFC 3339 timestamp, `--exclude-newer` used to accept a "UTC date." But this PR changes it to a "local date." That is, a date in the user's system configured time zone. I think this makes more sense than a UTC date, but one alternative is to drop support for a date and just rely on an RFC 3339 timestamp. The main motivation here is that automatically assuming UTC is often somewhat confusing, since just writing an unqualified date like `2024-08-19` is often assumed to be interpreted relative to the writer's "local" time.
This commit is contained in:
parent
c8f27a3978
commit
33480d61eb
38 changed files with 285 additions and 213 deletions
|
|
@ -1363,13 +1363,13 @@ fn unix_timestamp(time: SystemTime) -> u64 {
|
|||
}
|
||||
|
||||
fn rfc2822_to_unix_timestamp(s: &str) -> Option<u64> {
|
||||
rfc2822_to_datetime(s).and_then(|dt| u64::try_from(dt.timestamp()).ok())
|
||||
rfc2822_to_datetime(s).and_then(|timestamp| u64::try_from(timestamp.as_second()).ok())
|
||||
}
|
||||
|
||||
fn rfc2822_to_datetime(s: &str) -> Option<chrono::DateTime<chrono::Utc>> {
|
||||
chrono::DateTime::parse_from_rfc2822(s)
|
||||
fn rfc2822_to_datetime(s: &str) -> Option<jiff::Timestamp> {
|
||||
jiff::fmt::rfc2822::DateTimeParser::new()
|
||||
.parse_timestamp(s)
|
||||
.ok()
|
||||
.map(|dt| dt.to_utc())
|
||||
}
|
||||
|
||||
fn unix_timestamp_to_header(seconds: u64) -> Option<HeaderValue> {
|
||||
|
|
@ -1377,11 +1377,19 @@ fn unix_timestamp_to_header(seconds: u64) -> Option<HeaderValue> {
|
|||
}
|
||||
|
||||
fn unix_timestamp_to_rfc2822(seconds: u64) -> Option<String> {
|
||||
unix_timestamp_to_datetime(seconds).map(|dt| dt.to_rfc2822())
|
||||
use jiff::fmt::rfc2822::DateTimePrinter;
|
||||
|
||||
unix_timestamp_to_datetime(seconds).and_then(|timestamp| {
|
||||
let mut buf = String::new();
|
||||
DateTimePrinter::new()
|
||||
.print_timestamp(×tamp, &mut buf)
|
||||
.ok()?;
|
||||
Some(buf)
|
||||
})
|
||||
}
|
||||
|
||||
fn unix_timestamp_to_datetime(seconds: u64) -> Option<chrono::DateTime<chrono::Utc>> {
|
||||
chrono::DateTime::from_timestamp(i64::try_from(seconds).ok()?, 0)
|
||||
fn unix_timestamp_to_datetime(seconds: u64) -> Option<jiff::Timestamp> {
|
||||
jiff::Timestamp::from_second(i64::try_from(seconds).ok()?).ok()
|
||||
}
|
||||
|
||||
fn parse_seconds(value: &[u8]) -> Option<u64> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue