Kotlin / kotlinx-datetime

KotlinX multiplatform date/time library
Apache License 2.0
2.43k stars 102 forks source link

README documentation for `Instant::plus` method seems wrong #289

Closed raphael-dario closed 1 year ago

raphael-dario commented 1 year ago

the README says:

A particular amount of date/time units or a date/time period can be added to an Instant with the plus function:

val now = Clock.System.now()
val systemTZ = TimeZone.currentSystemDefault()
val tomorrow = now.plus(2, DateTimeUnit.DAY, systemTZ)
val threeYearsAndAMonthLater = now.plus(DateTimePeriod(years = 3, months = 1), systemTZ)

Using v0.4.0 on a KMM project, I can't seem to find those signatures. To add days, for example, I use the following:

dayCursor = dayCursor.plus(1.toDuration(DurationUnit.DAYS))

I'm guessing the README is outdated?

dkhalanskyjb commented 1 year ago

Using v0.4.0 on a KMM project, I can't seem to find those signatures

I just copy-pasted the code you're showing to the IDE where v0.4.0 is checked out, and it worked correctly with the latest version.

To add days, for example, I use the following

You shouldn't, it assumes 24-hour days and doesn't account for DST transitions.

raphael-dario commented 1 year ago

never mind, was missing an import, it does work after adding the missing import.