Java Code Examples for java.time.LocalTime#MIDNIGHT

The following examples show how to use java.time.LocalTime#MIDNIGHT . 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: TimePickerSettings.java    From LGoodDatePicker with MIT License 6 votes vote down vote up
/**
 * generatePotentialMenuTimes, This will generate a list of menu times for populating the combo
 * box menu, using a TimePickerSettings.TimeIncrement value. The menu times will always start at
 * Midnight, and increase according to the increment until the last time before 11:59pm.
 *
 * Note: This function can be called before or after setting an optional veto policy. Vetoed
 * times will never be added to the time picker menu, regardless of whether they are generated
 * by this function.
 *
 * Example usage: generatePotentialMenuTimes(TimeIncrement.FifteenMinutes);
 *
 * Number of entries: If no veto policy has been created, the number of entries in the drop down
 * menu would be determined by the size of the increment as follows; FiveMinutes has 288
 * entries. TenMinutes has 144 entries. FifteenMinutes has 96 entries. TwentyMinutes has 72
 * entries. ThirtyMinutes has 48 entries. OneHour has 24 entries.
 */
public void generatePotentialMenuTimes(TimeIncrement timeIncrement,
        LocalTime optionalStartTime, LocalTime optionalEndTime) {
    // If either bounding time does does not already exist, then set it to the maximum range.
    LocalTime startTime = (optionalStartTime == null) ? LocalTime.MIN : optionalStartTime;
    LocalTime endTime = (optionalEndTime == null) ? LocalTime.MAX : optionalEndTime;
    // Initialize our needed variables.
    potentialMenuTimes = new ArrayList<LocalTime>();
    int increment = timeIncrement.minutes;
    // Start at midnight, which is the earliest time of day for LocalTime values.
    LocalTime entry = LocalTime.MIDNIGHT;
    boolean continueLoop = true;
    while (continueLoop) {
        if (PickerUtilities.isLocalTimeInRange(entry, startTime, endTime, true)) {
            potentialMenuTimes.add(entry);
        }
        entry = entry.plusMinutes(increment);
        // Note: This stopping criteria works as long as as ((60 % increment) == 0).
        continueLoop = (!(LocalTime.MIDNIGHT.equals(entry)));
    }
}
 
Example 2
Source File: TCKLocalTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_plusMinutes_fromZero() {
    LocalTime base = LocalTime.MIDNIGHT;
    int hour;
    int min;
    for (int i = -70; i < 70; i++) {
        LocalTime t = base.plusMinutes(i);
        if (i < -60) {
            hour = 22;
            min = i + 120;
        } else if (i < 0) {
            hour = 23;
            min = i + 60;
        } else if (i >= 60) {
            hour = 1;
            min = i - 60;
        } else {
            hour = 0;
            min = i;
        }
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 3
Source File: TCKLocalTime.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {LocalTime.of(23, 5), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 0, 0), null},
            {LocalTime.of(23, 5, 20), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 0), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), LocalTime.of(23, 59, 59, 999999999), null},
            {LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},
            {LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), LocalTime.of(12, 0, 0), null},
            {LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},

            {LocalTime.of(23, 5), LocalDateTime.of(2210, 2, 2, 1, 1), LocalDateTime.of(2210, 2, 2, 23, 5), null},
            {LocalTime.of(23, 5), OffsetTime.of(1, 1, 0, 0, OFFSET_PTWO), OffsetTime.of(23, 5, 0, 0, OFFSET_PTWO), null},
            {LocalTime.of(23, 5), OffsetDateTime.of(2210, 2, 2, 1, 1, 0, 0, OFFSET_PTWO), OffsetDateTime.of(2210, 2, 2, 23, 5, 0, 0, OFFSET_PTWO), null},
            {LocalTime.of(23, 5), ZonedDateTime.of(2210, 2, 2, 1, 1, 0, 0, ZONE_PARIS), ZonedDateTime.of(2210, 2, 2, 23, 5, 0, 0, ZONE_PARIS), null},

            {LocalTime.of(23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {LocalTime.of(23, 5), null, null, NullPointerException.class},

    };
}
 
Example 4
Source File: TCKLocalTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {LocalTime.of(23, 5), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 0, 0), null},
            {LocalTime.of(23, 5, 20), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 0), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.of(23, 5, 20, 1000), LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), null},
            {LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), LocalTime.of(23, 59, 59, 999999999), null},
            {LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},
            {LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), LocalTime.of(12, 0, 0), null},
            {LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null},

            {LocalTime.of(23, 5), LocalDateTime.of(2210, 2, 2, 1, 1), LocalDateTime.of(2210, 2, 2, 23, 5), null},
            {LocalTime.of(23, 5), OffsetTime.of(1, 1, 0, 0, OFFSET_PTWO), OffsetTime.of(23, 5, 0, 0, OFFSET_PTWO), null},
            {LocalTime.of(23, 5), OffsetDateTime.of(2210, 2, 2, 1, 1, 0, 0, OFFSET_PTWO), OffsetDateTime.of(2210, 2, 2, 23, 5, 0, 0, OFFSET_PTWO), null},
            {LocalTime.of(23, 5), ZonedDateTime.of(2210, 2, 2, 1, 1, 0, 0, ZONE_PARIS), ZonedDateTime.of(2210, 2, 2, 23, 5, 0, 0, ZONE_PARIS), null},

            {LocalTime.of(23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {LocalTime.of(23, 5), null, null, NullPointerException.class},

    };
}
 
