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


Java Duration.ofSeconds方法代碼示例

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


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

示例1: timeToDeleteFromEnter

import java.time.Duration; //導入方法依賴的package包/類
public static void timeToDeleteFromEnter() {
	timeFromEnterCategory = config.getCategory("timeFromEnter");
	timeFromEnterCategory.setComment("Time that has needed to pass since someone entered a chunk for it to be deleted");
	int years = config.getInt("years", "timeFromEnter", 0, 0, 100, "years that have needed to pass");
	int months = config.getInt("months", "timeFromEnter", 2, 0, 11, "months that have needed to pass");
	int days = config.getInt("days", "timeFromEnter", 0, 0, 30, "days that have needed to pass");
	int hours = config.getInt("hours", "timeFromEnter", 0, 0, 23, "hours that have needed to pass");
	int minutes = config.getInt("minutes", "timeFromEnter", 0, 0, 59, "minutes that have needed to pass");
	int seconds = config.getInt("seconds", "timeFromEnter", 0, 0, 59, "seconds that have needed to pass");
	timeFromEnter = Duration.ofSeconds(seconds);
	timeFromEnter = timeFromEnter.plusMinutes(minutes);
	timeFromEnter = timeFromEnter.plusHours(hours);
	timeFromEnter = timeFromEnter.plusDays(days);
	timeFromEnter = timeFromEnter.plusDays(months * 31);
	timeFromEnter = timeFromEnter.plusDays(Math.round(years * 365.25));
}
 
開發者ID:coehlrich,項目名稱:chunk-logger,代碼行數:17,代碼來源:ChunkLoggerConfig.java

示例2: datadogStatsd

