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


Java Duration.ofDays方法代碼示例

本文整理匯總了Java中java.time.Duration.ofDays方法的典型用法代碼示例。如果您正苦於以下問題:Java Duration.ofDays方法的具體用法?Java Duration.ofDays怎麽用?Java Duration.ofDays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Duration的用法示例。


在下文中一共展示了Duration.ofDays方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: thatPushNotificationIsSentWhenLastThresholdWasPassedAndNoNotificationWasEverSent

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void thatPushNotificationIsSentWhenLastThresholdWasPassedAndNoNotificationWasEverSent() throws Exception {
    Duration firstThreshold = Duration.ofDays(1);
    Duration secondThreshold = Duration.ofDays(2);
    Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
    Instant jobRunInstant = disconnectInstant.plus(secondThreshold).plusSeconds(1);

    when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.empty());

    when(clock.instant()).thenReturn(disconnectInstant);

    offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));

    when(clock.instant()).thenReturn(jobRunInstant);

    offlineDevicesJob.run();

    verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
 
開發者ID:pietvandongen,項目名稱:pure-bliss-with-pure-java-functions,代碼行數:21,代碼來源:OfflineDevicesJobTests.java

示例2: thatPushNotificationIsNotSentWhenSingleThresholdWasPassedButNotificationWasAlreadySent

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void thatPushNotificationIsNotSentWhenSingleThresholdWasPassedButNotificationWasAlreadySent() throws Exception {
    Duration threshold = Duration.ofDays(1);
    Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
    Instant lastOfflineNotificationInstant = disconnectInstant.plus(threshold).plusSeconds(1);
    Instant jobRunInstant = disconnectInstant.plus(threshold).plusSeconds(2);

    when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.of(lastOfflineNotificationInstant));

    when(clock.instant()).thenReturn(disconnectInstant);

    offlineDevicesJob.onConfigurationUpdate(Collections.singletonList(threshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));

    when(clock.instant()).thenReturn(jobRunInstant);

    offlineDevicesJob.run();

    verify(pushNotificationService, never()).sendOfflineNotification(any(Device.class));
}
 
開發者ID:pietvandongen,項目名稱:pure-bliss-with-pure-java-functions,代碼行數:21,代碼來源:OfflineDevicesJobTests.java

示例3: thatPushNotificationIsSentWhenLastThresholdWasPassedAndLastSentNotificationWasForPreviousThreshold

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void thatPushNotificationIsSentWhenLastThresholdWasPassedAndLastSentNotificationWasForPreviousThreshold() throws Exception {
    Duration firstThreshold = Duration.ofDays(1);
    Duration secondThreshold = Duration.ofDays(2);
    Instant disconnectInstant = Instant.parse("2010-10-10T10:10:00.00Z");
    Instant lastOfflineNotificationInstant = disconnectInstant.plus(firstThreshold).plusSeconds(1);
    Instant jobRunInstant = disconnectInstant.plus(secondThreshold).plusSeconds(1);

    when(pushNotificationService.getLastOfflineNotificationInstant(any(Device.class))).thenReturn(Optional.of(lastOfflineNotificationInstant));

    when(clock.instant()).thenReturn(disconnectInstant);

    offlineDevicesJob.onConfigurationUpdate(Arrays.asList(firstThreshold, secondThreshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));

    when(clock.instant()).thenReturn(jobRunInstant);

    offlineDevicesJob.run();

    verify(pushNotificationService, times(1)).sendOfflineNotification(any(Device.class));
}
 
開發者ID:pietvandongen,項目名稱:pure-bliss-with-pure-java-functions,代碼行數:22,代碼來源:OfflineDevicesJobTests.java

示例4: shouldNotAuthenticateIfRequestIsNot200

import java.time.Duration; //導入方法依賴的package包/類
@Test(expected = GithubAuthenticationException.class)
public void shouldNotAuthenticateIfRequestIsNot200() throws Exception {
    HttpClient mockClient = Mockito.mock(HttpClient.class);
    HttpResponse mockRespone = Mockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
    Mockito.when(mockRespone.getStatusLine().getStatusCode()).thenReturn(403);
    Mockito.when(mockClient.execute(Mockito.any())).thenReturn(mockRespone);

    GithubApiClient clientToTest = new GithubApiClient(mockClient, new MockGithubOauthConfiguration(Duration.ofDays(1)));

    clientToTest.authz("demo-user", "DUMMY".toCharArray());
}
 
開發者ID:larscheid-schmitzhermes,項目名稱:nexus3-github-oauth-plugin,代碼行數:12,代碼來源:GithubApiClientTest.java

示例5: convert

