IsoDuration class
IsoDuration - ISO 8061 Duration Data Type
The duration data type is used to specify a time interval.
This format is often used as response value in REST APIs (YouTube video duration or length of the flight).
The time interval is specified in the following form PnYnMnDTnHnMnS
where:
- P indicates the period (required)
- nY indicates the number of years
- nM indicates the number of months
- nD indicates the number of days
- T indicates the start of a time section (required if you are going to specify hours, minutes, or seconds)
- nH indicates the number of hours
- nM indicates the number of minutes
- nS indicates the number of seconds
Example:
IsoDuration.parse('P5Y'); // IsoDuration{years: 5, months: 0, weeks: 0, days: 0, hours: 0, minutes: 0, seconds: 0};
IsoDuration.parse('P3Y6M4DT12H30M5S'); // IsoDuration{years: 3, months: 6, weeks: 0, days: 4, hours: 12, minutes: 30, seconds: 5};
can parse also decimal:
IsoDuration.parse('PT8M40.215S'); // IsoDuration{years: 0, months: 0, weeks: 0, days: 0, hours: 0, minutes: 8, seconds: 40.215};
Note: This IsoDuration is not like Dart's implementation of Duration.
Despite the similar name, a Duration object does not implement "Durations" as specified by ISO 8601. In particular, a duration object does not keep track of the individually provided members (such as "days" or "hours"), but only uses these arguments to compute the length of the corresponding time interval.
See also:
Constructors
Properties
- days → double
-
The duration part in days, if was given, otherwise defaults to 0.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- hours → double
-
The duration part in hours, if was given, otherwise defaults to 0.
final
- isZero → bool
-
Returns
true
if all values of IsoDuration object are equal to 0.no setter - minutes → double
-
The duration part in minutes, if was given, otherwise defaults to 0.
final
- months → double
-
The duration part in months, if was given, otherwise defaults to 0.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- seconds → double
-
The duration part in seconds, if was given, otherwise defaults to 0.
final
- weeks → double
-
The duration part in weeks, if was given, otherwise defaults to 0.
final
- years → double
-
The duration part in years, if was given, otherwise defaults to 0.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toIso(
) → void - TODO: Unimplemented: Possibility to convert back to ISO
-
toSeconds(
) → double - Calculates total duration only in seconds from the IsoDuration object. It is a sum of all individual parts, except years and months.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
parse(
String input) → IsoDuration - Parses the ISO 8601 - Duration. If the operation was not successful then it throws FormatException.
-
tryParse(
String input) → IsoDuration? -
Like parse but safely parses the ISO 8601 - Duration and
returns
null
if theinput
is invalid.