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

The following examples show how to use java.time.LocalTime#toSecondOfDay() . 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: ExtendedQueryCommandCodec.java    From vertx-sql-client with Apache License 2.0 6 votes vote down vote up
private void encodeTimeNParameter(ByteBuf payload, LocalTime time, byte scale) {
  payload.writeByte(0x00);
  payload.writeByte(0x00);
  payload.writeByte(MSSQLDataTypeId.TIMENTYPE_ID);

  payload.writeByte(scale); //FIXME scale?
  if (time == null) {
    payload.writeByte(0);
  } else {
    int length;
    if (scale <= 2) {
      length = 3;
    } else if (scale <= 4) {
      length = 4;
    } else {
      length = 5;
    }
    payload.writeByte(length);
    long nanos = time.getNano();
    int seconds = time.toSecondOfDay();
    long value = (long) ((long) seconds * Math.pow(10, scale) + nanos);
    encodeInt40(payload, value);
  }
}
 
Example 2
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddTimerWidgetWithStartTimeTriggered() throws Exception {
    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
    Timer timer = new Timer();
    timer.id = 112;
    timer.x = 1;
    timer.y = 1;
    timer.width = 2;
    timer.height = 1;
    timer.pinType = PinType.DIGITAL;
    timer.pin = 5;
    timer.startValue = "1";
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.startTime = curTime + 1;

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

    verify(clientPair.hardwareClient.responseMock, timeout(1500).times(1)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 1")));
}
 
Example 3
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddTimerWidgetWithStopAndStartTimeTriggered() throws Exception {
    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
    Timer timer = new Timer();
    timer.id = 112;
    timer.x = 1;
    timer.y = 1;
    timer.width = 2;
    timer.height = 1;
    timer.pinType = PinType.DIGITAL;
    timer.pin = 5;
    timer.stopValue = "0";
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.stopTime = curTime + 1;

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

    verify(clientPair.hardwareClient.responseMock, timeout(1500).times(1)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 0")));
}
 
Example 4
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddTimerWidgetWithStopTimeTriggered() 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));

    verify(clientPair.hardwareClient.responseMock, timeout(2500).times(2)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 0")));
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 1")));
}
 
Example 5
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 6
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddTimerWithSameStartStopTriggered() 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 = "0";
    timer.stopValue = "1";
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.startTime = curTime + 1;
    timer.stopTime = curTime + 1;

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

    verify(clientPair.hardwareClient.responseMock, timeout(2500).times(2)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 0")));
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 1")));
}
 
Example 7
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDashTimerNotTriggered() throws Exception {
    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
    Timer timer = new Timer();
    timer.id = 112;
    timer.x = 1;
    timer.y = 1;
    timer.width = 2;
    timer.height = 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;

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

    clientPair.appClient.deleteDash(1);
    clientPair.appClient.verifyResult(ok(2));

    verify(clientPair.hardwareClient.responseMock, after(2500).times(0)).channelRead(any(), any());
}
 
Example 8
Source File: RandomTimes.java    From tutorials with MIT License 5 votes vote down vote up
public static LocalTime between(LocalTime startTime, LocalTime endTime) {
    int startSeconds = startTime.toSecondOfDay();
    int endSeconds = endTime.toSecondOfDay();
    int randomTime = ThreadLocalRandom.current().nextInt(startSeconds, endSeconds);

    return LocalTime.ofSecondOfDay(randomTime);
}
 
Example 9
Source File: JsonRowDataDeserializationSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
private int convertToTime(JsonNode jsonNode) {
	TemporalAccessor parsedTime = SQL_TIME_FORMAT.parse(jsonNode.asText());
	LocalTime localTime = parsedTime.query(TemporalQueries.localTime());

	// get number of milliseconds of the day
	return localTime.toSecondOfDay() * 1000;
}
 
Example 10
Source File: CsvRowDataDeserializationSchema.java    From flink with Apache License 2.0 5 votes vote down vote up
private int convertToTime(JsonNode jsonNode) {
	// csv currently is using Time.valueOf() to parse time string
	LocalTime localTime = Time.valueOf(jsonNode.asText()).toLocalTime();
	// TODO: FLINK-17525 support millisecond and nanosecond
	// get number of milliseconds of the day
	return localTime.toSecondOfDay() * 1000;
}
 
Example 11
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTimerWidgetTriggered() 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.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));

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

    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")));
}
 
Example 12
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUpdateTimerWidgetWithStopTimeTriggered() throws Exception {
    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
    Timer timer = new Timer();
    timer.id = 112;
    timer.x = 1;
    timer.y = 1;
    timer.width = 2;
    timer.height = 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;

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

    timer.startValue = "11";
    timer.stopValue = "10";

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

    verify(clientPair.hardwareClient.responseMock, timeout(2500).times(2)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 11")));
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 10")));
}
 
Example 13
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testAddFewTimersWidgetWithStartTimeTriggered() 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.startValue = "1";
    timer.width = 2;
    timer.height = 1;
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.startTime = curTime + 1;

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

    timer.id = 113;
    timer.startValue = "2";

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

    verify(clientPair.hardwareClient.responseMock, timeout(2500).times(2)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 1")));
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 2")));
}
 
Example 14
Source File: TestPulsarConnector.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private static List<Entry> getTopicEntries(String topicSchemaName) {
    List<Entry> entries = new LinkedList<>();

    long count = topicsToNumEntries.get(topicSchemaName);
    for (int i=0 ; i < count; i++) {

        Foo foo = new Foo();
        foo.field1 = (int) count;
        foo.field2 = String.valueOf(count);
        foo.field3 = count;
        foo.field4 = count;
        foo.field5 = count % 2 == 0;
        foo.field6 = count;
        foo.timestamp = System.currentTimeMillis();

        LocalTime now = LocalTime.now(ZoneId.systemDefault());
        foo.time = now.toSecondOfDay() * 1000;

        LocalDate localDate = LocalDate.now();
        LocalDate epoch = LocalDate.ofEpochDay(0);
        foo.date = Math.toIntExact(ChronoUnit.DAYS.between(epoch, localDate));

        PulsarApi.MessageMetadata messageMetadata = PulsarApi.MessageMetadata.newBuilder()
                .setProducerName("test-producer").setSequenceId(i)
                .setPublishTime(currentTimeMs + i).build();

        Schema schema = topicsToSchemas.get(topicSchemaName).getType() == SchemaType.AVRO ? AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build()) : JSONSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());

        ByteBuf payload = io.netty.buffer.Unpooled
                .copiedBuffer(schema.encode(foo));

        ByteBuf byteBuf = serializeMetadataAndPayload(
                Commands.ChecksumType.Crc32c, messageMetadata, payload);

        Entry entry = EntryImpl.create(0, i, byteBuf);
        log.info("create entry: %s", entry.getEntryId());
        entries.add(entry);
    }
    return entries;
}
 
Example 15
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 16
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 17
Source File: TimerTest.java    From blynk-server with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testAddTimerWidgetToDeviceTilesWithStartTimeTriggered() throws Exception {
    DeviceTiles deviceTiles = new DeviceTiles();
    deviceTiles.id = 21321;
    deviceTiles.x = 8;
    deviceTiles.y = 8;
    deviceTiles.width = 50;
    deviceTiles.height = 100;

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

    TileTemplate tileTemplate = new ButtonTileTemplate(1,
            null, new int[] {0}, "name", "name", "iconName", BoardType.ESP8266, new DataStream((short) 111, PinType.VIRTUAL),
            false, false, false, null, null);

    clientPair.appClient.send("createTemplate " + b("1 " + deviceTiles.id + " ")
            + MAPPER.writeValueAsString(tileTemplate));
    clientPair.appClient.verifyResult(ok(2));

    ses.scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
    Timer timer = new Timer();
    timer.id = 112;
    timer.x = 1;
    timer.y = 1;
    timer.width = 2;
    timer.height = 1;
    timer.pinType = PinType.DIGITAL;
    timer.pin = 5;
    timer.startValue = "1";
    timer.deviceId = -1;
    LocalTime localDateTime = LocalTime.now(ZoneId.of("UTC"));
    int curTime = localDateTime.toSecondOfDay();
    timer.startTime = curTime + 1;

    clientPair.appClient.createWidget(1, b("21321 1 ") + JsonParser.MAPPER.writeValueAsString(timer));
    clientPair.appClient.verifyResult(ok(3));

    verify(clientPair.hardwareClient.responseMock, timeout(1500).times(1)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "dw 5 1")));
    verify(clientPair.appClient.responseMock, timeout(2000)).channelRead(any(), eq(hardware(7777, "1-0 dw 5 1")));
}
 
Example 18
Source File: HttpAndTCPSameJVMTest.java    From blynk-server with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testTimerWidgeWorkerWorksAsExpectedWithHttp() throws Exception {
    Executors.newScheduledThreadPool(1).scheduleAtFixedRate(holder.timerWorker, 0, 1000, TimeUnit.MILLISECONDS);
    Timer timer = new Timer();
    timer.id = 112;
    timer.x = 1;
    timer.y = 1;
    timer.pinType = VIRTUAL;
    timer.pin = 4;
    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 + 1;

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

    verify(clientPair.hardwareClient.responseMock, timeout(2500).times(2)).channelRead(any(), any());
    verify(clientPair.hardwareClient.responseMock, timeout(500)).channelRead(any(), eq(produce(7777, HARDWARE, b("vw 4 1"))));
    verify(clientPair.hardwareClient.responseMock, timeout(500)).channelRead(any(), eq(produce(7777, HARDWARE, b("vw 4 0"))));

    verify(clientPair.appClient.responseMock, timeout(2500).times(3)).channelRead(any(), any());
    verify(clientPair.appClient.responseMock, timeout(500)).channelRead(any(), eq(produce(7777, HARDWARE, b("1-0 vw 4 1"))));
    verify(clientPair.appClient.responseMock, timeout(500)).channelRead(any(), eq(produce(7777, HARDWARE, b("1-0 vw 4 0"))));

    clientPair.appClient.reset();
    HttpGet requestGET = new HttpGet(httpServerUrl + clientPair.token + "/get/v4");

    try (CloseableHttpResponse response = httpclient.execute(requestGET)) {
        assertEquals(200, response.getStatusLine().getStatusCode());
        List<String> values = TestUtil.consumeJsonPinValues(response);
        assertEquals(1, values.size());
        //todo order is not guarateed here!!! Known issue
        String res = values.get(0);
        assertTrue("0".equals(res) || "1".equals(res));
    }
}
 
Example 19
Source File: Functions.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
public SecondsSinceMidnight evaluate(LocalTime input){
	return new SecondsSinceMidnight(input.toSecondOfDay());
}
 
Example 20
Source File: ZoneRules.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Writes the state of the transition rule to the stream.
 *
 * @param rule  the transition rule, not null
 * @param out  the output stream, not null
 * @throws IOException if an error occurs
 */
static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException {
    int month = rule.getMonth().getValue();
    byte dom = (byte)rule.getDayOfMonthIndicator();
    int dow = (rule.getDayOfWeek() == null ? -1 : rule.getDayOfWeek().getValue());
    LocalTime time = rule.getLocalTime();
    boolean timeEndOfDay = rule.isMidnightEndOfDay();
    TimeDefinition timeDefinition = rule.getTimeDefinition();
    ZoneOffset standardOffset = rule.getStandardOffset();
    ZoneOffset offsetBefore = rule.getOffsetBefore();
    ZoneOffset offsetAfter = rule.getOffsetAfter();

    int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
    int stdOffset = standardOffset.getTotalSeconds();
    int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
    int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
    int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
    int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
    int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
    int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
    int dowByte = (dow == -1 ? 0 : dow);
    int b = (month << 28) +                     // 4 bytes
            ((dom + 32) << 22) +                // 6 bytes
            (dowByte << 19) +                   // 3 bytes
            (timeByte << 14) +                  // 5 bytes
            (timeDefinition.ordinal() << 12) +  // 2 bytes
            (stdOffsetByte << 4) +              // 8 bytes
            (beforeByte << 2) +                 // 2 bytes
            afterByte;                          // 2 bytes
    out.writeInt(b);
    if (timeByte == 31) {
        out.writeInt(timeSecs);
    }
    if (stdOffsetByte == 255) {
        out.writeInt(stdOffset);
    }
    if (beforeByte == 3) {
        out.writeInt(offsetBefore.getTotalSeconds());
    }
    if (afterByte == 3) {
        out.writeInt(offsetAfter.getTotalSeconds());
    }
}