-
Notifications
You must be signed in to change notification settings - Fork 541
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 functions to get start and end for other kinds of time periods #722
Comments
Hi @DavidMazarro - this is an interesting idea, these kind of functions (Especially ones dealing with adding/subtracting months in my experience) have quite wide applicability. That said there are a number of different ways to approach this which will suit different use cases and can generally be built on top of One existing crate that has some of this functionality is I also have a (very experimental) library which has a trait that looks quite similar to |
@DavidMazarro / @sestrella I'd like to talk about use cases. What are you trying to build and where do you run into limitations/gaps in the existing API? #666 seemed like a fairly simple extension but I'd like to explore the design space a bit more starting with the problem instead of a proposed solution to avoid XY problems. |
Had some excellent points from @avantgardnerio on this in #731
|
Some previous issues in this repo also discussed similar ideas:
This has also been discussed in
I think some things to be considered here are:
My thoughts on one way to implement this are:
|
One point to keep in mind is that some periods can be fairly cleanly represented as a |
My previous comment was probably a bit verbose, but you sum it up well with Month/Quarter/Year being in a different category from Minute and Hour (Day and Week are arguable due to timezone changes and leap seconds) My attempt at a more succinct explanation of my thoughts is below: Observations along a (for practical purposes) continuous set of possibilities. These are just
Observations along a discrete set of possibilities at regular intervals (not necessarily all of the same length in time). This includes
|
|
In the provided implementations we could have |
So it's not obvious to me that there's a lot of utility in having |
My main reasons for using types like this are:
Admittedly, these may be unusual use cases and may be outside the scope of |
Is "the minimal information" a conceptual concern or an actual memory size issue? |
Just a conceptual concern. But also practical for example when correlating values from two |
Following the spirit of #666, it would seem like a good idea to include utility functions like
first_day
andlast_day
for similar time periods such as months, quarters and years.To do this, @sestrella proposes to use a trait and have the corresponding types implement said trait to provide this functionality. For example:
The implementation of those functions for
NaiveWeek
would be refactored into an implementation of that trait forNaiveWeek
with this new change. Corresponding implementations would be provided for months and quarters as well as for any unmentioned period deemed useful.Another idea by @sestrella would be to expand this functionality a bit (WRT what's already done for
NaiveWeek
in #666) and include some sort of "iterator" functionality to the trait. For example:in this case, using
next
onTuesday
should yieldWednesday
and callingprev
onMonday
should yieldSunday
.The text was updated successfully, but these errors were encountered: