* @param offset the zone offset, not null
* @return the offset date-time, never null
* @throws CalendarConversionException if the instant exceeds the supported date range
*/
public static OffsetDateTime fromInstant(InstantProvider instantProvider, ZoneOffset offset) {
Instant instant = Instant.instant(instantProvider);
ISOChronology.checkNotNull(offset, "ZoneOffset must not be null");
long epochSecs = instant.getEpochSeconds() + offset.getAmountSeconds(); // overflow caught later
long yearZeroDays = (epochSecs / ISOChronology.SECONDS_PER_DAY) + ISOChronology.DAYS_0000_TO_1970;
int secsOfDay = (int) (epochSecs % ISOChronology.SECONDS_PER_DAY);
if (secsOfDay < 0) {
secsOfDay += ISOChronology.SECONDS_PER_DAY;
yearZeroDays--; // overflow caught later
}
LocalDate date = LocalDate.fromYearZeroDays(yearZeroDays);
LocalTime time = LocalTime.fromSecondOfDay(secsOfDay, instant.getNanoOfSecond());
LocalDateTime dateTime = LocalDateTime.dateTime(date, time);
return new OffsetDateTime(dateTime, offset);
}