Skip to content

Comments

refactor: chrono to jiff#634

Merged
tisonkun merged 8 commits intomainfrom
jiff
Sep 29, 2025
Merged

refactor: chrono to jiff#634
tisonkun merged 8 commits intomainfrom
jiff

Conversation

@tisonkun
Copy link
Member

@tisonkun tisonkun commented Sep 22, 2025

This closes #631

Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
@tisonkun
Copy link
Member Author

I pushed some more commits to migrate services deps to chrono. Others should follow the same pattern. Must go to sleep now, though >~<

Signed-off-by: tison <[email protected]>
@Xuanwo
Copy link
Member

Xuanwo commented Sep 22, 2025

I pushed some more commits to migrate services deps to chrono. Others should follow the same pattern. Must go to sleep now, though >~<

Thank you for this!

Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
@tisonkun
Copy link
Member Author

All migrated. Then we'd see how this "breaking change" would impact our users.

I wonder if we'd wrap jiff's types and methods behind reqsign-core. Or anyway we'd deliver reqsign with jiff since it's the better option now.

Signed-off-by: tison <[email protected]>
Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Maybe @BurntSushi wanna take another look?

Copy link

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Overall LGTM! I left a few suggestions, but I don't see anything that is incorrect. :-)

/// - Day must be 2 digit.
pub fn format_http_date(t: DateTime) -> String {
t.format_with_items(HTTP_DATE.iter()).to_string()
t.strftime("%a, %d %b %Y %T GMT").to_string()

Choose a reason for hiding this comment

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

Would it make sense to use an explicit RFC 9110 printer instead?

Note that I can't immediately spot anything obviously wrong with what you have here. Probably the dedicated printer is faster, but I'm not sure if that matters given the String alloc here anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good to know. Updating.

Copy link
Member Author

Choose a reason for hiding this comment

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

After a closer look, I'd prefer the current consistent usage of strftime as it's correct.

Would you elaborate a bit on how switching to the RFC 9110 printer can benefit?

Copy link
Member Author

@tisonkun tisonkun Sep 25, 2025

Choose a reason for hiding this comment

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

Probably the dedicated printer is faster, but I'm not sure if that matters given the String alloc here anyway

Yeah .. I'd prefer code consistency for understandability unless a break has a strong reason.

Choose a reason for hiding this comment

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

Possibly perf. And I think it makes the code clearer to use a dedicated printer. But that's your call.

// Parse the string format "2023-10-31 21:59:10.000000"
chrono::NaiveDateTime::parse_from_str(&expires_str, "%Y-%m-%d %H:%M:%S%.f")
jiff::civil::DateTime::strptime("%Y-%m-%d %H:%M:%S%.f", &expires_str)
.and_then(|dt| jiff::tz::TimeZone::UTC.to_timestamp(dt))

Choose a reason for hiding this comment

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

This makes me somewhat sad. I realize this is what you were doing before, but assuming UTC for datetime string without any time zone or offset is kind of a bummer. It can be rather ambiguous. It's too easy for users to assume the wrong thing (e.g., a local time).

Copy link
Member Author

Choose a reason for hiding this comment

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

cc @Xuanwo is this an issue from Azure Storage that they explicitly declare the expires_on string is of UTC but returned without a timezone?

Copy link
Member Author

@tisonkun tisonkun Sep 29, 2025

Choose a reason for hiding this comment

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

Confirmed with @Xuanwo that these strings are UTC. It's the vendor's decision so you may report to them directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

let nano_time = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
let nano_time = SystemTime::now()
.duration_since(UNIX_EPOCH)

Choose a reason for hiding this comment

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

I think this is just jiff::Timestamp::now().as_nanosecond(). Although I guess that will behave differently than the code here for clocks set to a time before 1970-01-01T00:00:00Z.

Copy link
Member Author

Choose a reason for hiding this comment

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

I get your point. Although, I'd keep the current code as is and leave investigating such a refactor later.

Copy link
Member Author

Choose a reason for hiding this comment

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

That said, jiff::Timestamp::now().as_nanosecond() returns i128 where the current nano_time calculation retruns u128. Subtle issues often come from signed/unsigned integers .. Maybe in reality they are the same, but let's investigate it later.

Signed-off-by: tison <[email protected]>
@tisonkun
Copy link
Member Author

Resolved comments updated.

@tisonkun tisonkun merged commit a925881 into main Sep 29, 2025
46 checks passed
@tisonkun tisonkun deleted the jiff branch September 29, 2025 07:00
@tisonkun
Copy link
Member Author

@BurntSushi would you expect a new reqsign release for use?

@BurntSushi
Copy link

Ideally yeah! :-)

@tisonkun
Copy link
Member Author

@BurntSushi Got it. Typically, an ASF release takes 72 hours for community consensus, but @Xuanwo and I are about to take the National Day holiday, so it may not happen this week.

This is on my task list now, anyway :D

@BurntSushi
Copy link

Thank you!!!

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.

Add support for jiff instead of chrono

3 participants