import java.time.Duration; //導入方法依賴的package包/類
public static StatsdMeterRegistry datadogStatsd() {
    return new StatsdMeterRegistry(new StatsdConfig() {
        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        public String get(String k) {
            return null;
        }

        @Override
        public StatsdFlavor flavor() {
            return StatsdFlavor.Datadog;
        }
    }, Clock.SYSTEM);
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:19,代碼來源:SampleRegistries.java

示例3: reads_historic_events_from_a_stream_even_if_another_stream_runs_out_of_events

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void reads_historic_events_from_a_stream_even_if_another_stream_runs_out_of_events() {
    Iterator<EventInIdentifiedStream> emptyStream = new SlowIterator<>(clock, Duration.ofSeconds(2), emptyIterator());
    List<EventInIdentifiedStream> stream2 = newArrayList(event(2, "2016-01-01T10:00:00Z", 2222L));

    clock.latchTo(Instant.parse("2016-01-01T10:00:00Z"));
    new EventStoreMergingIterator(clock, Duration.ofSeconds(0), of(emptyStream, stream2.iterator())).forEachRemaining(outputStream);
    assertThat(outputStream.eventVersions(), contains(2222L));

    outputStream.events.clear();

    clock.latchTo(Instant.parse("2016-01-01T10:00:00Z"));
    new EventStoreMergingIterator(clock, Duration.ofSeconds(0), of(stream2.iterator(), emptyStream)).forEachRemaining(outputStream);
    assertThat(outputStream.eventVersions(), contains(2222L));
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:16,代碼來源:EventStoreMergingIteratorTest.java

示例4: plusMillis_long_min

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void plusMillis_long_min() {
    Duration t = Duration.ofSeconds(Long.MIN_VALUE, 1000000);
    t = t.plusMillis(-1);
    assertEquals(t.getSeconds(), Long.MIN_VALUE);
    assertEquals(t.getNano(), 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TCKDuration.java

示例5: only_reads_from_streams_up_to_the_time_any_stream_runs_out_of_events

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void only_reads_from_streams_up_to_the_time_any_stream_runs_out_of_events() {
    Iterator<EventInIdentifiedStream> emptyStream = new SlowIterator<>(clock, Duration.ofSeconds(2), emptyIterator());
    List<EventInIdentifiedStream> stream2 = newArrayList(event(2, "2016-01-01T10:00:01Z", 2222L));

    clock.latchTo(Instant.parse("2016-01-01T10:00:00Z"));
    new EventStoreMergingIterator(clock, Duration.ofSeconds(0), of(emptyStream, stream2.iterator())).forEachRemaining(outputStream);
    assertThat(outputStream.eventVersions(), empty());

    clock.latchTo(Instant.parse("2016-01-01T10:00:00Z"));
    new EventStoreMergingIterator(clock, Duration.ofSeconds(0), of(stream2.iterator(), emptyStream)).forEachRemaining(outputStream);
    assertThat(outputStream.eventVersions(), empty());
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:14,代碼來源:EventStoreMergingIteratorTest.java

示例6: minusNanos_long

import java.time.Duration; //導入方法依賴的package包/類
@Test(dataProvider="MinusNanos")
public void minusNanos_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.minusNanos(amount);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TCKDuration.java

示例7: parseDuration_ShouldReturnDurationOf_Seconds

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void parseDuration_ShouldReturnDurationOf_Seconds() throws Exception {
    String raw = "00:00:05";

    Duration result = subject.parseDuration(raw);
    Duration expected = Duration.ofSeconds(5);

    assertThat(result).isEqualByComparingTo(expected);
}
 
開發者ID:ccremer,項目名稱:clustercode,代碼行數:10,代碼來源:FfmpegParserTest.java

示例8: 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

示例9: test_equals

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void test_equals() {
    Duration test5a = Duration.ofSeconds(5L, 20);
    Duration test5b = Duration.ofSeconds(5L, 20);
    Duration test5n = Duration.ofSeconds(5L, 30);
    Duration test6 = Duration.ofSeconds(6L, 20);

    assertEquals(test5a.equals(test5a), true);
    assertEquals(test5a.equals(test5b), true);
    assertEquals(test5a.equals(test5n), false);
    assertEquals(test5a.equals(test6), false);

    assertEquals(test5b.equals(test5a), true);
    assertEquals(test5b.equals(test5b), true);
    assertEquals(test5b.equals(test5n), false);
    assertEquals(test5b.equals(test6), false);

    assertEquals(test5n.equals(test5a), false);
    assertEquals(test5n.equals(test5b), false);
    assertEquals(test5n.equals(test5n), true);
    assertEquals(test5n.equals(test6), false);

    assertEquals(test6.equals(test5a), false);
    assertEquals(test6.equals(test5b), false);
    assertEquals(test6.equals(test5n), false);
    assertEquals(test6.equals(test6), true);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:TCKDuration.java

示例10: test_toMillis_min

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void test_toMillis_min() {
    Duration test = Duration.ofSeconds(Long.MIN_VALUE / 1000, (Long.MIN_VALUE % 1000) * 1000000);
    assertEquals(test.toMillis(), Long.MIN_VALUE);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKDuration.java

示例11: multipliedBy_tooBig

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

示例12: setup

import java.time.Duration; //導入方法依賴的package包/類
@Before
public void setup() {
    status = new EventSubscriptionStatus("", "", clock, DurationThreshold.warningThresholdWithCriticalRatio(Duration.ofSeconds(123), 1.25), new DurationThreshold(Duration.ofSeconds(1), Duration.ofSeconds(30)), new LocalEventSink());
    adapter = new SubscriptionListenerAdapter(new TestPosition(0), singletonList(status));
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:6,代碼來源:EventSubscriptionStatusTest.java

示例13: test_minus_Duration

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void test_minus_Duration() {
    Duration dur = Duration.ofSeconds(62, 3);
    OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.minus(dur);
    assertEquals(t, OffsetDateTime.of(2008, 6, 30, 11, 29, 57, 497, OFFSET_PONE));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TCKOffsetDateTime.java

示例14: plusSeconds_zeroReturnsThis

import java.time.Duration; //導入方法依賴的package包/類
@Test
public void plusSeconds_zeroReturnsThis() {
    Duration t = Duration.ofSeconds(-1);
    assertSame(t.plusSeconds(0), t);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:TestDuration.java

示例15: plusSeconds_long_overflowTooSmall

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


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