import java.time.Duration; //導入方法依賴的package包/類
@Override
public Duration convert(String source) {
    source = source.trim();
    if ("0".equals(source)) {
        return Duration.ZERO;
    }
    Matcher matcher = pattern.matcher(source);
    if (!matcher.matches()) throw new IllegalArgumentException("Illegal period: " + source);
    long value = Long.parseLong(matcher.group(1));
    switch (matcher.group(2).toLowerCase()) {
        case "ns":
        case "nanos":
            return Duration.ofNanos(value);
        case "ms":
        case "msec":
        case "millis":
            return Duration.ofMillis(value);
        case "s":
        case "sec":
            return Duration.ofSeconds(value);
        case "m":
        case "min":
            return Duration.ofMinutes(value);
        case "h":
        case "hour":
        case "hours":
            return Duration.ofHours(value);
        case "d":
        case "day":
        case "days":
            return Duration.ofDays(value);
        
    }
    throw new IllegalArgumentException("Illegal unit: " + source);
}
 
開發者ID:papyrusglobal,項目名稱:state-channels,代碼行數:36,代碼來源:DurationConverter.java

示例6: data_minus_TemporalAmount

import java.time.Duration; //導入方法依賴的package包/類
@DataProvider(name="minus_TemporalAmount")
Object[][] data_minus_TemporalAmount() {
    return new Object[][] {
        {YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(0, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(13, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), Period.ofYears(999999999), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), Period.ofYears(-999999999), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(0, 12), null},
        {YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(2, 1), null},
        {YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(-10, 12), null},
        {YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), Period.ofMonths(1), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), Period.ofMonths(-1), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(-1, 11), null},
        {YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(13, 2), null},

        {YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(-1, 11), null},
        {YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(13, 2), null},

        {YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:TCKYearMonth.java

示例7: sendMessageWithSchedule

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void sendMessageWithSchedule() throws Exception {
    String msgData = "data";
    FutureTimepoint tomorrow = new FutureTimepoint(Duration.ofDays(1));
    ChannelMessage<FutureTimepoint, String> msg =
            message(tomorrow, msgData);
    target.send(msg);

    assertHasSentMessage(QMessageType.Durable, msgData);
    assertThat(builtMsg.schedule, is(tomorrow));
}
 
開發者ID:openmicroscopy,項目名稱:omero-ms-queue,代碼行數:12,代碼來源:ScheduleTaskTest.java

示例8: thatNoPushNotificationIsSentWhenNoThresholdWasPassed

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void thatNoPushNotificationIsSentWhenNoThresholdWasPassed() {
    Duration threshold = Duration.ofDays(1);

    when(clock.instant()).thenReturn(Instant.now());

    offlineDevicesJob.onConfigurationUpdate(Collections.singletonList(threshold));
    offlineDevicesJob.onDeviceDisconnect(new Device(UUID.randomUUID()));
    offlineDevicesJob.run();

    verify(pushNotificationService, never()).sendOfflineNotification(any(Device.class));
}
 
開發者ID:pietvandongen,項目名稱:pure-bliss-with-pure-java-functions,代碼行數:13,代碼來源:OfflineDevicesJobTests.java

示例9: data_minusInvalidUnit

import java.time.Duration; //導入方法依賴的package包/類
@DataProvider(name="minusInvalidUnit")
Object[][] data_minusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TCKYear.java

示例10: parseCacheAge

import java.time.Duration; //導入方法依賴的package包/類
private void parseCacheAge() {
	String s = this.cacheAge.getText();
	this.maxAge = s.isEmpty() ? Duration.ofDays(1) : StringUtil.parseDuration(s);
	this.genEnd.setDisable(this.maxAge.equals(Duration.ZERO));
}
 
開發者ID:Yeregorix,項目名稱:EpiStats,代碼行數:6,代碼來源:DataCollectionPanel.java

示例11: plusDays_long

import java.time.Duration; //導入方法依賴的package包/類
@Test(dataProvider="PlusDays")
public void plusDays_long(long days, long amount, long expectedDays) {
    Duration t = Duration.ofDays(days);
    t = t.plusDays(amount);
    assertEquals(t.toDays(), expectedDays);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:TCKDuration.java

示例12: minusDays_long

import java.time.Duration; //導入方法依賴的package包/類
@Test(dataProvider="MinusDays")
public void minusDays_long(long days, long amount, long expectedDays) {
    Duration t = Duration.ofDays(days);
    t = t.minusDays(amount);
    assertEquals(t.toDays(), expectedDays);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TCKDuration.java

示例13: factory_days_tooBig

import java.time.Duration; //導入方法依賴的package包/類
@Test(expectedExceptions=ArithmeticException.class)
public void factory_days_tooBig() {
    Duration.ofDays(Long.MAX_VALUE / 86400 + 1);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:TCKDuration.java

示例14: factory_days_tooSmall

import java.time.Duration; //導入方法依賴的package包/類
@Test(expectedExceptions=ArithmeticException.class)
public void factory_days_tooSmall() {
    Duration.ofDays(Long.MIN_VALUE / 86400 - 1);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKDuration.java

示例15: minusDays_long_overflowTooBig

import java.time.Duration; //導入方法依賴的package包/類
@Test(expectedExceptions = {ArithmeticException.class})
public void minusDays_long_overflowTooBig() {
    Duration t = Duration.ofDays(Long.MAX_VALUE/3600/24);
    t.minusDays(-1);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKDuration.java


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