//core/io.islandtime.measures/Period
Period¶
common
@Serializable(with = PeriodIsoSerializer::class)
class Period
A date-based period of time, such as "2 years, 5 months, 16 days". Unlike Duration, which uses exact increments, a Period works with conceptual days, months, and years, ignoring daylight savings and length differences.
Types¶
| Name | Summary |
|---|---|
| Companion | common object Companion |
Properties¶
| Name | Summary |
|---|---|
| days | common val days: DaysThe number of days in this period. |
| months | common val months: MonthsThe number of months in this period. |
| totalMonths | common val totalMonths: MonthsThe total number of months in this period, including years. |
| years | common val years: YearsThe number of years in this period. |
Functions¶
| Name | Summary |
|---|---|
| component1 | common operator fun component1(): Years |
| component2 | common operator fun component2(): Months |
| component3 | common operator fun component3(): Days |
| copy | common fun copy(years: Years = this.years, months: Months = this.months, days: Days = this.days): PeriodReturns a new Period, replacing the years, months, and days components with new values, as desired |
| equals | common open operator override fun equals(other: Any?): Boolean |
| hashCode | common open override fun hashCode(): Int |
| isNegative | common fun isNegative(): BooleanChecks if any component of this period is negative. |
| isZero | common fun isZero(): BooleanChecks if this period is zero. |
| minus | common operator fun minus(days: Days): Periodoperator fun minus(months: Months): Periodoperator fun minus(weeks: Weeks): Periodoperator fun minus(years: Years): Periodcommon operator fun minus(other: Period): PeriodSubtracts each component of another period from this period. |
| normalized | common fun normalized(): PeriodNormalizes the number of years and months such that "1 year, 15 months" becomes "2 years, 3 months". Only the months and years components are combined. Days are never adjusted. |
| plus | common operator fun plus(days: Days): Periodoperator fun plus(months: Months): Periodoperator fun plus(weeks: Weeks): Periodoperator fun plus(years: Years): Periodcommon operator fun plus(other: Period): PeriodAdds each component of another period to each component of this period. |
| times | common operator fun times(scalar: Int): Periodoperator fun times(scalar: Long): PeriodMultiplies each component of this period by a scalar value. |
| toJavaPeriod | jvm fun Period.toJavaPeriod(): PeriodConverts this period to an equivalent Java Period. |
| toString | common open override fun toString(): StringReturns an ISO-8601 duration representation, such as "P1Y10M3D". |
| unaryMinus | common operator fun unaryMinus(): PeriodReverses the sign of each component in the period. |