getTimeZoneOffset static method

int getTimeZoneOffset(
  1. String timeZone
)

(Incomplete/Incorrect Implementation)

Attempts to get the offset in minutes for a given timezone string. Warning: This implementation is incorrect. It does not actually use the timeZone parameter and returns the offset of the device's current time.

Implementation

static int getTimeZoneOffset(String timeZone) {
  DateTime now = DateTime.now();
  if (timeZone == 'UTC') {
    return 0;
  } else {
    String timeZoneOffset = now.toString().split(' ')[5];
    int hours = int.parse(timeZoneOffset.substring(1, 3));
    int minutes = int.parse(timeZoneOffset.substring(3, 5));
    int totalOffsetInMinutes = hours * 60 + minutes;
    return totalOffsetInMinutes;
  }
}