當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalTime.minusHours方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:TCKLocalDateTime.java

示例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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TCKLocalDateTime.java

示例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");
        }
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:19,代碼來源:RangeSplitTests.java

示例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));
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKLocalTime.java

示例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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKLocalTime.java

示例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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TCKLocalTime.java

示例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)));
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:53,代碼來源:DayViewBase.java


注:本文中的java.time.LocalTime.minusHours方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。