getOffsetMinutes method

double getOffsetMinutes(
  1. ILibDate date, {
  2. bool wallTime = false,
})

The total offset from UTC for date in minutes east of UTC (standard + DST when in effect).

Set wallTime true when date carries local wall-clock components (so a spring-forward gap is resolved as standard time); leave it false when date represents an absolute UTC instant.

Implementation

double getOffsetMinutes(ILibDate date, {bool wallTime = false}) {
  if (_isLocal) {
    if (wallTime && date.dst == null) {
      // From-components, no dst flag: resolve the offset from the wall components,
      // applying the spring-forward gap correction (hour-before check). For a
      // non-existent wall time the OS rolls forward and reports
      // the post-transition offset, which is larger (further east) than the hour
      // before; in that case use the pre-transition (hour-before) offset so the typed
      // wall clock is interpreted as if standard time still applied.
      // The Gregorian wall components are derived from the instant (calendar-agnostic),
      // since date.year/month/day are in the date's own calendar (ThaiSolar/Persian).
      final DateTime wall = DateTime.fromMillisecondsSinceEpoch(
          _instantMillis(date),
          isUtc: true);
      final double dOff = sysWallOffsetMinutes(
          wall.year, wall.month, wall.day, wall.hour, wall.minute);
      final double hbOff = sysWallOffsetMinutes(
          wall.year, wall.month, wall.day, wall.hour - 1, wall.minute);
      return dOff > hbOff ? hbOff : dOff;
    }
    if (!wallTime && date.dst == null) {
      // From-instant, unambiguous: ask the OS directly.
      return sysOffsetMinutesForInstant(_instantMillis(date));
    }
    // dst flag set (DST-end overlap): data-driven.
    return _offset +
        (inDaylightTime(date, wallTime: wallTime) ? _dstSavings : 0);
  }
  return _offset +
      (inDaylightTime(date, wallTime: wallTime) ? _dstSavings : 0);
}