Skip to content

Add local time #187

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

Merged
merged 5 commits into from
Apr 25, 2022
Merged

Add local time #187

merged 5 commits into from
Apr 25, 2022

Conversation

bishiboosh
Copy link
Contributor

Fixes #57

@bishiboosh bishiboosh requested a review from kluever March 5, 2022 15:18
Copy link
Contributor

@dkhalanskyjb dkhalanskyjb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! This is very similar to what we planned to implement.

* See [LocalTime.parse] for examples of time string representations.
*
* @throws IllegalArgumentException if the text cannot be parsed or the boundaries of [LocalTime] are exceeded.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API looks nice.

The documentation, I think, should be carefully reviewed and reworded. It's clearly copy-pasted with few changes from LocalDateTime, but some points just don't make as much sense here.

For example, is it a real concern that someone would think that LocalTime somehow includes the time zone? (For the record, Java does think so: https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html, maybe they have a point?) In any case, it should be enough to state it at most once that LocalTime doesn't know the date or the time zone. The less useless clutter there is in the docs, the easier it is to find the relevant parts.

@bishiboosh bishiboosh requested a review from dkhalanskyjb March 9, 2022 13:09
@bishiboosh
Copy link
Contributor Author

@dkhalanskyjb I also added some converter methods between LocalDate/LocalTime

check(minute, 0, 59, "minute")
check(second, 0, 59, "second")
check(nanosecond, 0, NANOS_PER_ONE - 1, "nanosecond")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it's safe, just a bit more extra work for the computer to do. Maybe we'll merge this as is and rework it later if benchmarks show that the impact is non-negligible.

@bishiboosh bishiboosh requested a review from dkhalanskyjb March 11, 2022 09:15
@dkhalanskyjb dkhalanskyjb requested a review from ilya-g March 24, 2022 11:01
@wakaztahir
Copy link

When will this be available , I really need this...

@dkhalanskyjb dkhalanskyjb merged commit dc5c965 into Kotlin:master Apr 25, 2022
@dkhalanskyjb
Copy link
Contributor

Thank you for the great work!

@bishiboosh bishiboosh deleted the local-time branch April 25, 2022 11:41
@ilya-g ilya-g added this to the 0.4.0 milestone Jun 22, 2022
@PaulWoitaschek
Copy link

What's the reason that LocalTime.Companion.MIN and MAX are internal? They seem to be unused, can they be made public?

@dkhalanskyjb
Copy link
Contributor

We probably just forgot to remove them at some point. We didn't plan to make them public, at least with those names. Do you need them for something?

@PaulWoitaschek
Copy link

Previously we had our own LocalTime implementation that looks 95% like this implementation.
We have a fasting feature where we use fasting periods that are represented by time ranges and we use LocalTime.Min and .Max to determine things like fasting streaks (how many consecutive days fasted etc).

For now we have our own extension:

import kotlinx.datetime.LocalTime

private val min = LocalTime(0, 0, 0, 0)
public val LocalTime.Companion.Min: LocalTime get() = min

private val max = LocalTime(23, 59, 59, 999_999_999)
public val LocalTime.Companion.Max: LocalTime get() = max

But I think it's justified to add these upstream in pairity with the javas LocalTime.

@dkhalanskyjb
Copy link
Contributor

Could you please show some code that uses these constants? I didn't quite grasp how they help with calculating the fasting streaks.

Also, if it's something non-trivial, please open a separate issue so that this rationale becomes easier to find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide time only representation, e.g. LocalTime
7 participants