translateToUtc method

int translateToUtc(
  1. int millisecondsSinceEpoch
)

translate instant in time expressed as milliseconds since January 1, 1970 00:00:00 to UTC.

Implementation

int translateToUtc(int millisecondsSinceEpoch) {
  final t = lookupTimeZone(millisecondsSinceEpoch);
  final tz = t.timeZone;
  final start = t.start;
  final end = t.end;

  var utc = millisecondsSinceEpoch;

  if (tz.offset != 0) {
    utc -= tz.offset;

    if (utc < start) {
      utc =
          millisecondsSinceEpoch - lookupTimeZone(start - 1).timeZone.offset;
    } else if (utc >= end) {
      utc = millisecondsSinceEpoch - lookupTimeZone(end).timeZone.offset;
    }
  }

  return utc;
}