Example usage for java.time OffsetDateTime parse

List of usage examples for java.time OffsetDateTime parse

Introduction

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

Prototype

public static OffsetDateTime parse(CharSequence text) 

Source Link

Document

Obtains an instance of OffsetDateTime from a text string such as 2007-12-03T10:15:30+01:00 .

Usage

From source file:org.silverpeas.core.reminder.ContributionReminderUserNotificationTest.java

@Test
public void durationReminderOf0MinuteOnGenericContributionShouldWork() throws Exception {
    final DurationReminder durationReminder = initReminderBuilder().triggerBefore(0, TimeUnit.MINUTE, "");
    triggerDateTime(durationReminder, OffsetDateTime.parse("2018-02-21T00:00:00Z"));
    final Map<String, String> titles = computeNotificationTitles(durationReminder);
    assertThat(titles.get(DE), is("Reminder about the contribution super test - 21.02.2018 00:00"));
    assertThat(titles.get(EN), is("Reminder about the contribution super test - 02/21/2018 00:00"));
    assertThat(titles.get(FR), is("Rappel sur la contribution super test - 21/02/2018 00:00"));
    final Map<String, String> contents = computeNotificationContents(durationReminder);
    assertThat(contents.get(DE),//from  w  w w.j  a  v  a2 s . c  o  m
            is("You set a reminder <b>just</b> before the contribution <b>super test</b> (21.02.2018 00:00)."));
    assertThat(contents.get(EN),
            is("You set a reminder <b>just</b> before the contribution <b>super test</b> (02/21/2018 00:00)."));
    assertThat(contents.get(FR), is(
            "Vous avez demand un rappel <b>juste</b> avant la contribution <b>super test</b> (21/02/2018 00:00)."));
}

From source file:org.silverpeas.core.webapi.reminder.ReminderEntity.java

/**
 * Merges into given reminder instance the data from the entity.<br>
 * System data are not merged (id, creation date, update date, ...)
 * @param reminder the reminder which will get the new data.
 * @return the given reminder instance with merged data.
 * @throw javax.ws.rs.WebApplicationException if given reminder does not exist.
 *///from   w w w  . j  a v a  2s.  c  o m
public Reminder mergeInto(Reminder reminder) {
    reminder.withText(getText());
    if (reminder instanceof DateTimeReminder) {
        final DateTimeReminder dateTimeReminder = (DateTimeReminder) reminder;
        dateTimeReminder.triggerAt(OffsetDateTime.parse(getDateTime()));
    } else {
        final DurationReminder durationReminder = (DurationReminder) reminder;
        durationReminder.triggerBefore(getDuration(), getTimeUnit(), getcProperty());
    }
    return reminder;
}

From source file:org.silverpeas.core.reminder.ContributionReminderUserNotificationTest.java

@Test
public void durationReminderOf1MinuteOnGenericContributionShouldWork() throws Exception {
    final DurationReminder durationReminder = initReminderBuilder().triggerBefore(1, TimeUnit.MINUTE, "");
    triggerDateTime(durationReminder, OffsetDateTime.parse("2018-02-20T23:59:00Z"));
    final Map<String, String> titles = computeNotificationTitles(durationReminder);
    assertThat(titles.get(DE), is("Reminder about the contribution super test - 21.02.2018 00:00"));
    assertThat(titles.get(EN), is("Reminder about the contribution super test - 02/21/2018 00:00"));
    assertThat(titles.get(FR), is("Rappel sur la contribution super test - 21/02/2018 00:00"));
    final Map<String, String> contents = computeNotificationContents(durationReminder);
    assertThat(contents.get(DE), is(// www  . java  2s  . com
            "You set a reminder <b>1 minute</b> before the contribution <b>super test</b> (21.02.2018 00:00)."));
    assertThat(contents.get(EN), is(
            "You set a reminder <b>1 minute</b> before the contribution <b>super test</b> (02/21/2018 00:00)."));
    assertThat(contents.get(FR), is(
            "Vous avez demand un rappel <b>1 minute</b> avant la contribution <b>super test</b> (21/02/2018 00:00)."));
}

From source file:org.silverpeas.core.reminder.ContributionReminderUserNotificationTest.java

