tzDuration static method
Returns a Duration object representing the offset from UTC indicated by the given timezone string.
If the length of the timezone string is not equal to
timezoneValueLength, returns null. Otherwise, extracts the hours and
minutes values from the timezone string and returns a Duration object
representing the offset from UTC. The hours and minutes values are parsed
from the substring of the timezone string starting at the index of the
utcString constant plus 1 and continuing for two characters (the hours
value), and the substring starting at the index of the utcString
constant plus 4 and continuing for two characters (the minutes value).
Implementation
static Duration? tzDuration(String timezone) {
if (timezone.length != timezoneValueLength) return null;
final hour = timezone.substring(utcString.length + 1, utcString.length + 3);
final min = timezone.substring(utcString.length + 4, timezoneValueLength);
final intHour = int.tryParse(hour);
final minutes = int.tryParse(min);
if (minutes == null || intHour == null) return null;
return Duration(hours: intHour, minutes: minutes);
}