本文整理汇总了Java中java.time.LocalTime.minusHours方法的典型用法代码示例。如果您正苦于以下问题:Java LocalTime.minusHours方法的具体用法?Java LocalTime.minusHours怎么用?Java LocalTime.minusHours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.minusHours方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_minusHours_fromZero
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_fromZero() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDate d = base.toLocalDate().plusDays(2);
LocalTime t = LocalTime.of(3, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.minusHours(i);
t = t.minusHours(1);
if (t.getHour() == 23) {
d = d.minusDays(1);
}
assertEquals(dt.toLocalDate(), d, String.valueOf(i));
assertEquals(dt.toLocalTime(), t);
}
}
示例2: test_minusHours_fromOne
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_fromOne() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
LocalDate d = base.toLocalDate().plusDays(2);
LocalTime t = LocalTime.of(4, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.minusHours(i);
t = t.minusHours(1);
if (t.getHour() == 23) {
d = d.minusDays(1);
}
assertEquals(dt.toLocalDate(), d, String.valueOf(i));
assertEquals(dt.toLocalTime(), t);
}
}
示例3: testSplitLocalTime
import java.time.LocalTime; //导入方法依赖的package包/类
@Test(dataProvider = "directions")
public void testSplitLocalTime(boolean ascending) {
final Duration step = Duration.ofMillis(1);
final LocalTime start = ascending ? LocalTime.of(9, 0) : LocalTime.of(17, 0);
final LocalTime end = ascending ? start.plusHours(8) : start.minusHours(8);
final Range<LocalTime> range = Range.of(start, end, step);
final List<Range<LocalTime>> segments = range.split(100);
Assert.assertTrue(segments.size() > 1, "There are multiple segments");
for (int i=1; i<segments.size(); ++i) {
final Range<LocalTime> prior = segments.get(i-1);
final Range<LocalTime> next = segments.get(i);
Assert.assertEquals(prior.end(), next.start(), "Date connect as expect");
if (i == 1) Assert.assertEquals(prior.start(), range.start(), "First segment start matches range start");
if (i == segments.size()-1) {
Assert.assertEquals(next.end(), range.end(), "Last segment end matches range end");
}
}
}
示例4: test_minusHours_one
import java.time.LocalTime; //导入方法依赖的package包/类
@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));
}
}
示例5: test_minusHours_fromZero
import java.time.LocalTime; //导入方法依赖的package包/类
@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);
}
}
示例6: test_minusHours_fromOne
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_minusHours_fromOne() {
LocalTime base = LocalTime.of(1, 0);
for (int i = -50; i < 50; i++) {
LocalTime t = base.minusHours(i);
assertEquals(t.getHour(), (1 + (-i % 24) + 24) % 24);
}
}
示例7: trimTimeBounds
import java.time.LocalTime; //导入方法依赖的package包/类
private void trimTimeBounds() {
if (this instanceof WeekDayView) {
return;
}
LoggingDomain.PRINTING.fine("trimming hours");
LocalTime st = LocalTime.of(8, 0);
LocalTime et = LocalTime.of(19, 0);
LocalTime etu = getEarliestTimeUsed();
LocalTime ltu = getLatestTimeUsed();
LoggingDomain.PRINTING.fine("earliest time: " + etu + ", latest time: " + ltu);
setEarlyLateHoursStrategy(EarlyLateHoursStrategy.HIDE);
if (etu != null && ltu != null && ltu.isAfter(etu)) {
// some padding before the first entry
if (!etu.isBefore(LocalTime.of(1, 0))) {
etu = etu.minusHours(1);
} else {
etu = LocalTime.MIN;
}
// some padding after the last entry
if (!ltu.isAfter(LocalTime.of(23, 0))) {
ltu = ltu.plusHours(1);
} else {
ltu = LocalTime.MAX;
}
// only adjust start time if it is too late
if (etu.isBefore(st.plusHours(1))) {
setStartTime(etu);
} else {
setStartTime(st);
}
// only adjust end time if it is too early
if (ltu.isAfter(et.minusHours(1))) {
setEndTime(ltu);
} else {
setEndTime(et);
}
} else {
setStartTime(st);
setEndTime(et);
}
setVisibleHours(Math.min(24, (int) getStartTime().until(getEndTime(), ChronoUnit.HOURS)));
}