Java Code Examples for java.time.Clock

The following are top voted examples for showing how to use java.time.Clock. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: TCKZonedDateTime.java   View source code 6 votes vote down vote up
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
        assertEquals(test.getZone(), ZoneOffset.UTC);
    }
}
 
Example 2
Project: tg-eventstore   File: CachingEventsTest.java   View source code 6 votes vote down vote up
@Test
public void
givenMultipleCacheFilesInCacheDirectory_allReadInOrder() throws Exception {
    underlyingEventStore.write(stream_1, singletonList(event_1));
    Position firstPosition = saveAllToCache(getCacheFile("cache_1.gz"));

    underlyingEventStore.write(stream_1, singletonList(event_1));
    Position secondPosition = saveAllToCache(getCacheFile("cache_2.gz"), firstPosition);

    underlyingEventStore.write(stream_1, singletonList(event_1));
    Position thirdPosition = saveAllToCache(getCacheFile("cache_3.gz"), secondPosition);

    CacheEventReader newCacheEventReader = new CacheEventReader(new JavaInMemoryEventStore(Clock.systemUTC()), CODEC, cacheDirectory, "cache");
    List<ResolvedEvent> resolvedEvents = readAllFromEmpty(newCacheEventReader);
    assertThat(resolvedEvents.stream().map(ResolvedEvent::position).collect(toList()), contains(firstPosition, secondPosition, thirdPosition));
}
 
Example 3
Project: kafka-junit   File: KafkaTestUtils.java   View source code 6 votes vote down vote up
/**
 * Produce randomly generated records into the defined kafka namespace.
 *
 * @param numberOfRecords how many records to produce
 * @param topicName the namespace name to produce into.
 * @param partitionId the partition to produce into.
 * @return List of ProducedKafkaRecords.
 */
public List<ProducedKafkaRecord<byte[], byte[]>> produceRecords(
    final int numberOfRecords,
    final String topicName,
    final int partitionId
) {
    Map<byte[], byte[]> keysAndValues = new HashMap<>();

    // Generate random & unique data
    for (int x = 0; x < numberOfRecords; x++) {
        // Construct key and value
        long timeStamp = Clock.systemUTC().millis();
        String key = "key" + timeStamp;
        String value = "value" + timeStamp;

        // Add to map
        keysAndValues.put(key.getBytes(Charsets.UTF_8), value.getBytes(Charsets.UTF_8));
    }

    return produceRecords(keysAndValues, topicName, partitionId);
}
 
Example 4
Project: openjdk-jdk10   File: TCKOffsetDateTime.java   View source code 6 votes vote down vote up
@Test
public void now_Clock_allSecsInDay_offset() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), OFFSET_PONE);
    }
}
 
Example 5
Project: util4j   File: TimeIntroduction.java   View source code 6 votes vote down vote up
public static void testClock() throws InterruptedException {
    //时钟提供给我们用于访问某个特定 时区的 瞬时时间、日期 和 时间的。  
    Clock c1 = Clock.systemUTC(); //系统默认UTC时钟(当前瞬时时间 System.currentTimeMillis())  
    System.out.println(c1.millis()); //每次调用将返回当前瞬时时间(UTC)  
    Clock c2 = Clock.systemDefaultZone(); //系统默认时区时钟(当前瞬时时间)  
    Clock c31 = Clock.system(ZoneId.of("Europe/Paris")); //巴黎时区  
    System.out.println(c31.millis()); //每次调用将返回当前瞬时时间(UTC)  
    Clock c32 = Clock.system(ZoneId.of("Asia/Shanghai"));//上海时区  
    System.out.println(c32.millis());//每次调用将返回当前瞬时时间(UTC)  
    Clock c4 = Clock.fixed(Instant.now(), ZoneId.of("Asia/Shanghai"));//固定上海时区时钟  
    System.out.println(c4.millis());
    Thread.sleep(1000);
    System.out.println(c4.millis()); //不变 即时钟时钟在那一个点不动  
    Clock c5 = Clock.offset(c1, Duration.ofSeconds(2)); //相对于系统默认时钟两秒的时钟  
    System.out.println(c1.millis());
    System.out.println(c5.millis());
}
 
Example 6
Project: jdk8u-jdk   File: TCKClock_Tick.java   View source code 6 votes vote down vote up
public void test__equals() {
    Clock a = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
    Clock b = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
    assertEquals(a.equals(a), true);
    assertEquals(a.equals(b), true);
    assertEquals(b.equals(a), true);
    assertEquals(b.equals(b), true);

    Clock c = Clock.tick(Clock.system(MOSCOW), Duration.ofMillis(500));
    assertEquals(a.equals(c), false);

    Clock d = Clock.tick(Clock.system(PARIS), Duration.ofMillis(499));
    assertEquals(a.equals(d), false);

    assertEquals(a.equals(null), false);
    assertEquals(a.equals("other type"), false);
    assertEquals(a.equals(Clock.systemUTC()), false);
}
 
