curDateTimeByZone function

DateTime curDateTimeByZone (
  1. {@required String zone}
)

Takes a timezone, and returns the current DateTime in that timezone.

See timeZoneOffsets for all available time zones.

Implementation

DateTime curDateTimeByZone({@required String zone}) {
  var now = DateTime.now();
  DateTime toUTC = now.toUtc();
  DateTime returner;
  Duration subtr;
  Duration addr;
  if (timeZoneOffsets[zone] <= 0) {
    subtr = Duration(
        hours: timeZoneOffsets[zone].abs().truncate(),
        minutes: ((timeZoneOffsets[zone].abs() % 1) * 60).round());
    returner = toUTC.subtract(subtr);
  } else {
    addr = Duration(
        hours: timeZoneOffsets[zone].truncate(),
        minutes: ((timeZoneOffsets[zone] % 1) * 60).round());
    returner = toUTC.add(addr);
  }
  return returner;
}