Time extension type

An immutable type representing a time of day without date components. All times are stored internally in UTC timezone. Any non-UTC input DateTime will be converted to UTC during construction.

Note the behavior of extension types in Dart (https://dart.dev/language/extension-types). For most intends and purposes a Time is a DateTime but the date component is not accessible. All operations are performed in UTC. See the GitHub repo for a discussion on whether this type should be a class or an extension type.

on

Constructors

Time.new(DateTime dateTime)
Creates a Time from a DateTime, stripping all date components and converting to UTC. If the input DateTime is not in UTC, it will be converted automatically.
Time.fromValues({required int hour, required int minute, int second = 0})
Creates a Time from hour, minute, and optional second values. The resulting Time will be in UTC.
Time.now()
Creates a Time representing the current time in UTC, using Zone-provided time if available.
factory

Properties

hour int
The hour component of the time (0-23) in UTC
no setter
minute int
The minute component of the time (0-59) in UTC
no setter
second int
The second component of the time (0-59) in UTC
no setter
totalSeconds int
Total number of seconds since midnight in UTC
no setter

Methods

compareTo(Time other) int
Compares two Time values in UTC, returning:
toIso8601String() String
Converts this Time to an ISO 8601 string. The output represents the time in UTC without timezone information.

Static Methods

tryParse(String timeString) Time?
Parses a time string in the format "HH:mm" or "HH:mm:ss", returning null if invalid. The input is assumed to be in UTC. If timezone information is provided, it will be converted to UTC.