Example 7
Project: openjdk-jdk10   File: TCKClock_System.java   View source code 5 votes vote down vote up
public void test_millis() {
    Clock system = Clock.systemUTC();
    assertEquals(system.getZone(), ZoneOffset.UTC);
    for (int i = 0; i < 10000; i++) {
        // assume can eventually get these within 10 milliseconds
        long instant = system.millis();
        long systemMillis = System.currentTimeMillis();
        if (systemMillis - instant < 10) {
            return;  // success
        }
    }
    fail();
}
 
Example 8
Project: jdk8u-jdk   File: TCKMonthDay.java   View source code 5 votes vote down vote up
@Test
public void now() {
    MonthDay expected = MonthDay.now(Clock.systemDefaultZone());
    MonthDay test = MonthDay.now();
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = MonthDay.now(Clock.systemDefaultZone());
        test = MonthDay.now();
    }
    assertEquals(test, expected);
}
 
Example 9
Project: burpextender-proxyhistory-webui   File: BurpExtender.java   View source code 5 votes vote down vote up
@Override
public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) {
    this.callbacks = callbacks;
    this.helpers = callbacks.getHelpers();
    callbacks.setExtensionName("ProxyHistoryWebUI");

    try {
        // ONLY THIS PATTERN WORK FINE. ?? ClassLoader.loadClass() NOT WORK... X(
        Class.forName("org.h2.Driver");

        appContext = new AppContext(Clock.systemDefaultZone());
        appContext.setConsoleOutputWriter(new PrintWriter(callbacks.getStdout(), true));
        appContext.setConsoleErrorWriter(new PrintWriter(callbacks.getStderr(), true));

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                demoPanel = new DemoPanel(appContext);
                callbacks.customizeUiComponent(demoPanel);
                callbacks.addSuiteTab(BurpExtender.this);

                // register ourselves as an HTTP listener
                callbacks.registerProxyListener(BurpExtender.this);
            }
        });
    } catch (Exception e) {
        callbacks.printError(Throwables.getStackTraceAsString(e));
        e.printStackTrace();
    }
}
 
Example 10
Project: dztools   File: Components.java   View source code 5 votes vote down vote up
private void initSystemComponents(final SystemComponents systemComponents) {
    client = systemComponents.client();
    pluginConfig = systemComponents.pluginConfig();
    infoStrategy = systemComponents.infoStrategy();
    clientUtil = systemComponents.clientUtil();
    zorro = new Zorro(pluginConfig);
    clock = Clock.systemDefaultZone();
}
 
Example 11
Project: cmc-claim-store   File: TimeConfiguration.java   View source code 5 votes vote down vote up
@Bean
public Clock systemClock() {
    return Clock.systemDefaultZone();
}
 
Example 12
Project: jdk8u-jdk   File: TCKChronology.java   View source code 5 votes vote down vote up
@Test
public void test_MinguoChronology_dateNow() {
    ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
    Clock clock = Clock.system(zoneId_paris);

    Chronology chrono = Chronology.of("Minguo");
    assertEquals(chrono.dateNow(), MinguoChronology.INSTANCE.dateNow());
    assertEquals(chrono.dateNow(zoneId_paris), MinguoChronology.INSTANCE.dateNow(zoneId_paris));
    assertEquals(chrono.dateNow(clock), MinguoChronology.INSTANCE.dateNow(clock));
}
 
Example 13
Project: openjdk-jdk10   File: TCKClock_Tick.java   View source code 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 14
Project: uroborosql   File: DateTimeApiPropertyMapperTest.java   View source code 5 votes vote down vote up
@Test
public void test() throws NoSuchMethodException, SecurityException, SQLException {
	PropertyMapperManager mapper = new PropertyMapperManager();
	LocalDateTime localDateTime = LocalDateTime.now();
	OffsetDateTime offsetDateTime = OffsetDateTime.of(localDateTime, OffsetDateTime.now().getOffset());
	ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, Clock.systemDefaultZone().getZone());

	java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf(localDateTime);
	LocalDate localDate = localDateTime.toLocalDate();
	java.sql.Date date = java.sql.Date.valueOf(localDate);
	LocalTime localTime = localDateTime.toLocalTime();
	java.sql.Time time = new java.sql.Time(toTime(localTime));
	OffsetTime offsetTime = offsetDateTime.toOffsetTime();

	assertThat(mapper.getValue(JavaType.of(LocalDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(localDateTime));
	assertThat(mapper.getValue(JavaType.of(OffsetDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(offsetDateTime));
	assertThat(mapper.getValue(JavaType.of(ZonedDateTime.class), newResultSet("getTimestamp", timestamp), 1), is(zonedDateTime));
	assertThat(mapper.getValue(JavaType.of(LocalDate.class), newResultSet("getDate", date), 1), is(localDate));
	assertThat(mapper.getValue(JavaType.of(LocalTime.class), newResultSet("getTime", time), 1), is(localTime));
	assertThat(mapper.getValue(JavaType.of(OffsetTime.class), newResultSet("getTime", time), 1), is(offsetTime));

	assertThat(mapper.getValue(JavaType.of(LocalDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(OffsetDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(ZonedDateTime.class), newResultSet("getTimestamp", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(LocalDate.class), newResultSet("getDate", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(LocalTime.class), newResultSet("getTime", null), 1), is(nullValue()));
	assertThat(mapper.getValue(JavaType.of(OffsetTime.class), newResultSet("getTime", null), 1), is(nullValue()));

}
 
Example 15
Project: openjdk-jdk10   File: TCKZonedDateTime.java   View source code 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    ZonedDateTime expected = ZonedDateTime.now(Clock.system(zone));
    ZonedDateTime test = ZonedDateTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = ZonedDateTime.now(Clock.system(zone));
        test = ZonedDateTime.now(zone);
    }
    assertEquals(test.truncatedTo(ChronoUnit.SECONDS),
                 expected.truncatedTo(ChronoUnit.SECONDS));
}
 
Example 16
Project: openjdk-jdk10   File: TCKClock.java   View source code 5 votes vote down vote up
@Test
public void test_mockInstantClock_withZone() {
    ZoneId london = ZoneId.of("Europe/London");
    Clock changed = MOCK_INSTANT.withZone(london);
    assertEquals(MOCK_INSTANT.instant(), INSTANT);
    assertEquals(MOCK_INSTANT.millis(), INSTANT.toEpochMilli());
    assertEquals(changed.getZone(), london);
}
 
Example 17
Project: openjdk-jdk10   File: TCKClock_Tick.java   View source code 5 votes vote down vote up
public void test_hashCode() {
    Clock a = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
    Clock b = Clock.tick(Clock.system(PARIS), Duration.ofMillis(500));
    assertEquals(a.hashCode(), a.hashCode());
    assertEquals(a.hashCode(), b.hashCode());

    Clock c = Clock.tick(Clock.system(MOSCOW), Duration.ofMillis(500));
    assertEquals(a.hashCode() == c.hashCode(), false);

    Clock d = Clock.tick(Clock.system(PARIS), Duration.ofMillis(499));
    assertEquals(a.hashCode() == d.hashCode(), false);
}
 
Example 18
Project: storm-dynamic-spout   File: MessageId.java   View source code 5 votes vote down vote up
/**
 * Constructor.
 * @param namespace - the namespace this tuple came from.
 * @param partition - the partition this tuple came from.
 * @param offset - the offset this tuple came from.
 * @param srcVirtualSpoutId - the VirtualSpout's identifier this tuple came from.
 */
public MessageId(final String namespace, final int partition, final long offset, final VirtualSpoutIdentifier srcVirtualSpoutId) {
    this.namespace = namespace;
    this.partition = partition;
    this.offset = offset;
    this.srcVirtualSpoutId = srcVirtualSpoutId;
    this.timestamp = Clock.systemUTC().millis();
}
 
Example 19
Project: openjdk-jdk10   File: TCKInstant.java   View source code 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant expected = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(expected, ZoneOffset.UTC);
        Instant test = Instant.now(clock);
        assertEquals(test, expected);
    }
}
 
Example 20
Project: jdk8u-jdk   File: TCKInstant.java   View source code 5 votes vote down vote up
@Test
public void now() {
    Instant expected = Instant.now(Clock.systemUTC());
    Instant test = Instant.now();
    long diff = Math.abs(test.toEpochMilli() - expected.toEpochMilli());
    assertTrue(diff < 100);  // less than 0.1 secs
}
 
Example 21
Project: openjdk-jdk10   File: TCKClock_System.java   View source code 5 votes vote down vote up
public void test_hashCode() {
    Clock a = Clock.system(ZoneOffset.UTC);
    Clock b = Clock.system(ZoneOffset.UTC);
    assertEquals(a.hashCode(), a.hashCode());
    assertEquals(a.hashCode(), b.hashCode());

    Clock c = Clock.system(PARIS);
    assertEquals(a.hashCode() == c.hashCode(), false);
}
 
Example 22
Project: openjdk-jdk10   File: TCKLocalDate.java   View source code 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalDate test = LocalDate.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
    }
}
 
Example 23
Project: oauth-filter-for-java   File: ExpirationBasedCache.java   View source code 5 votes vote down vote up
ExpirationBasedCache()
{
    _cache = new ConcurrentHashMap<>();
    _clock = Clock.systemUTC();

    Timer timer = new Timer("cacheExpiration", true);
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            expireCacheEntries();
        }} , 60, 60);
}
 
