Skip to content

Commit 0e295ae

Browse files
committed
Address the comments
1 parent 8e4364c commit 0e295ae

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

core/common/src/DateTimeUnit.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ import kotlin.time.Duration.Companion.nanoseconds
3535
* Arithmetic operations on [LocalDateTime] are not provided.
3636
* Please see the [LocalDateTime] documentation for a discussion.
3737
*
38-
* [DateTimePeriod] is a combination of all [DateTimeUnit] values, used to express things like
38+
* [DateTimePeriod] is a combination of [DateTimeUnit] values of every kind, used to express things like
3939
* "two days and three hours."
4040
* [DatePeriod] is specifically a combination of [DateTimeUnit.DateBased] values.
41-
* [DateTimePeriod] is more flexible than [DateTimeUnit] because it can express a combination of different units or
42-
* have the length of zero, but in exchange, the duration of time between two [Instant] or [LocalDate] values can be
41+
* [DateTimePeriod] is more flexible than [DateTimeUnit] because it can express a combination of values with different
42+
* kinds of units, but in exchange, the duration of time between two [Instant] or [LocalDate] values can be
4343
* measured in terms of some [DateTimeUnit], but not [DateTimePeriod] or [DatePeriod].
4444
*
4545
* ### Construction, serialization, and deserialization
@@ -48,9 +48,9 @@ import kotlin.time.Duration.Companion.nanoseconds
4848
* [DateTimeUnit.MONTH], and others.
4949
*
5050
* Two ways are provided to create custom [DateTimeUnit] instances:
51-
* - By multiplying an existing unit on the right by an integer scalar: for example, `DateTimeUnit.NANOSECOND * 10`.
51+
* - By multiplying an existing unit on the right by an integer scalar: for example, `DateTimeUnit.MICROSECOND * 10`.
5252
* - By constructing an instance manually with [TimeBased], [DayBased], or [MonthBased]: for example,
53-
* `DateTimeUnit.TimeBased(nanoseconds = 10)`.
53+
* `DateTimeUnit.TimeBased(nanoseconds = 10_000)`.
5454
*
5555
* Also, [DateTimeUnit] can be serialized and deserialized using `kotlinx.serialization`:
5656
* [DateTimeUnitSerializer], [DateBasedDateTimeUnitSerializer], [DayBasedDateTimeUnitSerializer],

core/common/src/Instant.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import kotlin.time.*
7676
* The [plus] and [minus] operators can be used to add [Duration]s to and subtract them from an [Instant]:
7777
*
7878
* ```
79-
* Clock.System.now() + Duration.seconds(5) // 5 seconds from now
79+
* Clock.System.now() + 5.seconds // 5 seconds from now
8080
* ```
8181
*
8282
* Durations can also be represented as multiples of some [time-based date-time unit][DateTimeUnit.TimeBased]:
@@ -631,7 +631,7 @@ public fun Instant.minus(unit: DateTimeUnit.TimeBased): Instant =
631631
* If the [value] is negative, the returned instant is earlier than this instant.
632632
*
633633
* Note that the time zone does not need to be passed when the [unit] is a time-based unit.
634-
* It is also not needed when adding date-based units to a [LocalDate].
634+
* It is also not needed when adding date-based units to a [LocalDate][LocalDate.plus].
635635
*
636636
* @throws DateTimeArithmeticException if this value or the result is too large to fit in [LocalDateTime].
637637
* @sample kotlinx.datetime.test.samples.InstantSamples.plusDateTimeUnit

