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.

class Period

Types

Companion
Link copied to clipboard
common
object Companion

Functions

component1
Link copied to clipboard
common
operator fun component1(): IntYears
component2
Link copied to clipboard
common
operator fun component2(): IntMonths
component3
Link copied to clipboard
common
operator fun component3(): IntDays
copy
Link copied to clipboard
common

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

fun copy(years: IntYears, months: IntMonths, days: IntDays): Period
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

Checks if any component of this period is negative.

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

Checks if this period is zero.

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

Subtracts each component of another period from this period.

operator fun minus(other: Period): Period
operator fun minus(years: IntYears): Period
operator fun minus(months: IntMonths): Period
operator fun minus(weeks: IntWeeks): Period
operator fun minus(days: IntDays): Period
operator fun minus(years: LongYears): Period
operator fun minus(months: LongMonths): Period
operator fun minus(weeks: LongWeeks): Period
operator fun minus(days: LongDays): Period
normalized
Link copied to clipboard
common

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.

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

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

operator fun plus(other: Period): Period
operator fun plus(years: IntYears): Period
operator fun plus(months: IntMonths): Period
operator fun plus(weeks: IntWeeks): Period
operator fun plus(days: IntDays): Period
operator fun plus(years: LongYears): Period
operator fun plus(months: LongMonths): Period
operator fun plus(weeks: LongWeeks): Period
operator fun plus(days: LongDays): Period
times
Link copied to clipboard
common

Multiplies each component of this period by a scalar value.

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

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

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

Reverses the sign of each component in the period.

operator fun unaryMinus(): Period

Properties

days
Link copied to clipboard
common

The number of days in this period.

val days: IntDays
months
Link copied to clipboard
common

The number of months in this period.

val months: IntMonths
totalMonths
Link copied to clipboard
common

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

val totalMonths: LongMonths
years
Link copied to clipboard
common

The number of years in this period.

val years: IntYears

Extensions

toJavaPeriod
Link copied to clipboard

Converts this period to an equivalent Java Period.

fun Period.toJavaPeriod(): Period