Skip to content

How to round a Timestamp to the nearest SignedDuration? #270

Answered by BurntSushi
vultix asked this question in Q&A
Discussion options

You must be logged in to vote

But TimestampRound::from_duration still has the same problem I cited above. If you do TimestampRound::from_duration(...).smallest(Unit::Microsecond), what is its behavior?

And note that there are already a number of requirements on what increment values are considered legal. An error will occur if you get it wrong. This doesn't quite handle the error case of signed_duration.as_nanos() as i64 silently truncating though. But since the increment already has to divide evenly into 86,400 seconds, and 86,400,000,000,000 nanoseconds fits into an i64, it's hard for me to reason about exactly what could go wrong here.

In any case, as is a footgun unto itself. I'm not sure I want to be adding APIs …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@BurntSushi
Comment options

@BurntSushi
Comment options

@vultix
Comment options

@BurntSushi
Comment options

Answer selected by vultix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #269 on February 17, 2025 18:10.