Period class final
A Period represents a quantity of time in terms of its individual parts.
This is different from Duration which stores a quantity of time in microseconds. For example, a duration of 1 day is always 86,400,000,000 microseconds while a period of 1 day is 1 "day". Adding either to a DateTime or ZonedDateTime nearing a DST transition can produce different results.
// DST occurs at 2023-03-12 02:00
// https://www.timeanddate.com/time/change/usa/detroit?year=2023
final datetime = ZoneDateTime('America/Detroit', 2023, 3, 12);
datetime.add(Duration(days: 1)); // 2023-03-13 01:00 [America/Detroit]
datetime + Period(days: 1); // 2023-03-13 00:00 [America/Detroit]
A Period
is immutable. It's individual parts may be negative.
Unless otherwise stated, functions do not perform normalization. A period of "15 months" isn't automatically converted
to a period of "1 year and 3 months". Likewise, the aforementioned periods are not equal.
Constructors
Properties
- days → int
-
The days.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- hours → int
-
The hours.
final
- microseconds → int
-
The microseconds.
final
- milliseconds → int
-
The milliseconds.
final
- minutes → int
-
The minutes.
final
- months → int
-
The months.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- seconds → int
-
The seconds.
final
- years → int
-
The years.
final
Methods
-
copyWith(
{int? years, int? months, int? days, int? hours, int? minutes, int? seconds, int? milliseconds, int? microseconds}) → Period - Creates a copy of this with the updated units of time.
-
minus(
{int years = 0, int months = 0, int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) → Period - Returns a copy of this with the units of time subtracted.
-
normalize(
) → Period - Returns a normalized copy of this.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
plus(
{int years = 0, int months = 0, int days = 0, int hours = 0, int minutes = 0, int seconds = 0, int milliseconds = 0, int microseconds = 0}) → Period - Returns a copy of this with the units of time added.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator +(
Period other) → Period -
Returns the sum of this and
other
. -
operator -(
Period other) → Period -
Returns a copy of this with
other
subtracted. -
operator ==(
Object other) → bool -
The equality operator.
override