Period

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

Companion
Link copied to clipboard
common
object Companion

Functions

component1
Link copied to clipboard
common
operator fun component1(): Years
component2
Link copied to clipboard
common
operator fun component2(): Months
component3
Link copied to clipboard
common
operator fun component3(): Days
copy
Link copied to clipboard
common
fun copy(years: Years = this.years, months: Months = this.months, days: Days = this.days): Period

Returns a new Period, replacing the years, months, and days components with new values, as desired

equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
isNegative
Link copied to clipboard
common
fun isNegative(): Boolean

Checks if any component of this period is negative.

isZero
Link copied to clipboard
common
fun isZero(): Boolean

Checks if this period is zero.

minus
Link copied to clipboard
common
operator fun minus(days: Days): Period
operator fun minus(months: Months): Period
operator fun minus(weeks: Weeks): Period
operator fun minus(years: Years): Period
operator fun minus(other: Period): Period

Subtracts each component of another period from this period.

normalized
Link copied to clipboard
common
fun normalized(): Period

Normalizes 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
Link copied to clipboard
common
operator fun plus(days: Days): Period
operator fun plus(months: Months): Period
operator fun plus(weeks: Weeks): Period
operator fun plus(years: Years): Period
operator fun plus(other: Period): Period

Adds each component of another period to each component of this period.

times
Link copied to clipboard
common
operator fun times(scalar: Int): Period
operator fun times(scalar: Long): Period

Multiplies each component of this period by a scalar value.

toString
Link copied to clipboard
common
open override fun toString(): String

Returns an ISO-8601 duration representation, such as "P1Y10M3D".

unaryMinus
Link copied to clipboard
common
operator fun unaryMinus(): Period

Reverses the sign of each component in the period.

Properties

days
Link copied to clipboard
common
val days: Days

The number of days in this period.

months
Link copied to clipboard
common
val months: Months

The number of months in this period.

totalMonths
Link copied to clipboard
common
val totalMonths: Months

The total number of months in this period, including years.

years
Link copied to clipboard
common
val years: Years

The number of years in this period.

Extensions

toJavaPeriod
Link copied to clipboard
fun Period.toJavaPeriod(): Period

Converts this period to an equivalent Java Period.