mapLocal method

ZoneLocalMapping mapLocal(
  1. LocalDateTime localDateTime
)

Returns complete information about how the given LocalDateTime is mapped in this time zone.

Mapping a local date/time to a time zone can give an unambiguous, ambiguous or impossible result, depending on time zone transitions. Use the return value of this method to handle these cases in an appropriate way for your use case.

As an alternative, consider ResolveLocal(LocalDateTime, ZoneLocalMappingResolver), which uses a caller-provided strategy to convert the ZoneLocalMapping returned here to a ZonedDateTime.

  • localDateTime: The local date and time to map in this time zone.

Returns: A mapping of the given local date and time to zero, one or two zoned date/time values.

Implementation

ZoneLocalMapping mapLocal(LocalDateTime localDateTime) {
  LocalInstant localInstant = ILocalDateTime.toLocalInstant(localDateTime);
  Instant firstGuess = localInstant.minusZeroOffset();
  ZoneInterval interval = getZoneInterval(firstGuess);

  // Most of the time we'll go into here... the local instant and the instant
  // are close enough that we've found the right instant.
  if (IZoneInterval.containsLocal(interval, localInstant)) {
    ZoneInterval? earlier = _getEarlierMatchingInterval(interval, localInstant);
    if (earlier != null) {
      return IZoneLocalMapping.newZoneLocalMapping(this, localDateTime, earlier, interval, 2);
    }
    ZoneInterval? later = _getLaterMatchingInterval(interval, localInstant);
    if (later != null) {
      return IZoneLocalMapping.newZoneLocalMapping(this, localDateTime, interval, later, 2);
    }
    return IZoneLocalMapping.newZoneLocalMapping(this, localDateTime, interval, interval, 1);
  }
  else {
    // Our first guess was wrong. Either we need to change interval by one (either direction)
    // or we're in a gap.
    ZoneInterval? earlier = _getEarlierMatchingInterval(interval, localInstant);
    if (earlier != null) {
      return IZoneLocalMapping.newZoneLocalMapping(this, localDateTime, earlier, earlier, 1);
    }
    ZoneInterval? later = _getLaterMatchingInterval(interval, localInstant);
    if (later != null) {
      return IZoneLocalMapping.newZoneLocalMapping(this, localDateTime, later, later, 1);
    }
    return IZoneLocalMapping.newZoneLocalMapping(this, localDateTime, _getIntervalBeforeGap(localInstant), _getIntervalAfterGap(localInstant), 0);
  }
}