operator [] method

  1. @override
Future<DateTimeZone> operator [](
  1. String id
)
override

Returns the time zone for the given ID.

Unlike getZoneOrNull, this indexer will never return a null reference. If the ID is not supported by this provider, it will throw DateTimeZoneNotFoundException.

Note that this may return a DateTimeZone that has a different ID to that requested, if the ID provided is an alias.

Note also that this method is not required to return the same DateTimeZone instance for successive requests for the same ID; however, all instances returned for a given ID must compare as equal.

The fixed-offset timezones with IDs 'UTC' and "UTC+/-Offset" are always available.

  • id: The time zone id to find.

  • DateTimeZoneNotFoundException: This provider does not support the given ID.

Implementation

@override
Future<DateTimeZone> operator [](String id) async {
  var zone = await getZoneOrNull(id);
  if (zone == null) {
    throw DateTimeZoneNotFoundError('Time zone $id is unknown to source $versionId');
  }
  return zone;
}