static LocalTime readExternal(DataInput in) throws IOException { int hour = in.readByte(); int minute = 0; int second = 0; int nano = 0; if (hour < 0) { hour = ~hour; } else { minute = in.readByte(); if (minute < 0) { minute = ~minute; } else { second = in.readByte(); if (second < 0) { second = ~second; } else { nano = in.readInt(); } } } return LocalTime.of(hour, minute, second, nano); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this date at the * specified hour, minute and second. * The nanosecond field will be set to zero. * The individual time fields must be within their valid range. * All possible combinations of date and time are valid. * * @param hour the hour-of-day to use, from 0 to 23 * @param minute the minute-of-hour to use, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @return the local date-time formed from this date and the specified time, not null * @throws DateTimeException if the value of any field is out of range */ public LocalDateTime atTime(int hour, int minute, int second) { return atTime(LocalTime.of(hour, minute, second)); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this date at the * specified hour, minute, second and nanosecond. * The individual time fields must be within their valid range. * All possible combinations of date and time are valid. * * @param hour the hour-of-day to use, from 0 to 23 * @param minute the minute-of-hour to use, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999 * @return the local date-time formed from this date and the specified time, not null * @throws DateTimeException if the value of any field is out of range */ public LocalDateTime atTime(int hour, int minute, int second, int nanoOfSecond) { return atTime(LocalTime.of(hour, minute, second, nanoOfSecond)); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this date at the * specified hour, minute and second. * The nanosecond field will be set to zero. * The individual time fields must be within their valid range. * All possible combinations of date and time are valid. * * @param hour the hour-of-day to use, from 0 to 23 * @param minute the minute-of-hour to use, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @return the local date-time formed from this date and the specified time, not null * @throws DateTimeException if the value of any field is out of range */ public LocalDateTime atTime(int hour, int minute, int second) { return atTime(LocalTime.of(hour, minute, second)); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this date at the * specified hour, minute, second and nanosecond. * The individual time fields must be within their valid range. * All possible combinations of date and time are valid. * * @param hour the hour-of-day to use, from 0 to 23 * @param minute the minute-of-hour to use, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999 * @return the local date-time formed from this date and the specified time, not null * @throws DateTimeException if the value of any field is out of range */ public LocalDateTime atTime(int hour, int minute, int second, int nanoOfSecond) { return atTime(LocalTime.of(hour, minute, second, nanoOfSecond)); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this date at the * specified hour and minute. * The seconds and nanosecond fields will be set to zero. * The individual time fields must be within their valid range. * All possible combinations of date and time are valid. * * @param hour the hour-of-day to use, from 0 to 23 * @param minute the minute-of-hour to use, from 0 to 59 * @return the local date-time formed from this date and the specified time, not null * @throws DateTimeException if the value of any field is out of range */ public LocalDateTime atTime(int hour, int minute) { return atTime(LocalTime.of(hour, minute)); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this date at the * specified hour and minute. * The seconds and nanosecond fields will be set to zero. * The individual time fields must be within their valid range. * All possible combinations of date and time are valid. * * @param hour the hour-of-day to use, from 0 to 23 * @param minute the minute-of-hour to use, from 0 to 59 * @return the local date-time formed from this date and the specified time, not null * @throws DateTimeException if the value of any field is out of range */ public LocalDateTime atTime(int hour, int minute) { return atTime(LocalTime.of(hour, minute)); }
/** * Obtains an instance of {@code OffsetTime} from an hour, minute, second and nanosecond. * <p> * This creates an offset time with the four specified fields. * <p> * This method exists primarily for writing test cases. * Non test-code will typically use other methods to create an offset time. * {@code LocalTime} has two additional convenience variants of the * equivalent factory method taking fewer arguments. * They are not provided here to reduce the footprint of the API. * * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999 * @param offset the zone offset, not null * @return the offset time, not null * @throws DateTimeException if the value of any field is out of range */ public static OffsetTime of(int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset) { return new OffsetTime(LocalTime.of(hour, minute, second, nanoOfSecond), offset); }
/** * Obtains an instance of {@code OffsetTime} from an hour, minute, second and nanosecond. * <p> * This creates an offset time with the four specified fields. * <p> * This method exists primarily for writing test cases. * Non test-code will typically use other methods to create an offset time. * {@code LocalTime} has two additional convenience variants of the * equivalent factory method taking fewer arguments. * They are not provided here to reduce the footprint of the API. * * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999 * @param offset the zone offset, not null * @return the offset time, not null * @throws DateTimeException if the value of any field is out of range */ public static OffsetTime of(int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset) { return new OffsetTime(LocalTime.of(hour, minute, second, nanoOfSecond), offset); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour, minute, second and nanosecond. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute, second, nanoOfSecond); return new LocalDateTime(date, time); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour, minute, second and nanosecond. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute, second, nanoOfSecond); return new LocalDateTime(date, time); }
/** * Converts a {@code java.sql.Time} to a {@code LocalTime}. * * @param sqlTime the SQL time, not null * @return the local time, not null */ @SuppressWarnings("deprecation") public static LocalTime toLocalTime(java.sql.Time sqlTime) { return LocalTime.of(sqlTime.getHours(), sqlTime.getMinutes(), sqlTime.getSeconds()); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour and minute, setting the second and nanosecond to zero. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * The second and nanosecond fields will be set to zero. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, not null * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute); return new LocalDateTime(date, time); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour and minute, setting the second and nanosecond to zero. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * The second and nanosecond fields will be set to zero. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute); return new LocalDateTime(date, time); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour, minute, second and nanosecond. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, not null * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @param nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute, second, nanoOfSecond); return new LocalDateTime(date, time); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour and minute, setting the second and nanosecond to zero. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * The second and nanosecond fields will be set to zero. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute); return new LocalDateTime(date, time); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour, minute and second, setting the nanosecond to zero. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * The nanosecond field will be set to zero. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute, second); return new LocalDateTime(date, time); }
/** * Obtains an instance of {@code LocalDateTime} from year, month, * day, hour, minute and second, setting the nanosecond to zero. * <p> * The day must be valid for the year and month, otherwise an exception will be thrown. * The nanosecond field will be set to zero. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, not null * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @param hour the hour-of-day to represent, from 0 to 23 * @param minute the minute-of-hour to represent, from 0 to 59 * @param second the second-of-minute to represent, from 0 to 59 * @return the local date-time, not null * @throws DateTimeException if the value of any field is out of range * @throws DateTimeException if the day-of-month is invalid for the month-year */ public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second) { LocalDate date = LocalDate.of(year, month, dayOfMonth); LocalTime time = LocalTime.of(hour, minute, second); return new LocalDateTime(date, time); }
/** * Converts a {@code java.sql.Time} to a {@code LocalTime}. * * @param sqlTime the SQL time, not null * @return the local time, not null */ @SuppressWarnings("deprecation") public static LocalTime toLocalTime(java.sql.Time sqlTime) { return LocalTime.of(sqlTime.getHours(), sqlTime.getMinutes(), sqlTime.getSeconds()); }
@Before public void setUp() throws Exception { jsr301DateTime = LocalDateTime.of(1970, Month.MAY, 18, 13, 30, 0, 20000000); jsr301Date = LocalDate.of(1970, Month.MAY, 18); jsr301Time = LocalTime.of(13, 30, 0); jodaDateTime = new DateTime(1970, 5, 18, 13, 30, 0, 20); jodaDateTimeUtc = new DateTime(1970, 5, 18, 13, 30, 0, 20, DateTimeZone.UTC); }