@Test
public void durationReminderOf5MinutesOnGenericContributionShouldWork() throws Exception {
    final DurationReminder durationReminder = initReminderBuilder().triggerBefore(5, TimeUnit.MINUTE, "");
    triggerDateTime(durationReminder, OffsetDateTime.parse("2018-02-20T23:55:00Z"));
    final Map<String, String> titles = computeNotificationTitles(durationReminder);
    assertThat(titles.get(DE), is("Reminder about the contribution super test - 21.02.2018 00:00"));
    assertThat(titles.get(EN), is("Reminder about the contribution super test - 02/21/2018 00:00"));
    assertThat(titles.get(FR), is("Rappel sur la contribution super test - 21/02/2018 00:00"));
    final Map<String, String> contents = computeNotificationContents(durationReminder);
    assertThat(contents.get(DE), is(/*from w  ww.  j a  v  a  2s  . c om*/
            "You set a reminder <b>5 minutes</b> before the contribution <b>super test</b> (21.02.2018 00:00)."));
    assertThat(contents.get(EN), is(
            "You set a reminder <b>5 minutes</b> before the contribution <b>super test</b> (02/21/2018 00:00)."));
    assertThat(contents.get(FR), is(
            "Vous avez demand un rappel <b>5 minutes</b> avant la contribution <b>super test</b> (21/02/2018 00:00)."));
}

From source file:msi.gama.util.GamaDate.java

private static Temporal parse(final IScope scope, final String original, final DateTimeFormatter df) {
    if (original == null || original.isEmpty() || original.equals("now")) {
        return LocalDateTime.now(GamaDateType.DEFAULT_ZONE);
    }/*from   www . j a  v a  2s.  c o m*/
    Temporal result = null;

    if (df != null) {
        try {
            final TemporalAccessor ta = df.parse(original);
            if (ta instanceof Temporal) {
                return (Temporal) ta;
            }
            if (!ta.isSupported(ChronoField.YEAR) && !ta.isSupported(ChronoField.MONTH_OF_YEAR)
                    && !ta.isSupported(ChronoField.DAY_OF_MONTH)) {
                if (ta.isSupported(ChronoField.HOUR_OF_DAY)) {
                    return LocalTime.from(ta);
                }
            }
            if (!ta.isSupported(ChronoField.HOUR_OF_DAY) && !ta.isSupported(ChronoField.MINUTE_OF_HOUR)
                    && !ta.isSupported(ChronoField.SECOND_OF_MINUTE)) {
                return LocalDate.from(ta);
            }
            return LocalDateTime.from(ta);
        } catch (final DateTimeParseException e) {
            e.printStackTrace();
        }
        GAMA.reportAndThrowIfNeeded(scope,
                GamaRuntimeException.warning(
                        "The date " + original + " can not correctly be parsed by the pattern provided", scope),
                false);
        return parse(scope, original, null);
    }

    String dateStr;
    try {
        // We first make sure all date fields have the correct length and
        // the string is correctly formatted
        String string = original;
        if (!original.contains("T") && original.contains(" ")) {
            string = StringUtils.replaceOnce(original, " ", "T");
        }
        final String[] base = string.split("T");
        final String[] date = base[0].split("-");
        String other;
        if (base.length == 1) {
            other = "00:00:00";
        } else {
            other = base[1];
        }
        String year, month, day;
        if (date.length == 1) {
            // ISO basic date format
            year = date[0].substring(0, 4);
            month = date[0].substring(4, 6);
            day = date[0].substring(6, 8);
        } else {
            year = date[0];
            month = date[1];
            day = date[2];
        }
        if (year.length() == 2) {
            year = "20" + year;
        }
        if (month.length() == 1) {
            month = '0' + month;
        }
        if (day.length() == 1) {
            day = '0' + day;
        }
        dateStr = year + "-" + month + "-" + day + "T" + other;
    } catch (final Exception e1) {
        throw GamaRuntimeException.error("The date " + original
                + " is not correctly formatted. Please refer to the ISO date/time format", scope);
    }

    try {
        result = LocalDateTime.parse(dateStr);
    } catch (final DateTimeParseException e) {
        try {
            result = OffsetDateTime.parse(dateStr);
        } catch (final DateTimeParseException e2) {
            try {
                result = ZonedDateTime.parse(dateStr);
            } catch (final DateTimeParseException e3) {
                throw GamaRuntimeException.error(
                        "The date " + original
                                + " is not correctly formatted. Please refer to the ISO date/time format",
                        scope);
            }
        }
    }

    return result;
}

From source file:com.nike.cerberus.service.MetadataServiceTest.java