Example 5
Source File: TCKLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_plusSeconds_one() {
    LocalTime t = LocalTime.MIDNIGHT;
    int hour = 0;
    int min = 0;
    int sec = 0;
    for (int i = 0; i < 3700; i++) {
        t = t.plusSeconds(1);
        sec++;
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
Example 6
Source File: TCKLocalTime.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_plusSeconds_one() {
    LocalTime t = LocalTime.MIDNIGHT;
    int hour = 0;
    int min = 0;
    int sec = 0;
    for (int i = 0; i < 3700; i++) {
        t = t.plusSeconds(1);
        sec++;
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
    }
}
 
Example 7
Source File: TCKLocalTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_plusMinutes_one() {
    LocalTime t = LocalTime.MIDNIGHT;
    int hour = 0;
    int min = 0;
    for (int i = 0; i < 70; i++) {
        t = t.plusMinutes(1);
        min++;
        if (min == 60) {
            hour++;
            min = 0;
        }
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 8
Source File: TCKLocalTime.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void test_plusMinutes_fromZero() {
    LocalTime base = LocalTime.MIDNIGHT;
    int hour;
    int min;
    for (int i = -70; i < 70; i++) {
        LocalTime t = base.plusMinutes(i);
        if (i < -60) {
            hour = 22;
            min = i + 120;
        } else if (i < 0) {
            hour = 23;
            min = i + 60;
        } else if (i >= 60) {
            hour = 1;
            min = i - 60;
        } else {
            hour = 0;
            min = i;
        }
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
    }
}
 
Example 9
Source File: TCKLocalTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="plusSeconds_fromZero")
public void test_plusSeconds_fromZero(int seconds, int hour, int min, int sec) {
    LocalTime base = LocalTime.MIDNIGHT;
    LocalTime t = base.plusSeconds(seconds);

    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
}
 
Example 10
Source File: TCKLocalTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, int hour, int min, int sec, int nanos) {
    LocalTime base = LocalTime.MIDNIGHT;
    LocalTime t = base.minusNanos(nanoseconds);

    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 11
Source File: TCKLocalTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="plusNanos_fromZero")
public void test_plusNanos_fromZero(long nanoseconds, int hour, int min, int sec, int nanos) {
    LocalTime base = LocalTime.MIDNIGHT;
    LocalTime t = base.plusNanos(nanoseconds);

    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 12
Source File: TCKLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_minusHours_one() {
    LocalTime t = LocalTime.MIDNIGHT;
    for (int i = 0; i < 50; i++) {
        t = t.minusHours(1);
        assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24, String.valueOf(i));
    }
}
 
Example 13
Source File: TCKLocalTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusHours_fromZero() {
    LocalTime base = LocalTime.MIDNIGHT;
    for (int i = -50; i < 50; i++) {
        LocalTime t = base.plusHours(i);
        assertEquals(t.getHour(), (i + 72) % 24);
    }
}
 
Example 14
Source File: TCKLocalTime.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="minusNanos_fromZero")
public void test_minusNanos_fromZero(long nanoseconds, int hour, int min, int sec, int nanos) {
    LocalTime base = LocalTime.MIDNIGHT;
    LocalTime t = base.minusNanos(nanoseconds);

    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 15
Source File: TCKLocalTime.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="plusNanos_fromZero")
public void test_plusNanos_fromZero(long nanoseconds, int hour, int min, int sec, int nanos) {
    LocalTime base = LocalTime.MIDNIGHT;
    LocalTime t = base.plusNanos(nanoseconds);

    assertEquals(hour, t.getHour());
    assertEquals(min, t.getMinute());
    assertEquals(sec, t.getSecond());
    assertEquals(nanos, t.getNano());
}
 
Example 16
Source File: TCKLocalTime.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_plusHours_fromZero() {
    LocalTime base = LocalTime.MIDNIGHT;
    for (int i = -50; i < 50; i++) {
        LocalTime t = base.plusHours(i);
        assertEquals(t.getHour(), (i + 72) % 24);
    }
}
 
Example 17
Source File: TCKLocalTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {TEST_12_30_40_987654321, LocalTime.MIN, LocalTime.MAX, LocalTime.MIDNIGHT, LocalTime.NOON};
    return Arrays.asList(array);
}
 
Example 18
Source File: TCKLocalTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {TEST_12_30_40_987654321, LocalTime.MIN, LocalTime.MAX, LocalTime.MIDNIGHT, LocalTime.NOON};
    return Arrays.asList(array);
}
 
Example 19
Source File: LocalTimeSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public LocalTime createInstance() {
	return LocalTime.MIDNIGHT;
}
 
Example 20
Source File: TCKLocalTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected List<TemporalAccessor> samples() {
    TemporalAccessor[] array = {TEST_12_30_40_987654321, LocalTime.MIN, LocalTime.MAX, LocalTime.MIDNIGHT, LocalTime.NOON};
    return Arrays.asList(array);
}