Example 24
Project: gremlin-ogm   File: VertexGraph.java   View source code 5 votes vote down vote up
@Override
protected org.apache.tinkerpop.gremlin.structure.Vertex complete(GraphTraversal traversal) {
  long startTime = Clock.systemUTC().millis();
  try {
    return (org.apache.tinkerpop.gremlin.structure.Vertex) super.complete(traversal);
  } finally {
    if (log.isDebugEnabled()) {
      long endTime = Clock.systemUTC().millis();
      log.debug("Executing '{} vertex' traversal {} in {}ms", should().label(), show(traversal),
          endTime - startTime);
    }
  }
}
 
Example 25
Project: jdk8u-jdk   File: TCKClock.java   View source code 5 votes vote down vote up
@Test
public void test_mockInstantClock_withZone() {
    ZoneId london = ZoneId.of("Europe/London");
    Clock changed = MOCK_INSTANT.withZone(london);
    assertEquals(MOCK_INSTANT.instant(), INSTANT);
    assertEquals(MOCK_INSTANT.millis(), INSTANT.toEpochMilli());
    assertEquals(changed.getZone(), london);
}
 
Example 26
Project: openjdk-jdk10   File: TCKYear.java   View source code 5 votes vote down vote up
@Test
public void now() {
    Year expected = Year.now(Clock.systemDefaultZone());
    Year test = Year.now();
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = Year.now(Clock.systemDefaultZone());
        test = Year.now();
    }
    assertEquals(test, expected);
}
 
Example 27
Project: jdk8u-jdk   File: TCKLocalTime.java   View source code 5 votes vote down vote up
@Test
public void now_Clock_min() {
    Clock clock = Clock.fixed(Instant.MIN, ZoneOffset.UTC);
    LocalTime test = LocalTime.now(clock);
    assertEquals(test.getHour(), 0);
    assertEquals(test.getMinute(), 0);
    assertEquals(test.getSecond(), 0);
    assertEquals(test.getNano(), 0);
}
 
Example 28
Project: openjdk-jdk10   File: TCKLocalTime.java   View source code 5 votes vote down vote up
@Test
public void now_Clock_min() {
    Clock clock = Clock.fixed(Instant.MIN, ZoneOffset.UTC);
    LocalTime test = LocalTime.now(clock);
    assertEquals(test.getHour(), 0);
    assertEquals(test.getMinute(), 0);
    assertEquals(test.getSecond(), 0);
    assertEquals(test.getNano(), 0);
}
 
Example 29
Project: pure-bliss-with-pure-java-functions   File: OfflineDevicesJobImpl.java   View source code 5 votes vote down vote up
OfflineDevicesJobImpl(
        Clock clock,
        DeviceService deviceService,
        PushNotificationService pushNotificationService
) {
    if (clock == null || deviceService == null || pushNotificationService == null) {
        throw new IllegalArgumentException("Clock, device service nor push notification service can be null.");
    }

    this.clock = clock;
    this.deviceService = deviceService;
    this.pushNotificationService = pushNotificationService;
    this.offlineDevices = new ConcurrentHashMap<>(deviceService.getOfflineDevices());
}
 
Example 30
Project: tg-eventstore   File: CachingEventsTest.java   View source code 5 votes vote down vote up
@Test
public void
givenReadingFromEmptyStorePosition_readsFromTheCache() throws Exception {
    underlyingEventStore.write(stream_1, singletonList(event_1));
    saveAllToCache(getCacheFile("cache.gz"));

    assertThat(readAllFromEmpty(cacheEventReader), hasSize(1));

    CacheEventReader newCacheEventReader = new CacheEventReader(new JavaInMemoryEventStore(Clock.systemUTC()), CODEC, cacheDirectory, "cache");
    assertThat(readAllFromEmpty(newCacheEventReader), hasSize(1));
    assertThat(readAllFromEmpty(newCacheEventReader), equalTo(readAllToList(underlyingEventStore)));
}
 
