-
Notifications
You must be signed in to change notification settings - Fork 102
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
Improve the KDoc #367
Improve the KDoc #367
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tremendous and solid work
39d8627
to
2b88030
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small batch from the stash
* ``` | ||
* | ||
* [parse] and [toString] methods can be used to obtain a [DateTimePeriod] from and convert it to a string in the | ||
* ISO 8601 extended format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way we can link to the ISO 8601 spec section which outlines time intervals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is it worth calling out what revision of ISO 8601 we're adhering to in every KDoc? For example, I previously misunderstood that LocalTime
should support 24:00
because it was included in ISO 8601:2004(E) , but I found out it was removed in later revisions of the spec. Being specific about what revision we support could help remove ambiguity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can only mention the relevant ISO 8601 section, but not link to it, because the standard is not in public access.
7e8f55e
to
daec006
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first part of comments
core/common/src/Clock.kt
Outdated
* **Pitfall**: using this function with [Clock.System] is error-prone, | ||
* because [Clock.System] is not well suited for measuring time intervals. | ||
* Please only use this conversion function on the [Clock] instances that are fully controlled programmatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to describe specifics of a time source obtained from a clock, but I wouldn't call this error prone and would avoid giving this recommendation "Please only use this conversion function on the [Clock] instances that are fully controlled programmatically."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other valid use cases do you see for this function? Related: #372
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, tracking timeouts tied to the wall clock. TimeMarks obtained from Instants can potentially be persistable between program runs, however we may currently lack the API to achieve that.
9fd3885
to
8391eff
Compare
core/common/src/DateTimeUnit.kt
Outdated
* [DateTimePeriod] is a combination of all [DateTimeUnit] values, used to express things like | ||
* "two days and three hours." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be unclear what "all [DateTimeUnit] values" means given that we declare many date-time units and there can also be arbitrary user-defined ones.
* | ||
* For values very far in the past or the future, this conversion may fail. | ||
* The specific range of values that can be converted to [LocalDateTime] is platform-specific, but at least | ||
* [DISTANT_PAST], [DISTANT_FUTURE], and all values between them can be converted to [LocalDateTime]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another way to say it is "all values in the range [DISTANT_PAST]..[DISTANT_FUTURE]", up to your decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like things like a..b
to be between backticks so that ..
is not treated as just some broken punctuation, but then, we can't have references to entities.
@qwwdfsad, IIRC, you're collecting feature requests for the KDoc syntax—navigable links in code blocks and inline code would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't hesitate to file it in Dokka with kdoc-spec
label
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
Fixes #347
Co-authored-by: ilya-g <ilya.gorbunov@jetbrains.com>
01650af
to
f7878af
Compare
core/common/src/LocalTime.kt
Outdated
* ### Platform specifics | ||
* | ||
* On the JVM, | ||
* there are `LocalTime.toJavaLocalTime()` and `java.time.LocalTime.toKotlinLocalTime()` extension functions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to mention for what are these extensions. (same for other entities for which we provide conversions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tough for me to think of a good way to say this without being tautological, but I tried. Is this what you meant?
core/common/src/LocalTime.kt
Outdated
@@ -49,9 +103,15 @@ public expect class LocalTime : Comparable<LocalTime> { | |||
* @throws IllegalArgumentException if [secondOfDay] is outside the `0 until 86400` range, | |||
* with 86400 being the number of seconds in a calendar day. | |||
* | |||
* It is incorrect to pass the number of seconds since the start of the day to this function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Together with the summary, it makes the impression that this function is inherently incorrect.
I believe that we should describe the model this entity represents and its discrepancies once in the class docs, and then refer to it instead of providing such note on each operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, the wording here is misleading. I tried correcting it.
@Test | ||
fun plusDuration() { | ||
// Finding a moment that's later than the starting point by the given amount of real time | ||
val instant = Instant.fromEpochMilliseconds(epochMilliseconds = 7 * 60 * 60 * 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more understandable to use instants obtained from parse
and show the result as toString
for arithmetic operation samples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using fromEpochMilliseconds
also serves to highlight the difference between Instant
and LocalDateTime
values. Newcomers are often confused by the distinction between them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear that overreliance on from/toEpochMilliseconds
in samples would convey the wrong idea that Instant is completely defined by that number of milliseconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with fromEpochSeconds
/epochSeconds + nanosecondsOfSecond
.
repeat(100) { | ||
val instant1 = randomInstant() | ||
val instant2 = randomInstant() | ||
check((instant1 < instant2) == (instant1.toEpochMilliseconds() < instant2.toEpochMilliseconds())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like a definition of this operation, whereas it is more nuanced. Better to use constant instants obtained from parse
@Test | ||
fun plusDuration() { | ||
// Finding a moment that's later than the starting point by the given amount of real time | ||
val instant = Instant.fromEpochMilliseconds(epochMilliseconds = 7 * 60 * 60 * 1000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fear that overreliance on from/toEpochMilliseconds
in samples would convey the wrong idea that Instant is completely defined by that number of milliseconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Let's address what is clear and merge it, leaving debatable things for further improvement.
// Printing a given date-time format as a Kotlin code snippet that creates the same format | ||
val customFormat = LocalDate.Format { | ||
@OptIn(FormatStringsInDatetimeFormats::class) | ||
byUnicodePattern("MM/dd uuuu") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to show the substitution for yyyy
which is more widespread instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Fixes #347
Not requesting the review initially, because I myself need to look at it with fresh eyes in a couple of days, but if someone's in the mood, they can point out the issues already. EDIT: after one more pass on my own, I've requested a review.