@Test
public void test_that_restore_metadata_calls_the_sdb_service_with_expected_sdb_box() throws IOException {
    String user = "unit-test-user";
    String id = "111";
    String categoryId = "222";
    String categoryName = "Applications";
    String readId = "333";
    String sdbName = "HEALTH CHECK BUCKET";

    ObjectMapper mapper = CmsConfig.configureObjectMapper();
    InputStream metadataStream = getClass().getClassLoader()
            .getResourceAsStream("com/nike/cerberus/service/sdb_metadata_backup.json");
    SDBMetadata sdbMetadata = mapper.readValue(metadataStream, SDBMetadata.class);

    when(safeDepositBoxService.getSafeDepositBoxIdByName(sdbName)).thenReturn(Optional.ofNullable(null));
    when(uuidSupplier.get()).thenReturn(id);
    when(categoryService.getCategoryIdByName(categoryName)).thenReturn(Optional.of(categoryId));
    Role readRole = new Role();
    readRole.setId(readId);//from  w  ww.  j a  v a  2  s .c om
    when(roleService.getRoleByName(RoleRecord.ROLE_READ)).thenReturn(Optional.of(readRole));

    metadataService.restoreMetadata(sdbMetadata, user);

    SafeDepositBoxV2 expectedSdb = new SafeDepositBoxV2();
    expectedSdb.setId(id);
    expectedSdb.setPath("app/health-check-bucket/");
    expectedSdb.setCategoryId(categoryId);
    expectedSdb.setName(sdbName);
    expectedSdb.setOwner("Lst-Squad.Carebears");
    expectedSdb.setDescription("This SDB is read by the Health Check Lambda...");
    expectedSdb.setCreatedTs(OffsetDateTime.parse("2016-09-08T15:39:31Z"));
    expectedSdb.setLastUpdatedTs(OffsetDateTime.parse("2016-12-13T17:28:00Z"));
    expectedSdb.setCreatedBy("justin.field@nike.com");
    expectedSdb.setLastUpdatedBy("todd.lisonbee@nike.com");

    Set<UserGroupPermission> userPerms = new HashSet<>();
    userPerms.add(new UserGroupPermission().withName("Foundation.Prod.Support").withRoleId(readId));
    userPerms.add(new UserGroupPermission().withName("Lst-NIKE.FOO.ISL").withRoleId(readId));
    expectedSdb.setUserGroupPermissions(userPerms);

    Set<IamPrincipalPermission> iamPerms = new HashSet<>();
    String arn = "arn:aws:iam::1111111111:role/lambda_prod_healthcheck";
    iamPerms.add(new IamPrincipalPermission().withIamPrincipalArn(arn).withRoleId(readId));
    expectedSdb.setIamPrincipalPermissions(iamPerms);

    expectedSdb.setUserGroupPermissions(userPerms);
    expectedSdb.setIamPrincipalPermissions(iamPerms);

    verify(safeDepositBoxService, times(1)).restoreSafeDepositBox(expectedSdb, user);
}

From source file:org.silverpeas.core.reminder.ContributionReminderUserNotificationTest.java

@Test
public void durationReminderOf0HourAndWithAnotherUserZoneIdOnGenericContributionShouldWork() throws Exception {
    receiver.getUserPreferences().setZoneId(ZoneId.of("Asia/Muscat"));
    final DurationReminder durationReminder = initReminderBuilder().triggerBefore(0, TimeUnit.HOUR, "");
    triggerDateTime(durationReminder, OffsetDateTime.parse("2018-02-21T00:00:00Z"));
    final Map<String, String> titles = computeNotificationTitles(durationReminder);
    assertThat(titles.get(DE), is("Reminder about the contribution super test - 21.02.2018 00:00 (UTC)"));
    assertThat(titles.get(EN), is("Reminder about the contribution super test - 02/21/2018 00:00 (UTC)"));
    assertThat(titles.get(FR), is("Rappel sur la contribution super test - 21/02/2018 00:00 (UTC)"));
    final Map<String, String> contents = computeNotificationContents(durationReminder);
    assertThat(contents.get(DE), is(//  w w  w .  j  a  va 2 s .  co  m
            "You set a reminder <b>just</b> before the contribution <b>super test</b> (21.02.2018 00:00 (UTC))."));
    assertThat(contents.get(EN), is(
            "You set a reminder <b>just</b> before the contribution <b>super test</b> (02/21/2018 00:00 (UTC))."));
    assertThat(contents.get(FR), is(
            "Vous avez demand un rappel <b>juste</b> avant la contribution <b>super test</b> (21/02/2018 00:00 (UTC))."));
}

From source file:org.silverpeas.core.webapi.calendar.CalendarEventEntity.java

