withOffset method

OffsetDateTime withOffset(
  1. Offset offset
)

Creates a new OffsetDateTime representing the instant in time in the same calendar, but with a different offset. The local date and time is adjusted accordingly.

  • offset: The new offset to use.

Returns: The converted OffsetDateTime.

Implementation

OffsetDateTime withOffset(Offset offset) {
  // Slight change to the normal operation, as it's *just* about plausible that we change day
  // twice in one direction or the other.
  // todo: pretty sure this isn't going to work out
  /*
  int days = 0;
  int nanos = clockTime.timeSinceMidnight.inNanoseconds + offset.inNanoseconds - _offsetNanoseconds;
  if (nanos >= TimeConstants.nanosecondsPerDay) {
    days++;
    nanos -= TimeConstants.nanosecondsPerDay;
    if (nanos >= TimeConstants.nanosecondsPerDay) {
      days++;
      nanos -= TimeConstants.nanosecondsPerDay;
    }
  }
  else if (nanos < 0) {
    days--;
    nanos += TimeConstants.nanosecondsPerDay;
    if (nanos < 0) {
      days--;
      nanos += TimeConstants.nanosecondsPerDay;
    }
  }

  return new OffsetDateTime(
      days == 0 ? _yearMonthDayCalendar : ILocalDate.yearMonthDayCalendar(calendarDate
          .addDays(days)), nanos, offset);
*/
  // return localDateTime.withOffset(offset);

  return OffsetDateTime._fromInstant(toInstant(), offset, calendar);
}