DateTimeZone.forOffset constructor
DateTimeZone.forOffset(
- Offset offset
Returns a fixed time zone with the given offset.
The returned time zone will have an ID of 'UTC' if the offset is zero, or "UTC+/-Offset" otherwise. In the former case, the returned instance will be equal to utc.
Note also that this method is not required to return the same DateTimeZone instance for successive requests for the same offset; however, all instances returned for a given offset will compare as equal.
offset
: The offset for the returned time zone
Returns: A fixed time zone with the given offset.
Implementation
factory DateTimeZone.forOffset(Offset offset) {
int seconds = offset.inSeconds;
if (arithmeticMod(seconds, _fixedZoneCacheGranularitySeconds) != 0) {
return FixedDateTimeZone.forOffset(offset);
}
int index = (seconds - _fixedZoneCacheMinimumSeconds) ~/ _fixedZoneCacheGranularitySeconds;
if (index < 0 || index >= _fixedZoneCacheSize) {
return FixedDateTimeZone.forOffset(offset);
}
return _fixedZoneCache[index];
}