getTimeZoneOffset function

int? getTimeZoneOffset(
  1. String timezone
)

Parse a potential timezone string and return the time offset in minutes

Implementation

int? getTimeZoneOffset(String timezone) {
  // check if timezone is one of the known abbreviations
  var offset = timeZoneAbbreviations[timezone.toUpperCase()];
  if (offset != null) return offset;
  // check if the timezone is of type offset
  final match = offsetRegExp.firstMatch(timezone);
  if (match != null) {
    final sign = match.namedGroup('sign') == '-' ? -1 : 1;
    // we know <hours> and <minutes> are not null because the RexExp matched
    final hours = int.parse(match.namedGroup('hours')!);
    final minutes = int.parse(match.namedGroup('minutes')!);
    return sign * (60 * hours + minutes);
  }

  return null;
}