-
Notifications
You must be signed in to change notification settings - Fork 119
Closed as not planned
Description
I just got hit by an exception when adding days to a LocalDate
I took a look at the function signature:
public actual fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate = plusNumber(1, unit)
So I was using DateTimeUnit.DateBased
to dynamically add days:
loopDate.plus(DateTimeUnit.DateBased.DayBased(fastingDays.size))
This was throwing an exception:
java.lang.IllegalArgumentException: Unit duration must be positive, but was 0 days.
at kotlinx.datetime.DateTimeUnit$DateBased$DayBased.<init>(DateTimeUnit.kt:68)
On the slack channel I discovered that I should not use the DayBased
constructor at all and instead use a period:
.plus(DatePeriod(days = 0))
I would suggest to mention that in the documentation and make the constructors internal so such usage errors don't happen.
Metadata
Metadata
Assignees
Labels
No labels