Skip to content
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

Merged
merged 35 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b6a6338
Improve the KDoc
dkhalanskyjb Mar 12, 2024
0a7298e
Fix typos and small mistakes
dkhalanskyjb Mar 18, 2024
e076439
Don't hyphenate ISO 8601 when used as a compound adjective
dkhalanskyjb Mar 21, 2024
ca9c739
Implement the first pack of fixes after the review
dkhalanskyjb Mar 21, 2024
c6dd47f
The second pack of changes
dkhalanskyjb Mar 22, 2024
1a4b0f9
Add samples for TimeZone, UtcOffset, and Month
dkhalanskyjb Apr 3, 2024
6883ffb
WIP: add samples for LocalTime
dkhalanskyjb Apr 4, 2024
671ee59
WIP: add samples for some formatting APIs
dkhalanskyjb Apr 5, 2024
bca9eab
More samples
dkhalanskyjb Apr 15, 2024
ba55ab6
Add samples for format builders
dkhalanskyjb Apr 15, 2024
85ab102
Samples for Date(Time)Period and Clock
dkhalanskyjb Apr 16, 2024
cccad01
fixup
dkhalanskyjb Apr 16, 2024
f3d4653
More samples; only LocalDate and Instant left
dkhalanskyjb Apr 16, 2024
77aff41
Samples for LocalDate
dkhalanskyjb Apr 16, 2024
d70657b
Finish adding samples
dkhalanskyjb Apr 17, 2024
3c956e0
Address the reviews
dkhalanskyjb Apr 17, 2024
788285c
Try to find the edge cases that work across platforms
dkhalanskyjb Apr 17, 2024
60ed765
reword
dkhalanskyjb Apr 17, 2024
fd8be7d
Update core/common/src/DateTimeUnit.kt
dkhalanskyjb Apr 19, 2024
1302b7e
Address the comments
dkhalanskyjb Apr 19, 2024
8f73a08
Clarify setting DateTimeComponents.month
dkhalanskyjb Apr 19, 2024
33a3717
Provide a one-line description for every sample
dkhalanskyjb Apr 19, 2024
a2af2de
More additions according to the reviews
dkhalanskyjb Apr 19, 2024
f7878af
feat: new docs review
danil-pavlov Apr 12, 2024
63644e6
Mention the relevant parts of ISO 8601 when describing formats
dkhalanskyjb Apr 30, 2024
e6b758e
Incorporate some more proofreading results
dkhalanskyjb Apr 30, 2024
517ae7a
Address the review
dkhalanskyjb May 1, 2024
f45e493
Address the review
dkhalanskyjb May 3, 2024
8a0e356
~fixup
dkhalanskyjb May 8, 2024
f70e422
Remove separate samples for Long overloads (plus a small fixup)
dkhalanskyjb May 10, 2024
6c1423a
Use yyyy instead of uuuu in the Unicode pattern sample
dkhalanskyjb May 10, 2024
fa59e05
Use Instant.fromEpochSeconds in samples more
dkhalanskyjb May 10, 2024
a529d44
Fix a broken sample reference
dkhalanskyjb May 10, 2024
a0a1335
Fix broken table rendering
dkhalanskyjb May 10, 2024
8851274
Properly display samples in Dokka
dkhalanskyjb May 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ To convert back, use the companion object function `Instant.fromEpochMillisecond
### Converting instant and local date/time to and from the ISO 8601 string

`Instant`, `LocalDateTime`, `LocalDate` and `LocalTime` provide shortcuts for
parsing and formatting them using the extended ISO-8601 format.
parsing and formatting them using the extended ISO 8601 format.
The `toString()` function is used to convert the value to a string in that format, and
the `parse` function in companion object is used to parse a string representation back.

Expand All @@ -201,7 +201,7 @@ LocalTime.parse("12:0:03.999") // fails with an IllegalArgumentException

### Working with other string formats

When some data needs to be formatted in some format other than ISO-8601, one
When some data needs to be formatted in some format other than ISO 8601, one
can define their own format or use some of the predefined ones:

```kotlin
Expand Down
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ val downloadWindowsZonesMapping by tasks.registering {
tasks.withType<AbstractDokkaLeafTask>().configureEach {
pluginsMapConfiguration.set(mapOf("org.jetbrains.dokka.base.DokkaBase" to """{ "templatesDir" : "${projectDir.toString().replace('\\', '/')}/dokka-templates" }"""))

failOnWarning.set(true)
dokkaSourceSets.configureEach {
kotlin.sourceSets.commonTest.get().kotlin.srcDirs.forEach { samples.from(it) }
// reportUndocumented.set(true) // much noisy output about `hashCode` and serializer encoders, decoders etc
skipDeprecated.set(true)
// Enum members and undocumented toString()
Expand Down
40 changes: 39 additions & 1 deletion core/common/src/Clock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,71 @@ import kotlin.time.*
* A source of [Instant] values.
*
* See [Clock.System][Clock.System] for the clock instance that queries the operating system.
*
* It is not recommended to use [Clock.System] directly in the implementation. Instead, you can pass a
* [Clock] explicitly to the necessary functions or classes.
* This way, tests can be written deterministically by providing custom [Clock] implementations
* to the system under test.
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
*/
public interface Clock {
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
/**
* Returns the [Instant] corresponding to the current time, according to this clock.
*
* It is not guaranteed that calling [now] later will return a larger [Instant].
* In particular, for [Clock.System] it is completely expected that the opposite will happen,
* and it must be taken into account.
* See the [System] documentation for details.
*
* Even though [Instant] is defined to be on the UTC-SLS time scale, which enforces a specific way of handling
* leap seconds, [now] is not guaranteed to handle leap seconds in any specific way.
*/
public fun now(): Instant

/**
* The [Clock] instance that queries the operating system as its source of knowledge of time.
* The [Clock] instance that queries the platform-specific system clock as its source of time knowledge.
*
* Successive calls to [now] will not necessarily return increasing [Instant] values, and when they do,
* these increases will not necessarily correspond to the elapsed time.
*
* For example, when using [Clock.System], the following could happen:
* - [now] returns `2023-01-02T22:35:01Z`.
* - The system queries the Internet and recognizes that its clock needs adjusting.
* - [now] returns `2023-01-02T22:32:05Z`.
*
* When you need predictable intervals between successive measurements, consider using [TimeSource.Monotonic].
*
* For improved testability, you should avoid using [Clock.System] directly in the implementation
* and pass a [Clock] explicitly instead. For example:
*
* @sample kotlinx.datetime.test.samples.ClockSamples.system
* @sample kotlinx.datetime.test.samples.ClockSamples.dependencyInjection
*/
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
public object System : Clock {
override fun now(): Instant = @Suppress("DEPRECATION_ERROR") Instant.now()
dkhalanskyjb marked this conversation as resolved.
Show resolved Hide resolved
}

/** A companion object used purely for namespacing. */
public companion object {

}
}

/**
* Returns the current date at the given [time zone][timeZone], according to [this Clock][this].
*
* The time zone is important because the current date is not the same in all time zones at the same instant.
*
* @sample kotlinx.datetime.test.samples.ClockSamples.todayIn
*/
public fun Clock.todayIn(timeZone: TimeZone): LocalDate =
now().toLocalDateTime(timeZone).date

qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
/**
* Returns a [TimeSource] that uses this [Clock] to mark a time instant and to find the amount of time elapsed since that mark.
*
* **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.
qwwdfsad marked this conversation as resolved.
Show resolved Hide resolved
*/
@ExperimentalTime
public fun Clock.asTimeSource(): TimeSource.WithComparableMarks = object : TimeSource.WithComparableMarks {
Expand Down
Loading