/**
 * Gets the period of the event.//from   w ww .j  ava2 s.co m
 * @return a period instance.
 */
@XmlTransient
Period getPeriod() {
    final Period eventPeriod;
    if (isOnAllDay()) {
        eventPeriod = Period.between(LocalDate.parse(startDate), LocalDate.parse(endDate));
    } else {
        eventPeriod = Period.between(OffsetDateTime.parse(startDate), OffsetDateTime.parse(endDate));
    }
    return eventPeriod;
}

From source file:net.dv8tion.jda.handle.EntityBuilder.java

private void createGuildMemberPass(GuildImpl guildObj, JSONArray members) {
    Map<String, Role> rolesMap = guildObj.getRolesMap();
    Map<User, List<Role>> userRoles = guildObj.getUserRoles();
    Map<User, VoiceStatus> voiceStatusMap = guildObj.getVoiceStatusMap();
    Map<User, OffsetDateTime> joinedAtMap = guildObj.getJoinedAtMap();
    Map<User, String> nickMap = guildObj.getNickMap();
    for (int i = 0; i < members.length(); i++) {
        JSONObject member = members.getJSONObject(i);
        User user = createUser(member.getJSONObject("user"));
        userRoles.put(user, new ArrayList<>());
        JSONArray roleArr = member.getJSONArray("roles");
        for (int j = 0; j < roleArr.length(); j++) {
            String roleId = roleArr.getString(j);
            Role role = rolesMap.get(roleId);
            if (role != null) {
                userRoles.get(user).add(role);
            } else {
                WebSocketClient.LOG//w  w w.ja  v a 2s. c  o  m
                        .warn("While building the guild users, encountered a user that is assigned a "
                                + "non-existent role. This is a Discord error, not a JDA error. Ignoring the role. "
                                + "GuildId: " + guildObj.getId() + " UserId: " + user.getId() + " RoleId: "
                                + roleId);
            }
        }
        VoiceStatusImpl voiceStatus = new VoiceStatusImpl(user, guildObj);
        voiceStatus.setServerDeaf(member.getBoolean("deaf"));
        voiceStatus.setServerMute(member.getBoolean("mute"));
        voiceStatusMap.put(user, voiceStatus);
        joinedAtMap.put(user, OffsetDateTime.parse(member.getString("joined_at")));
        if (member.has("nick") && !member.isNull("nick"))
            nickMap.put(user, member.getString("nick"));
    }
}

From source file:org.openbase.bco.ontology.lib.manager.aggregation.DataAggregation.java

/**
 * Method is used to check and prepare the input information, which should be aggregated.
 *
 * @param unitConnectionTime is the time, which describes the connection time in milliseconds between unit and bco. Inconspicuous connection states should
 *                           have connection times equal the time frame of aggregation.
 * @param stateChanges are the state changes, which should be sorted ascending by including timestamp.
 * @return the sorted list of state changes.
 * @throws MultiException is thrown in case the verification of input information, which should be aggregated, is invalid.
 *//*from  w  w  w. j a v  a 2 s .c om*/
private List<OntStateChangeBuf> preparingStateChanges(final long unitConnectionTime,
        final List<OntStateChangeBuf> stateChanges) throws MultiException {
    MultiException.ExceptionStack exceptionStack = null;

    try {
        if (unitConnectionTime > timeFrameMilliS) {
            throw new VerificationFailedException(
                    "The unitConnectionTime is bigger than the time frame of aggregation!");
        }
    } catch (VerificationFailedException e) {
        exceptionStack = MultiException.push(this, e, null);
    }
    try {
        if (stateChanges.isEmpty()) {
            throw new VerificationFailedException("The list of state changes is empty!");
        }
    } catch (VerificationFailedException e) {
        exceptionStack = MultiException.push(this, e, exceptionStack);
    }
    try {
        if (OffsetDateTime.parse(stateChanges.get(0).getTimestamp()).isAfter(dateTimeFrom)) {
            throw new VerificationFailedException(
                    "First state change is after the beginning aggregation time frame! No information about the state in "
                            + "the beginning time frame! First state change entry should be, chronological, before/equal the beginning time frame.");
        }
    } catch (VerificationFailedException e) {
        exceptionStack = MultiException.push(this, e, exceptionStack);
    }

    MultiException.checkAndThrow("Could not perform aggregation!", exceptionStack);

    // sort ascending (old to young)
    stateChanges.sort(Comparator.comparing(OntStateChangeBuf::getTimestamp));

    return stateChanges;
}