-
Notifications
You must be signed in to change notification settings - Fork 103
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
Substitute for YearMonth? #168
Comments
|
data class YearMonth(val year: Int, val month: Month) for additional type safety. |
Well yes, but I think it would be nice for the library to provide it out of the box. Wouldn't you agree? |
Do you need this to support any operations that would meaningfully interact with the rest of the library? What functionality would you want from such a class? |
Things like |
|
I agree
Funnily enough my use case is a calendar with a month view that the user can swipe through. The current implementation takes a start and end |
See also my early draft PR #173 which could be the starting point for arbitrary precision date handling and type safety via sealed interfaces. Medical data comes with date fields containing Year or YearMonth or other arbitrary precision levels (within one single field) and we need to parse, display, sort, compare, etc. such values. It would be great to have that use-case supported in this lib instead of having everyone reinvent the wheel. |
Any updates on this? I'm happy to get something together in a PR, just need to know if it's something the maintainers want to go ahead with |
Another use case for me would be:
|
@morki, this does not explain why this would be useful. Sure, if |
For me only as a standardized wrapper with "well known" serialization. For example for parsing The other useful common type is |
We don't yet have a position to understand, or this issue would be closed one way or another. You're using Also, ISO 8601 describes serialization for this: |
Calendars, finance apps (your monthly bank statement), fitness apps (you ran how far this month?), sales reports... the concept of a specific month in a specific year is ubiquitous. |
Relevant for me. |
As a team transitioning away from Klock, I do make use of its YearMonth type and have been wanting a replacement for it. plus and minus for number of months is vital. Having it handle the fact that adding a month and having it take care of incrementing the years without having to handle this yourself is part of the usefulness. Some useful properties from Klock's implementation is number days in the month, number of days from the start of the year to the start of the month and number of days from end of month to end of year. We have a schedule part of our app. It may be showing a day, week, or month. When we load the data we load the given month, the previous month, and the next month. We cache the data loaded using the YearMonth as the key to the cache. So the current date is basically a Date that corresponds to the day in day mode or the first day of the week in week mode. With YearMonth i can just say something of the form:
I can't say the class is absolutely necessary. The alternative would be to use a LocalDate that is the first day of the month. YearMonth is just more convenient and doesn't cost a lot. |
java.time has a YearMonth class for referring to a particular month in the year, what's the kotlinx-datetime equivalent? LocalDate also stores a day of the month which isn't ideal
The text was updated successfully, but these errors were encountered: