Example usage for java.time ZonedDateTime parse

List of usage examples for java.time ZonedDateTime parse

Introduction

In this page you can find the example usage for java.time ZonedDateTime parse.

Prototype

public static ZonedDateTime parse(CharSequence text) 

Source Link

Document

Obtains an instance of ZonedDateTime from a text string such as 2007-12-03T10:15:30+01:00[Europe/Paris] .

Usage

From source file:org.silverpeas.core.calendar.CalendarEventOccurrenceGenerationTest.java

@Test
public void nextOccurrenceAboutRecurrentHourEventWithExceptionShouldWork() {
    CalendarEvent recurrentEvent = calendarEventForTest(
            Period.between(dateTimeInUTC(2017, 12, 12, 13, 30), dateTimeInUTC(2017, 12, 12, 14, 45)))
                    .recur(Recurrence.every(1, TimeUnit.DAY).until(3).excludeEventOccurrencesStartingAt(
                            dateTimeInUTC(2017, 12, 12, 13, 30), dateTimeInUTC(2017, 12, 14, 13, 30)));
    ZonedDateTime from = ZonedDateTime.parse("2000-01-01T11:11:11-01:00[Atlantic/Azores]");
    CalendarEventOccurrence result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());//from   w  ww  .jav  a  2  s . c  o  m
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 13, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 13, 14, 45)));

    from = ZonedDateTime.parse("2017-12-12T13:29:59Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 13, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 13, 14, 45)));

    from = ZonedDateTime.parse("2017-12-12T13:30:00Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 13, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 13, 14, 45)));

    from = ZonedDateTime.parse("2017-12-13T13:30:00Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, nullValue());
}

From source file:org.silverpeas.core.calendar.CalendarEventOccurrenceGenerationTest.java

@Test
public void nextOccurrenceAboutRecurrentHugeHourEventShouldWork() {
    CalendarEvent recurrentEvent = calendarEventForTest(
            Period.between(dateTimeInUTC(2017, 12, 12, 13, 30), dateTimeInUTC(2017, 12, 15, 14, 45)))
                    .recur(Recurrence.every(1, TimeUnit.DAY).until(3));
    ZonedDateTime from = ZonedDateTime.parse("2000-01-01T11:11:11-01:00[Atlantic/Azores]");
    CalendarEventOccurrence result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());//ww  w.  j  ava 2 s  .  c  o  m
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 12, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 15, 14, 45)));

    from = ZonedDateTime.parse("2017-12-12T13:29:59Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 12, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 15, 14, 45)));

    from = ZonedDateTime.parse("2017-12-12T13:30:00Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 13, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 16, 14, 45)));

    from = ZonedDateTime.parse("2017-12-13T13:30:00Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 14, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 17, 14, 45)));

    from = ZonedDateTime.parse("2017-12-14T13:30:00Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, nullValue());
}

From source file:org.silverpeas.core.calendar.CalendarEventOccurrenceGenerationTest.java

@Test
public void nextOccurrenceAboutRecurrentHugeHourEventWithExceptionShouldWork() {
    CalendarEvent recurrentEvent = calendarEventForTest(
            Period.between(dateTimeInUTC(2017, 12, 12, 13, 30), dateTimeInUTC(2017, 12, 15, 14, 45)))
                    .recur(Recurrence.every(1, TimeUnit.DAY).until(3).excludeEventOccurrencesStartingAt(
                            dateTimeInUTC(2017, 12, 12, 13, 30), dateTimeInUTC(2017, 12, 14, 13, 30)));
    ZonedDateTime from = ZonedDateTime.parse("2000-01-01T11:11:11-01:00[Atlantic/Azores]");
    CalendarEventOccurrence result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());/*from   w  w  w .  j  ava  2s .  c om*/
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 13, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 16, 14, 45)));

    from = ZonedDateTime.parse("2017-12-13T13:29:59Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, notNullValue());
    assertThat(result.getStartDate(), is(dateTimeInUTC(2017, 12, 13, 13, 30)));
    assertThat(result.getEndDate(), is(dateTimeInUTC(2017, 12, 16, 14, 45)));

    from = ZonedDateTime.parse("2017-12-13T13:30:00Z");
    result = generator.generateNextOccurrenceOf(recurrentEvent, from);
    assertThat(result, nullValue());
}

From source file:org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.java

public void updateNotifications(ZonedDateTime currentTime, ZonedDateTime now,
        @Nullable JsonCommandPayloadPushNotificationChange pushPayload,
        JsonNotificationResponse[] notifications) {
    Device device = this.device;
    if (device == null) {
        return;//  w w w  . j  a  va 2s .  c om
    }

    ZonedDateTime nextReminder = null;
    ZonedDateTime nextAlarm = null;
    ZonedDateTime nextMusicAlarm = null;
    ZonedDateTime nextTimer = null;
    for (JsonNotificationResponse notification : notifications) {
        if (StringUtils.equals(notification.deviceSerialNumber, device.serialNumber)) {
            // notification for this device
            if (StringUtils.equals(notification.status, "ON")) {
                if ("Reminder".equals(notification.type)) {
                    String offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()).toString();
                    ZonedDateTime alarmTime = ZonedDateTime
                            .parse(notification.originalDate + "T" + notification.originalTime + offset);
                    if (StringUtils.isNotBlank(notification.recurringPattern) && alarmTime.isBefore(now)) {
                        continue; // Ignore recurring entry if alarm time is before now
                    }
                    if (nextReminder == null || alarmTime.isBefore(nextReminder)) {
                        nextReminder = alarmTime;
                    }
                } else if ("Timer".equals(notification.type)) {
                    // use remaining time
                    ZonedDateTime alarmTime = currentTime.plus(notification.remainingTime, ChronoUnit.MILLIS);
                    if (nextTimer == null || alarmTime.isBefore(nextTimer)) {
                        nextTimer = alarmTime;
                    }
                } else if ("Alarm".equals(notification.type)) {
                    String offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()).toString();
                    ZonedDateTime alarmTime = ZonedDateTime
                            .parse(notification.originalDate + "T" + notification.originalTime + offset);
                    if (StringUtils.isNotBlank(notification.recurringPattern) && alarmTime.isBefore(now)) {
                        continue; // Ignore recurring entry if alarm time is before now
                    }
                    if (nextAlarm == null || alarmTime.isBefore(nextAlarm)) {
                        nextAlarm = alarmTime;
                    }
                } else if ("MusicAlarm".equals(notification.type)) {
                    String offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()).toString();
                    ZonedDateTime alarmTime = ZonedDateTime
                            .parse(notification.originalDate + "T" + notification.originalTime + offset);
                    if (StringUtils.isNotBlank(notification.recurringPattern) && alarmTime.isBefore(now)) {
                        continue; // Ignore recurring entry if alarm time is before now
                    }
                    if (nextMusicAlarm == null || alarmTime.isBefore(nextMusicAlarm)) {
                        nextMusicAlarm = alarmTime;
                    }
                }
            }
        }
    }

    updateState(CHANNEL_NEXT_REMINDER, nextReminder == null ? UnDefType.UNDEF : new DateTimeType(nextReminder));
    updateState(CHANNEL_NEXT_ALARM, nextAlarm == null ? UnDefType.UNDEF : new DateTimeType(nextAlarm));
    updateState(CHANNEL_NEXT_MUSIC_ALARM,
            nextMusicAlarm == null ? UnDefType.UNDEF : new DateTimeType(nextMusicAlarm));
    updateState(CHANNEL_NEXT_TIMER, nextTimer == null ? UnDefType.UNDEF : new DateTimeType(nextTimer));
}

From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java

@Test
public void movingAMessageIsNotSupported() throws Exception {
    String newMailboxName = "heartFolder";
    jmapServer.serverProbe().createMailbox("#private", username, newMailboxName);
    Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", username, newMailboxName);
    String heartFolderId = heartFolder.getMailboxId().serialize();

    ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
    jmapServer.serverProbe().appendMessage(username, new MailboxPath("#private", username, "inbox"),
            new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)),
            Date.from(dateTime.toInstant()), false, new Flags());

    String messageToMoveId = "user|inbox|1";

    String requestBody = "[" + "  [" + "    \"setMessages\"," + "    {" + "      \"update\": { \""
            + messageToMoveId + "\" : {" + "        \"mailboxIds\": [\"" + heartFolderId + "\"]" + "      }}"
            + "    }," + "    \"#0\"" + "  ]" + "]";

    given().header("Authorization", this.accessToken.serialize()).body(requestBody).when().post("/jmap").then()
            .statusCode(200).body(NAME, equalTo("messagesSet")).body(NOT_UPDATED, hasKey(messageToMoveId))
            .body(NOT_UPDATED + "[\"" + messageToMoveId + "\"].type", equalTo("invalidProperties"))
            .body(NOT_UPDATED + "[\"" + messageToMoveId + "\"].properties[0]", equalTo("mailboxIds"))
            .body(NOT_UPDATED + "[\"" + messageToMoveId + "\"].description",
                    equalTo("mailboxIds: moving a message is not supported "
                            + "(through reference chain: org.apache.james.jmap.model.Builder[\"mailboxIds\"])"))
            .body(ARGUMENTS + ".updated", hasSize(0));
}

From source file:org.qcert.camp.translator.SemRule2CAMP.java

/**
 * Generate the appropriate output for converting a String to a long.  At present, we only do this when the string is a constant
 *   (in which case we can evaluate it at compile time and simply produce a long SemConstant).  Generalization to expressions
 *   would be possible but would require timeDate manipulation functions to be present in coq.
 * @param ast the SemMethodInvocation to convert, known to be of the proper form because it was examined by isTimeStringToEpochMillis
 * @return/*  www .j  av a2 s . c  o  m*/
 */
private CampPattern translateTimeStringToEpochMillis(SemMethodInvocation ast) {
    ast = ((SemMethodInvocation) ast.getCurrentObject()); // the toInstant() call
    ast = ((SemMethodInvocation) ast.getCurrentObject()); // the parse() call
    SemValue val = ast.getArguments().get(0); // the string
    if (val instanceof SemConstant) {
        String string = (String) ((SemConstant) val).getValue();
        if (!string.contains("Z"))
            string += "Z";
        long millis = ZonedDateTime.parse(string).toInstant().toEpochMilli();
        return new ConstPattern(millis);
    }
    return notImplemented("String to date conversion for non-constants");
}