本文整理汇总了Java中java.time.LocalTime.MIDNIGHT属性的典型用法代码示例。如果您正苦于以下问题:Java LocalTime.MIDNIGHT属性的具体用法?Java LocalTime.MIDNIGHT怎么用?Java LocalTime.MIDNIGHT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.MIDNIGHT属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_minusMinutes_fromZero
@Test
public void test_minusMinutes_fromZero() {
LocalTime base = LocalTime.MIDNIGHT;
int hour = 22;
int min = 49;
for (int i = 70; i > -70; i--) {
LocalTime t = base.minusMinutes(i);
min++;
if (min == 60) {
hour++;
min = 0;
if (hour == 24) {
hour = 0;
}
}
assertEquals(t.getHour(), hour);
assertEquals(t.getMinute(), min);
}
}
示例2: data_adjustInto
@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},
};
}
示例3: test_plusMinutes_fromZero
@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);
}
}
示例4: test_plusHours_one
@Test
public void test_plusHours_one() {
LocalTime t = LocalTime.MIDNIGHT;
for (int i = 0; i < 50; i++) {
t = t.plusHours(1);
assertEquals(t.getHour(), (i + 1) % 24);
}
}
示例5: test_plusNanos_fromZero
@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());
}
示例6: test_minusHours_one
@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));
}
}
示例7: test_plusHours_fromZero
@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);
}
}
示例8: test_minusNanos_halfABillion
@Test
public void test_minusNanos_halfABillion() {
LocalTime t = LocalTime.MIDNIGHT;
int hour = 0;
int min = 0;
int sec = 0;
int nanos = 0;
for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
t = t.minusNanos(500000000);
nanos -= 500000000;
if (nanos < 0) {
sec--;
nanos += 1000000000;
if (sec == -1) {
min--;
sec += 60;
if (min == -1) {
hour--;
min += 60;
if (hour == -1) {
hour += 24;
}
}
}
}
assertEquals(t.getHour(), hour);
assertEquals(t.getMinute(), min);
assertEquals(t.getSecond(), sec);
assertEquals(t.getNano(), nanos);
}
}
示例9: test_plusNanos_halfABillion
@Test
public void test_plusNanos_halfABillion() {
LocalTime t = LocalTime.MIDNIGHT;
int hour = 0;
int min = 0;
int sec = 0;
int nanos = 0;
for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) {
t = t.plusNanos(500000000);
nanos += 500000000;
if (nanos == 1000000000) {
sec++;
nanos = 0;
}
if (sec == 60) {
min++;
sec = 0;
}
if (min == 60) {
hour++;
min = 0;
}
assertEquals(t.getHour(), hour);
assertEquals(t.getMinute(), min);
assertEquals(t.getSecond(), sec);
assertEquals(t.getNano(), nanos);
}
}
示例10: test_minusHours_fromZero
@Test
public void test_minusHours_fromZero() {
LocalTime base = LocalTime.MIDNIGHT;
for (int i = -50; i < 50; i++) {
LocalTime t = base.minusHours(i);
assertEquals(t.getHour(), ((-i % 24) + 24) % 24);
}
}
示例11: test_minusSeconds_one
@Test
public void test_minusSeconds_one() {
LocalTime t = LocalTime.MIDNIGHT;
int hour = 0;
int min = 0;
int sec = 0;
for (int i = 0; i < 3700; i++) {
t = t.minusSeconds(1);
sec--;
if (sec == -1) {
min--;
sec = 59;
if (min == -1) {
hour--;
min = 59;
if (hour == -1) {
hour = 23;
}
}
}
assertEquals(t.getHour(), hour);
assertEquals(t.getMinute(), min);
assertEquals(t.getSecond(), sec);
}
}
示例12: test_plusSeconds_fromZero
@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());
}
示例13: test_minusSeconds_fromZero
@Test(dataProvider="minusSeconds_fromZero")
public void test_minusSeconds_fromZero(int seconds, int hour, int min, int sec) {
LocalTime base = LocalTime.MIDNIGHT;
LocalTime t = base.minusSeconds(seconds);
assertEquals(t.getHour(), hour);
assertEquals(t.getMinute(), min);
assertEquals(t.getSecond(), sec);
}