-
Notifications
You must be signed in to change notification settings - Fork 119
Closed as not planned
Description
Right now all of the instances of DateTimeUnit
guard against instantiating with zero of the underlying asset. For example:
@Serializable(with = DayBasedDateTimeUnitSerializer::class)
public class DayBased(
/**
* The length of this unit in days.
*/
public val days: Int
) : DateBased() {
init {
require(days > 0) { "Unit duration must be positive, but was $days days." }
}
This feels really unintuitive. If someone is dynamically performing math operations of Instant
, LocalDate
, etc. it should be permissible to have an identity operation. Currently this requires null coalescing for identity-like operations. Eg:
val dateTimeUnit: DateTimeUnit? = /* TODO */
val date = clock.now().toLocalDate(/* omitted */).let { date ->
if (dateTimeUnit == null) date else date.minus(dateTimeUnit)
}
I'm hoping to understand the rationale for why zero of some DateTimeUnit
is generally prohibited. Thank you!
Metadata
Metadata
Assignees
Labels
No labels