Java Code Examples for java.time.LocalDateTime#getNano()

The following examples show how to use java.time.LocalDateTime#getNano() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalDateTimeSerializer.java    From jackson-modules-java8 with Apache License 2.0 6 votes vote down vote up
private final void _serializeAsArrayContents(LocalDateTime value, JsonGenerator g,
        SerializerProvider provider) throws IOException
{
    g.writeNumber(value.getYear());
    g.writeNumber(value.getMonthValue());
    g.writeNumber(value.getDayOfMonth());
    g.writeNumber(value.getHour());
    g.writeNumber(value.getMinute());
    final int secs = value.getSecond();
    final int nanos = value.getNano();
    if ((secs > 0) || (nanos > 0)) {
        g.writeNumber(secs);
        if (nanos > 0) {
            if (useNanoseconds(provider)) {
                g.writeNumber(nanos);
            } else {
                g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
            }
        }
    }
}
 
Example 2
Source File: DataTypeCodec.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private static void binaryEncodeDatetime(LocalDateTime value, ByteBuf buffer) {
  int year = value.getYear();
  int month = value.getMonthValue();
  int day = value.getDayOfMonth();
  int hour = value.getHour();
  int minute = value.getMinute();
  int second = value.getSecond();
  int microsecond = value.getNano() / 1000;

  // LocalDateTime does not have a zero value of month or day
  if (hour == 0 && minute == 0 && second == 0 && microsecond == 0) {
    buffer.writeByte(4);
    buffer.writeShortLE(year);
    buffer.writeByte(month);
    buffer.writeByte(day);
  } else if (microsecond == 0) {
    buffer.writeByte(7);
    buffer.writeShortLE(year);
    buffer.writeByte(month);
    buffer.writeByte(day);
    buffer.writeByte(hour);
    buffer.writeByte(minute);
    buffer.writeByte(second);
  } else {
    buffer.writeByte(11);
    buffer.writeShortLE(year);
    buffer.writeByte(month);
    buffer.writeByte(day);
    buffer.writeByte(hour);
    buffer.writeByte(minute);
    buffer.writeByte(second);
    buffer.writeIntLE(microsecond);
  }
}
 
Example 3
Source File: Main.java    From Java-Coding-Problems with MIT License 4 votes vote down vote up
public static void main(String[] args) {

        System.out.println("Before JDK 8:");

        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        int yearC = calendar.get(Calendar.YEAR);
        int monthC = calendar.get(Calendar.MONTH);
        int weekC = calendar.get(Calendar.WEEK_OF_MONTH);
        int dayC = calendar.get(Calendar.DATE);
        int hourC = calendar.get(Calendar.HOUR_OF_DAY);
        int minuteC = calendar.get(Calendar.MINUTE);
        int secondC = calendar.get(Calendar.SECOND);
        int millisC = calendar.get(Calendar.MILLISECOND);

        System.out.println("Date: " + date);
        System.out.println("Year: " + yearC + " Month: " + monthC
                + " Week: " + weekC + " Day: " + dayC + " Hour: " + hourC
                + " Minute: " + minuteC + " Second: " + secondC + " Millis: " + millisC);

        System.out.println("\nStarting with JDK 8:");
        
        LocalDateTime ldt = LocalDateTime.now();
        
        int yearLDT = ldt.getYear();
        int monthLDT = ldt.getMonthValue();
        int dayLDT = ldt.getDayOfMonth();
        int hourLDT = ldt.getHour();
        int minuteLDT = ldt.getMinute();
        int secondLDT = ldt.getSecond();
        int nanoLDT = ldt.getNano();                

        System.out.println("LocalDateTime: " + ldt);
        System.out.println("Year: " + yearLDT + " Month: " + monthLDT
                + " Day: " + dayLDT + " Hour: " + hourLDT + " Minute: " + minuteLDT 
                + " Second: " + secondLDT + " Nano: " + nanoLDT);
        
        int yearLDT2 = ldt.get(ChronoField.YEAR);
        int monthLDT2 = ldt.get(ChronoField.MONTH_OF_YEAR);
        int dayLDT2 = ldt.get(ChronoField.DAY_OF_MONTH);
        int hourLDT2 = ldt.get(ChronoField.HOUR_OF_DAY);
        int minuteLDT2 = ldt.get(ChronoField.MINUTE_OF_HOUR);
        int secondLDT2 = ldt.get(ChronoField.SECOND_OF_MINUTE);
        int nanoLDT2 = ldt.get(ChronoField.NANO_OF_SECOND);                
        
        System.out.println("Year: " + yearLDT2 + " Month: " + monthLDT2
                + " Day: " + dayLDT2 + " Hour: " + hourLDT2 + " Minute: " + minuteLDT2
                + " Second: " + secondLDT2 + " Nano: " + nanoLDT2);
    }
 
