-
Notifications
You must be signed in to change notification settings - Fork 533
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
Rename NaiveDate
and potentially remove Date<Tz>
#820
Comments
I am very on board with ditching |
This comment was marked as outdated.
This comment was marked as outdated.
I like just |
Fair enough. |
My thinking around the naming is as follows
All this being said, I'm keen to explore any use cases where specified dates are |
Hello, I am here because the 0.4.23 release notes request feedback on the deprecations in that release. I prefer the current implementation of For what I think is a typical correct usage of |
Thanks very much for the feedback @dtolnay. This is helpful as we don't have a way of surveying the ecosystem, so putting in depredations for our future plans is really the only option we have to see how the APIs are being used. Myself and @djc are keen to deprecate and eventually remove From my perspective, one potentially compelling reason for deprecation is that the actual current offset of a The other reason I am partial to is that the naming pushes users towards avoiding types beginning with The usage in However it looks like the intended usage in If a crate were to be published with that kind of functionality, would that be satisfactory for your use case to replace the current use of Alternatively, would a very minimal |
Storing the Reducing the public API of |
I just want to add my voice to the
above. |
@dtolnay thanks for the feedback! I've been thinking about your feedback quite a bit but ultimately I'm not sure I find it compelling. Your use case seems to be about storing what amounts to an interval of timestamps that are aligned to date boundaries. This works reasonably well with UTC but would pretty much fall down in the case of most other timezones that have something like daylight savings time, where you would have 2 25-hour days and 2 23-hour days per year. Because it only works well with UTC and other fixed-offset timezones, it seems to me that this could equally well be represented with the Another reason this probably only makes sense for As @esheppa explains, I think the |
I don't agree with the "pretty much falls down" characterization, since it works equally well with UTC and daylight-saving-having time zones as long as it's not a single offset that is stored, but the tz itself, like @esheppa mentions at the bottom of #820 (comment). Ignoring that option, I still don't agree that something supporting only fixed-offset time zones means it should use
That is not how I would handle that case in the db-dump crate. If crates.io's download count dates were a different time zone, I would define a zero-sized time zone and impl chrono::offset::TimeZone for it with a zero-sized offset type, to represent crates.io database time. I think it's especially important in this case that the crate wouldn't just be using
I don't think anyone was confusing these until your change. It's clear to me that "point in the calendar" is the point of |
So I guess maybe we should rename We've definitely seen people use this in surprising ways in the issues. |
What if we add impl<Tz: TimeZone + Copy> Day<Tz> {
fn start_time(&self) -> DateTime<Tz>;
fn date(&self) -> NaiveDate;
fn zone(&self) -> Tz;
}
impl<Tz: TimeZone + Copy> From<DateTime<Tz>> for Day<Tz> {
...
}
@dtolnay would it be satisfactory if Subsequently it could be kept in (The |
Yes, I think that's the right direction. Maybe |
While it seems so from the code above, my intention here is to allow
This is problematic due to the possibility of leap seconds. |
I've pushed up a branch with a basic implementation of this: #883. If the API is generally suitable then I'll go ahead and flesh out the documentation and add more tests |
That's what I meant by "it's doing double duty as some kind of semantic bound". We should either document how/why
Okay, makes sense. |
I swear I'm not trying to bikeshed and I like the idea of being able to backport this change to 0.4, but the parallel between More pedantically, a date is a combination of day, month, and year while day is part of a date but is not associated with a date. You have "day of the week," "day of the month," and "day of the year." But since you can go from the proposed Less pedantically and more intuitively, careful users are going to wonder what the semantic difference between "day" and "date" is, when in fact there is none and it's just a choice of names. If anything, the names could be reversed since On a completely different topic,
It doesn't have to be if |
@mqudsi - thanks for the feedback. Interestingly, it should be possible to put the impl of
Definitely agreed on this, and I think the choice of whether the type (if merged) is ultimately called
This is an interesting idea, but it has implications for methods like
Yes this makes sense, now implemented: Line 94 in 7169602
|
My vote goes to: |
@mqudsi - Thanks for the suggestion with the alternative Tz type, I've created an example at: #894. It potentially remains to be seen whether the This could be extended to
Thanks for these thoughts @Ten0. What do you think about #894? |
Unless I'm mistaken, some operations are naturally going to end up being faillible in Tz contexts and not in naive contexts (or the opposite). Implementing it this way seems dangerous with regards to flexibility (I suspect one would quickly hit "can't be specialized" errors), readability, as well as overall correctness. For instance, correctness: impl Offset for NotSpecified {
fn fix(&self) -> FixedOffset {
FixedOffset::ZERO
}
} with offset being defined as systematically a way to remap to UTC, would now be incorrect for that type, so that would have to be made unavailable in the API somehow. flexibility: readability: Overall I strongly believe that keeping on considering To expand a little on why I agree with making the
In my experience, mapping to the most semantically correct naming is always going to be what makes it most natural for users to understand the underlying concepts. |
Yes, I think we should stick with |
Thanks @Ten0 this is an excellent point. I'm keen to put words to this effect in the documentation itself to make a clear argument for having both types The dictionary definitions are good, perhaps we can include them as well, maybe from wiktionary (the license looks like it is compatible if we don't alter the definitions) |
First some past commentary:
Chrono RFC's: https://github.com/chronotope/chrono-rfcs/blob/master/notes/api-issues.md
chronotope/chrono-rfcs#1
chronotope/chrono-rfcs#3
#204
I think #204 has the right approach here, and this could be combined or kept separate from other renaming (eg potential renaming of
NaiveTime
):Date<Tz>
NaiveDate
toDate
We now have functions like
and_local_timezone
which offer an alternative way of constructing literals in a given timezone, however I think that making literals in a given timezone likeUtc.ymd(2018, 1, 1).and_hms(1, 2, 3)
is probably not the common case anyway, as they would often either be parsed, be the current time, or be some function of one of the previous.We could also use
LocalDate
instead ofDate
as mentioned in chronotope/chrono-rfcs#3 (comment) which is what java.time / NodaTime use - however my preference is justDate
.The text was updated successfully, but these errors were encountered: