Java Code Examples for java.time.LocalTime#now()

The following examples show how to use java.time.LocalTime#now() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddTimerWidgetWithStopTimeAndRemove() throws Exception {
    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
    Timer timer = new Timer();
    timer.id = 112;
    timer.x = 1;
    timer.y = 1;
    timer.pinType = PinType.DIGITAL;
    timer.pin = 5;
    timer.width = 2;
    timer.height = 1;
    timer.startValue = "1";
    timer.stopValue = "0";
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.startTime = curTime + 1;
    timer.stopTime = curTime + 2;

    clientPair.appClient.createWidget(1, timer);
    clientPair.appClient.verifyResult(ok(1));

    clientPair.appClient.deleteWidget(1, 112);
    clientPair.appClient.verifyResult(ok(2));

    verify(clientPair.hardwareClient.responseMock, after(2500).never()).channelRead(any(), any());
}
 
Example 2
Source File: MarketDayUtil.java    From java-trader with Apache License 2.0 6 votes vote down vote up
public static LocalDate thisOrNextMarketDay(Exchange exchange, LocalDate tradingDay, boolean thisCompleted){
    if ( exchange==null) {
        exchange = Exchange.SSE;
    }
    if( tradingDay==null ) {
        tradingDay = LocalDate.now(exchange.getZoneId());
    }
    LocalTime thisTime = LocalTime.now(exchange.getZoneId());
    if ( thisCompleted && thisTime.compareTo(exchange.getMarketTimes()[1])<=0 ){
        tradingDay = tradingDay.plusMonths(1);
    }
    if ( isMarketDay(exchange, tradingDay) ) {
        return tradingDay;
    }
    return nextMarketDay(exchange, tradingDay);
}
 
Example 3
Source File: WaitingQueueProcessorIntegrationTest.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testPreRegistration() {
    List<TicketCategoryModification> categories = Collections.singletonList(
            new TicketCategoryModification(null, "default", 10,
                    new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()),
                    new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()),
                    DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event.mustUseFirstAndLastName()), "[email protected]", null, Locale.ENGLISH);
    waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event.mustUseFirstAndLastName()), "[email protected]", null, Locale.ITALIAN);
    assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);

    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size());

    TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10,
            new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()),
            new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()),
            DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty());
    eventManager.insertCategory(event.getId(), tcm, pair.getValue());

    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);

    List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
    assertTrue(subscriptions.stream().allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)));
    assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES)));

}
 
Example 4
Source File: TCKLocalTime.java    From jdk8u-jdk with GNU General Public License v2.0 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 5
Source File: CurrentTime.java    From antsdb with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) {
	LocalTime time = LocalTime.now();
	Duration duration = Duration.ofSeconds(time.getHour() * 3600 + time.getMinute() * 60 + time.getSecond());
    long addr = FishTime.allocSet(heap, duration);
    return addr;
}
 
Example 6
Source File: TCKLocalTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalTime expected = LocalTime.now(Clock.system(zone));
    LocalTime test = LocalTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalTime.now(Clock.system(zone));
        test = LocalTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 7
Source File: TCKLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    LocalTime expected = LocalTime.now(Clock.system(zone));
    LocalTime test = LocalTime.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = LocalTime.now(Clock.system(zone));
        test = LocalTime.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 8
Source File: TCKLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 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 9
Source File: CassandraRowMapperFnTest.java    From DataflowTemplates with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeColumn() {
  LocalTime now = LocalTime.now(ZoneId.systemDefault());

  Long value = now.toNanoOfDay();
  primeWithType(value, TIME);
  ResultSet resultSet = getResultSet();

  Schema schema = Schema.builder().addNullableField("col", FieldType.INT64).build();
  Row expected = Row.withSchema(schema).addValue(value).build();

  assertEquals(expected, cassandraRowMapper.map(resultSet).next());
}
 
Example 10
Source File: TCKLocalTime.java    From openjdk-8 with GNU General Public License v2.0 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 11
Source File: TCKLocalTime.java    From openjdk-jdk9 with GNU General Public License v2.0 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 12
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testTimerWidgetTriggeredAndSendCommandToCorrectDevice() throws Exception {
    TestHardClient hardClient2 = new TestHardClient("localhost", properties.getHttpPort());
    hardClient2.start();

    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);

    clientPair.appClient.deactivate(1);
    clientPair.appClient.verifyResult(ok(1));

    Timer timer = new Timer();
    timer.id = 1;
    timer.x = 1;
    timer.y = 1;
    timer.pinType = PinType.DIGITAL;
    timer.pin = 5;
    timer.startValue = "1";
    timer.stopValue = "0";
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.startTime = curTime + 1;
    timer.stopTime = curTime + 2;

    DashBoard dashBoard = new DashBoard();
    dashBoard.id = 1;
    dashBoard.name = "Test";
    dashBoard.widgets = new Widget[] {timer};

    clientPair.appClient.updateDash(dashBoard);
    clientPair.appClient.verifyResult(ok(2));

    dashBoard.id = 2;
    clientPair.appClient.createDash(dashBoard);
    clientPair.appClient.verifyResult(ok(3));

    clientPair.appClient.activate(1);
    clientPair.appClient.verifyResult(ok(4));

    clientPair.appClient.reset();
    clientPair.appClient.createDevice(2, new Device(1, "Device", BoardType.ESP8266));
    Device device = clientPair.appClient.parseDevice();
    hardClient2.login(device.token);
    hardClient2.verifyResult(ok(1));
    hardClient2.reset();

    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 1")));
    clientPair.hardwareClient.reset();
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 0")));

    verify(hardClient2.responseMock, never()).channelRead(any(), any());
    hardClient2.stop().awaitUninterruptibly();
}
 
Example 13
Source File: TCKLocalTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
    LocalTime.now((ZoneId) null);
}
 
Example 14
Source File: BlogService.java    From Spring-Boot-2-Fundamentals with MIT License 4 votes vote down vote up
public String getTimeMessage(){
    return "It is "+LocalTime.now();
}
 
Example 15
Source File: TCKLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
    LocalTime.now((ZoneId) null);
}
 
Example 16
Source File: ReportButtonPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private String getJagexTime()
{
	LocalTime time = LocalTime.now(JAGEX);
	return time.format(timeFormat);
}
 
Example 17
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testTimerWidgetTriggeredAndSyncWorks() throws Exception {
    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);

    clientPair.appClient.deactivate(1);
    clientPair.appClient.verifyResult(ok(1));

    Timer timer = new Timer();
    timer.id = 1;
    timer.x = 1;
    timer.y = 1;
    timer.pinType = PinType.VIRTUAL;
    timer.pin = 5;
    timer.startValue = "1";
    timer.stopValue = "0";
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.startTime = curTime + 1;
    timer.stopTime = curTime + 2;

    DashBoard dashBoard = new DashBoard();
    dashBoard.id = 1;
    dashBoard.name = "Test";
    dashBoard.widgets = new Widget[] {timer};

    clientPair.appClient.updateDash(dashBoard);
    clientPair.appClient.verifyResult(ok(2));

    clientPair.appClient.activate(1);
    clientPair.appClient.verifyResult(ok(3));

    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "vw 5 1")));
    clientPair.hardwareClient.reset();
    clientPair.hardwareClient.sync(PinType.VIRTUAL, 5);
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(1, "vw 5 1")));

    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "vw 5 0")));

    clientPair.hardwareClient.sync(PinType.VIRTUAL, 5);
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(2, "vw 5 0")));
}
 
Example 18
Source File: TCKLocalTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    LocalTime.now((Clock) null);
}
 
Example 19
Source File: TCKLocalTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    LocalTime.now((Clock) null);
}
 
Example 20
Source File: ReportButtonPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private String getJagexTime()
{
	LocalTime time = LocalTime.now(JAGEX);
	return time.format(timeFormat);
}