Example 31
Project: storm-dynamic-spout   File: SpoutRunnerTest.java   View source code 5 votes vote down vote up
/**
 * Tests the constructor sets things appropriately.
 */
@Test
public void testConstructor() {
    // Define inputs
    final MessageBus messageBus = new MessageBus(new FifoBuffer());
    final Map<VirtualSpoutIdentifier, Queue<MessageId>> ackQueue = Maps.newConcurrentMap();
    final Map<VirtualSpoutIdentifier, Queue<MessageId>> failQueue = Maps.newConcurrentMap();
    final Clock clock = Clock.systemUTC();

    // Define some config params
    final long consumerStateFlushInterval = 200L;

    // Create our spout delegate
    final DelegateSpout spout = mock(DelegateSpout.class);

    // Create config
    final Map<String, Object> topologyConfig = getDefaultConfig(consumerStateFlushInterval);

    // Create instance.
    SpoutRunner spoutRunner = new SpoutRunner(
        spout,
        messageBus,
        clock,
        topologyConfig
    );

    // Call getters and validate!
    assertEquals("Clock instance is what we expect", clock, spoutRunner.getClock());
    assertEquals("TopologyConfig looks legit", topologyConfig, spoutRunner.getTopologyConfig());
    assertEquals(
        "getConsumerStateFlushIntervalMs() returns right value",
        consumerStateFlushInterval,
        spoutRunner.getConsumerStateFlushIntervalMs()
    );

    assertNotNull("StartTime is null", spoutRunner.getStartTime());
    assertNotEquals("StartTime is not zero", 0, spoutRunner.getStartTime());
    assertEquals("Spout delegate got set", spout, spoutRunner.getSpout());
}
 
Example 32
Project: jdk8u-jdk   File: TCKLocalTime.java   View source code 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalTime test = LocalTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
    }
}
 
Example 33
Project: rskj   File: HashRateCalculator.java   View source code 5 votes vote down vote up
protected BigInteger calculateHashRate(Predicate<BlockHeaderElement> countCondition, Duration period) {
    if (hasBestBlock()) {
        Instant upto = Clock.systemUTC().instant();
        Instant from = upto.minus(period);
        return this.hashRate(getHeaderElement(blockStore.getBestBlock().getHash()), countCondition, b -> checkBlockTimeRange(b, from, upto));
    }
    return BigInteger.ZERO;
}
 
Example 34
Project: jdk8u-jdk   File: TCKChronology.java   View source code 5 votes vote down vote up
@Test
public void test_ThaiBuddhistChronology_dateNow() {
    ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
    Clock clock = Clock.system(zoneId_paris);

    Chronology chrono = Chronology.of("ThaiBuddhist");
    assertEquals(chrono.dateNow(), ThaiBuddhistChronology.INSTANCE.dateNow());
    assertEquals(chrono.dateNow(zoneId_paris), ThaiBuddhistChronology.INSTANCE.dateNow(zoneId_paris));
    assertEquals(chrono.dateNow(clock), ThaiBuddhistChronology.INSTANCE.dateNow(clock));
}
 
Example 35
Project: clustercode   File: JGroupsTaskStateImplTest.java   View source code 5 votes vote down vote up
@Test
public void getCurrentUtcTime_ShouldReturnTimeInUtc() throws Exception {
    subject = new JGroupsTaskStateImpl(Clock.fixed(Instant.parse("2017-01-01T13:30:00Z"), ZoneOffset.UTC));
    ZonedDateTime time = subject.getCurrentUtcTime();
    assertThat(time.getHour()).isEqualTo(13);
    assertThat(time.getMinute()).isEqualTo(30);
    assertThat(time.getOffset()).isEqualByComparingTo(ZoneOffset.UTC);
}
 
Example 36
Project: openjdk-jdk10   File: TCKOffsetTime.java   View source code 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 37
Project: jdk8u-jdk   File: TCKOffsetTime.java   View source code 5 votes vote down vote up
@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetTime test = OffsetTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
Example 38
Project: openjdk-jdk10   File: TCKLocalTime.java   View source code 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    LocalTime.now((Clock) null);
}
 
Example 39
Project: users-service   File: DateServiceImpl.java   View source code 4 votes vote down vote up
public DateServiceImpl() {
    this.clock = Clock.system(ZoneId.of("UTC"));
}
 
Example 40
Project: openjdk-jdk10   File: TCKClock_Fixed.java   View source code 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test_fixed_InstantZoneId_nullInstant() {
    Clock.fixed(null, PARIS);
}