Skip to content

feat: normalize use of chrono for time and datetime operations#2125

Open
taddes wants to merge 5 commits intomasterfrom
feat/use-chrono-for-time-operations-STOR-169
Open

feat: normalize use of chrono for time and datetime operations#2125
taddes wants to merge 5 commits intomasterfrom
feat/use-chrono-for-time-operations-STOR-169

Conversation

@taddes
Copy link
Collaborator

@taddes taddes commented Mar 12, 2026

Description

Due to the age of the code and a number of other reasons, we have often “hand crafted” datetime and duration values as integers or strings instead of using well-known constants provided by existing core libraries. In addition, we also tend to use string or u64 representations of times instead of using Instance and Duration values, which can lead to errors and confusion.

This PR aims to make our use more consistent in how we deal with timestamps and time values, favoring chrono yet maintaing std::time::Duration for those APIs like reqwest, deadpool, or actix and expect this in their signatures. We made these updates to Autopush also due to a history of bugs related to inconsistency.

There is mixed use of the time crate, chrono and Rust's standard std::time crate. There are instances in which the signature is maintained, in the example of tokio::time, since it would make needless conversions that complicate the code for no benefit.

The majority of use cases of std::time are related to capturing a duration since epoch, converting to milliseconds and then casting as an i64. Many Duration values remain intact as they are used for type consistency. In instances where Durations are derived and passed into a function, Duration::from_secs() is used, opposed to setting a TimeDelta and converting, which is cumbersome for these use cases.

Crate Current Role
chrono Database models, DateTime<Utc>, timestamp formatting, TimeDelta (to be favored as preferential implementation)
std::time Duration (pool/server timeouts), Instant (metrics), SystemTime/UNIX_EPOCH (timestamp generation)
time Duration::weeks(52) in syncserver only, therefore removed
tokio::time Async sleep/timeout — runtime requirement, cannot be replaced

Also fixes an issue with Glean Probe scraper that had the wrong sha.

Issue(s)

Closes STOR-169.

@taddes taddes self-assigned this Mar 12, 2026
@taddes taddes changed the title WIP: normalize use of chrono for time and datetime operations feat: normalize use of chrono for time and datetime operations Mar 13, 2026
@taddes taddes marked this pull request as ready for review March 13, 2026 19:05
@taddes taddes force-pushed the feat/use-chrono-for-time-operations-STOR-169 branch from 0d71dfc to 9b74b53 Compare March 13, 2026 19:05
@taddes taddes requested review from chenba and pjenvey March 13, 2026 19:19
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.

1 participant