core/common/src/LocalDate.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ public fun String.toLocalDate(): LocalDate = LocalDate.parse(this)
263263
* For finding an instant that corresponds to the start of a date in a particular time zone consider using
264264
* [LocalDate.atStartOfDayIn] function because a day does not always start at the fixed time 0:00:00.
265265
*
266+
* **Pitfall**: since [LocalDateTime] is not tied to a particular time zone, the resulting [LocalDateTime] may not
267+
* exist in the implicit time zone.
268+
* For example, `LocalDate(2021, 3, 28).atTime(2, 16, 20)` will successfully create a [LocalDateTime],
269+
* even though in Berlin, times between 2:00 and 3:00 do not exist on March 28, 2021 due to the transition to DST.
270+
*
266271
* @sample kotlinx.datetime.test.samples.LocalDateSamples.atTimeInline
267272
*/
268273
public fun LocalDate.atTime(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): LocalDateTime =
@@ -356,7 +361,7 @@ public operator fun LocalDate.minus(other: LocalDate): DatePeriod = other.period
356361
* - zero if this date is equal to the other.
357362
*
358363
* The value is rounded toward zero.
359-
364+
*
360365
* If the result does not fit in [Int], returns [Int.MAX_VALUE] for a positive result or [Int.MIN_VALUE] for a negative result.
361366
*
362367
* @see LocalDate.daysUntil
@@ -393,6 +398,8 @@ public expect fun LocalDate.monthsUntil(other: LocalDate): Int
393398
/**
394399
* Returns the number of whole years between two dates.
395400
*
401+
* The value is rounded toward zero.
402+
*
396403
* If the result does not fit in [Int], returns [Int.MAX_VALUE] for a positive result or [Int.MIN_VALUE] for a negative result.
397404
*
398405
* @see LocalDate.until

core/common/src/LocalDateTime.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import kotlinx.serialization.Serializable
1818
* For example, `2020-08-30T18:43` is not a *moment in time*, since someone in Berlin and someone in Tokyo would witness
1919
* this on their clocks at different times, but it is a [LocalDateTime].
2020
*
21-
* The main purpose of this class is to provide human-readable representations of [Instant] values, or to transfer them
22-
* as data.
23-
* Instances of [LocalDateTime] should not be stored when a specific time zone is known: in this case, it is recommended
24-
* to use [Instant] instead.
21+
* The main purpose of this class is to provide human-readable representations of [Instant] values, to transfer them
22+
* as data, or to define future planned events that will have the same local date-time even if the time zone rules
23+
* change.
24+
* In all other cases when a specific time zone is known, it is recommended to use [Instant] instead.
2525
*
2626
* ### Arithmetic operations
2727
*
@@ -30,7 +30,8 @@ import kotlinx.serialization.Serializable
3030
*
3131
* For example, in Berlin, naively adding one day to `2021-03-27T02:16:20` without accounting for the time zone would
3232
* result in `2021-03-28T02:16:20`.
33-
* However, this local date-time is invalid, because the clocks moved forward from `02:00` to `03:00` on that day.
33+
* However, the resulting local date-time cannot be observed in that time zone,
34+
* because the clocks moved forward from `02:00` to `03:00` on that day.
3435
* This is known as a "time gap", or a "spring forward" transition.
3536
*
3637
* Similarly, the local date-time `2021-10-31T02:16:20` is ambiguous,
@@ -39,8 +40,8 @@ import kotlinx.serialization.Serializable
3940
*
4041
* For these reasons, using [LocalDateTime] as an input to arithmetic operations is discouraged.
4142
*
42-
* When only arithmetic on the date component is needed, without touching the time, use [LocalDate] instead,
43-
* as it provides well-defined date arithmetic.
43+
* When only the date component is needed, without the time, use [LocalDate] instead.
44+
* It provides well-defined date arithmetic.
4445
*
4546
* If the time component must be taken into account, [LocalDateTime]
4647
* should be converted to [Instant] using a specific time zone, and the arithmetic on [Instant] should be used.
@@ -65,7 +66,8 @@ import kotlinx.serialization.Serializable
6566
* whether the given date and time components are valid in the implied time zone.
6667
* For example, `2021-03-28T02:16:20` is invalid in Berlin, as it falls into a time gap, but nothing prevents one
6768
* from constructing such a [LocalDateTime].
68-
* Before constructing a [LocalDateTime] using any API, please ensure that the result is valid in the implied time zone.
69+
* Before using a [LocalDateTime] constructed using any API,
70+
* please ensure that the result is valid in the implied time zone.
6971
* The recommended pattern is to convert a [LocalDateTime] to [Instant] as soon as possible (see
7072
* [LocalDateTime.toInstant]) and work with [Instant] values instead.
7173
*

0 commit comments

Comments
 (0)