Example 4
Source File: Jdk8DateCodec.java    From uavstack with Apache License 2.0 4 votes vote down vote up
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
                  int features) throws IOException {
    SerializeWriter out = serializer.out;
    if (object == null) {
        out.writeNull();
    } else {
        if (fieldType == null) {
            fieldType = object.getClass();
        }

        if (fieldType == LocalDateTime.class) {
            final int mask = SerializerFeature.UseISO8601DateFormat.getMask();
            LocalDateTime dateTime = (LocalDateTime) object;
            String format = serializer.getDateFormatPattern();

            if (format == null) {
                if ((features & mask) != 0 || serializer.isEnabled(SerializerFeature.UseISO8601DateFormat)) {
                    format = formatter_iso8601_pattern;
                } else {
                    int nano = dateTime.getNano();
                    if (nano == 0) {
                        format = formatter_iso8601_pattern;
                    } else if (nano % 1000000 == 0) {
                        format = formatter_iso8601_pattern_23;
                    } else {
                        format = formatter_iso8601_pattern_29;
                    }
                }
            }

            if (format != null) {
                write(out, dateTime, format);
            } else if (out.isEnabled(SerializerFeature.WriteDateUseDateFormat)) {
                //使用固定格式转化时间
                write(out, dateTime, JSON.DEFFAULT_DATE_FORMAT);
            } else {
                out.writeLong(dateTime.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli());
            }
        } else {
            out.writeString(object.toString());
        }
    }
}
 
Example 5
Source File: Timestamp.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 6
Source File: Timestamp.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 7
Source File: Timestamp.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 8
Source File: ZoneOffsetTransition.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
    Objects.requireNonNull(transition, "transition");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (offsetBefore.equals(offsetAfter)) {
        throw new IllegalArgumentException("Offsets must not be equal");
    }
    if (transition.getNano() != 0) {
        throw new IllegalArgumentException("Nano-of-second must be zero");
    }
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 9
Source File: Timestamp.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 10
Source File: Timestamp.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 11
Source File: Timestamp.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 12
Source File: ZoneOffsetTransition.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
    Objects.requireNonNull(transition, "transition");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (offsetBefore.equals(offsetAfter)) {
        throw new IllegalArgumentException("Offsets must not be equal");
    }
    if (transition.getNano() != 0) {
        throw new IllegalArgumentException("Nano-of-second must be zero");
    }
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 13
Source File: ZoneOffsetTransition.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
    Objects.requireNonNull(transition, "transition");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (offsetBefore.equals(offsetAfter)) {
        throw new IllegalArgumentException("Offsets must not be equal");
    }
    if (transition.getNano() != 0) {
        throw new IllegalArgumentException("Nano-of-second must be zero");
    }
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 14
Source File: ZoneOffsetTransition.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
    Objects.requireNonNull(transition, "transition");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (offsetBefore.equals(offsetAfter)) {
        throw new IllegalArgumentException("Offsets must not be equal");
    }
    if (transition.getNano() != 0) {
        throw new IllegalArgumentException("Nano-of-second must be zero");
    }
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 15
Source File: Timestamp.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 16
Source File: ZoneOffsetTransition.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
    Objects.requireNonNull(transition, "transition");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (offsetBefore.equals(offsetAfter)) {
        throw new IllegalArgumentException("Offsets must not be equal");
    }
    if (transition.getNano() != 0) {
        throw new IllegalArgumentException("Nano-of-second must be zero");
    }
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 17
Source File: Timestamp.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 18
Source File: ZoneOffsetTransition.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
    Objects.requireNonNull(transition, "transition");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (offsetBefore.equals(offsetAfter)) {
        throw new IllegalArgumentException("Offsets must not be equal");
    }
    if (transition.getNano() != 0) {
        throw new IllegalArgumentException("Nano-of-second must be zero");
    }
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
Example 19
Source File: Timestamp.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 20
Source File: ZoneOffsetTransition.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
    Objects.requireNonNull(transition, "transition");
    Objects.requireNonNull(offsetBefore, "offsetBefore");
    Objects.requireNonNull(offsetAfter, "offsetAfter");
    if (offsetBefore.equals(offsetAfter)) {
        throw new IllegalArgumentException("Offsets must not be equal");
    }
    if (transition.getNano() != 0) {
        throw new IllegalArgumentException("Nano-of-second must be zero");
    }
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}