-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an interval type, or modify Duration to allow larger spans #52
Comments
That depends on what you mean by days. Unix Epoch timestamps don't include leap seconds, so incrementing the timestamp by 24*3600 always increases the time by one day. However if you want to count physical seconds, then you do need to worry about leap seconds. And if you have a scenario where you need to worry about leap seconds, then you somehow need to continually update a database of all past leap seconds, because it is impossible to predict when future leap seconds will be more than a few months in advance. |
It should be noted that there should be two slightly different difference types for date and time:
Note that there should be only one difference type of the first kind while there can be multiple difference types of the second kind. So Chrono's eventual difference type of the first kind (which is definitely not It might be possible that we can just provide everything reasonable: the eventual difference type may directly support I will keep this issue open to track support for other difference types of the second kind. |
given this, I wonder if there should be a trait for this second time, so that users can easily create new types for this. For example a user could add a duration/interval that uses units of a non-Gregorian calendar, or more esoteric time units, like sidereal days. I'm not entirely sure what the interface of that trait would look like since it would need to work with Date, DateTime, NaiveTime, NaiveDate, and NaiveDateTime. My initial suggestion would be something like: trait DurationLike {
fn addTo(&self, src: &NaiveDateTime) -> Option<NaiveDateTime>;
fn subFrom(&self, src: &NaiveDateTime) -> Option<NaiveDateTime>;
} although that interface has some limitations, like the fact that it would be rather awkward to implement |
@tmccombs You don't need a separate trait, you can just |
I suppose that's true. Although you would have to implement |
Is there any progress on this? I would really like to have a bug free to iterate over last few months |
We now have a dedicated issue on adding a |
It would be great to have a data type which behaves similarly to the PostgreSQL
interval
data type. Unlike the duration type currently in Rust Chrono, it stores days and months as separate fields. Days cannot be accurately represented in seconds without a reference instant due to the existence of leap seconds, and months cannot be represented in days or weeks for obvious reasons. It would be great to have a standard target for this type of data type.The text was updated successfully, but these errors were encountered: