Period class

A date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days'.

Implemented types

Constructors

Period({int days = 0, int months = 0, int years = 0})
Constructs a new Period instance from components.
const
Period.between(Temporal startInclusive, Temporal endExclusive)
Creates a new Period instance consisting of the number of years, months and days between startInclusive and endExclusive.
factory

Properties

days int
The days unit of this Period.
no setter
hashCode int
The hash code for this object.
no setteroverride
isNegative bool
Whether this Period is negative.
no setter
months int
The months unit of this Period.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
totalMonths int
The total number of months in this Period.
no setter
years int
The years unit of this Period.
no setter

Methods

addTo(Temporal temporal) Temporal
Returns a new instance of Temporal with this TemporalAmount added to the given temporal.
override
copyWith({int? years, int? months, int? days}) Period
Returns a new instance of this Period with the given individual properties adjusted.
minus(int amountToSubtract, ChronoUnit unit) Period
Returns a new instance of this TemporalAmount with the given amount subtracted.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
plus(int amountToAdd, ChronoUnit unit) Period
Returns a new instance of this TemporalAmount with the given amount added.
override
subtractFrom(Temporal temporal) Temporal
Returns a new instance of Temporal with this TemporalAmount subtracted from the given temporal.
override
toString() String
Returns a string representation of this Period.
override

Operators

operator +(Period other) Period
Adds this Period and other and returns the sum as a new Period object.
operator -(Period other) Period
Subtracts other from this Period and returns the difference as a new Period object.
operator ==(Object other) bool
Whether this Period is equal other.
override
operator unary-() Period
Creates a new Period with the opposite direction of this Period.

Constants

zero → const Period
A constant for a period of zero.