Period class Relative times
Represents a period between two dates on a calendar.
Unlike Timespan and Duration, which both represent an absolute length of time, the exact time this represents varies according to the dates it's applied to. Some months are shorter or longer than others, as are some days (for example while "springing forward" or "falling back" for daylight savings time).
var d1 = LocalDate(2023, 2, 1);
var d2 = LocalDate(2023, 3, 2);
d1.periodUntil(d2) == Period(months: 1, days: 1);
d2.timespanUntil(d2) == Timespan(days: 29);
- Annotations
-
- @immutable
Constructors
Properties
- days → int
-
The number of days in the period.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- months → int
-
The number of months in the period.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- years → int
-
The number of years in the period.
final
Methods
-
normalize(
) → Period - Returns an equivalent period where months is less than 12 and all fields have matching signs.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
Formats the period as an ISO 8601 string.
override
Operators
-
operator ==(
Object other) → bool -
Tests whether this Period is exactly the same as another.
override
-
operator unary-(
) → Period - Negates all elements in the period.