curDateTimeByUtcOffset function

DateTime curDateTimeByUtcOffset (
  1. {@required double offset}
)

Takes a UTC offset, and returns the current DateTime with that offset.

Generally, dateTimeByZone is preferable for readability purposes, so use that if possible. Only use this if desired timezone is not listed in timeZoneOffsets.

Implementation

DateTime curDateTimeByUtcOffset({@required double offset}) {
  var now = DateTime.now().toUtc();
  DateTime returner;
  Duration subtr;
  Duration addr;
  if (offset <= 0) {
    subtr = Duration(
        hours: offset.abs().truncate(),
        minutes: ((offset.abs() % 1) * 60).round());
    returner = now.subtract(subtr);
  } else {
    addr = Duration(
        hours: offset.truncate(), minutes: ((offset % 1) * 60).round());
    returner = now.add(addr);
  }
  return returner;
}