Example usage for org.joda.time.format DateTimeFormatter parseDateTime

List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseDateTime.

Prototype

public DateTime parseDateTime(String text) 

Source Link

Document

Parses a date-time from the given text, returning a new DateTime.

Usage

From source file:org.integratedmodelling.time.literals.TimeValue.java

License:Open Source License

@Override
public void parseLiteral(String s) throws ThinklabValidationException {
    try {/*from  w ww .j  ava 2s. co m*/

        if (s.matches(matchYear)) {
            DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy");
            value = fmt.parseDateTime(s);
            precision = TemporalPrecision.YEAR;
        } else if (s.matches(matchMonthYear)) {
            DateTimeFormatter fmt = DateTimeFormat.forPattern("MM-yyyy");
            value = fmt.parseDateTime(s);
            precision = TemporalPrecision.MONTH;
        } else if (s.matches(matchDayMonthYear)) {
            DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
            value = fmt.parseDateTime(s);
            precision = TemporalPrecision.DAY;
        } else {
            value = new DateTime(s);
        }
        concept = TimePlugin.DateTime();
    } catch (Exception e) {
        throw new ThinklabValidationException(e);
    }
}

From source file:org.jahia.modules.jcroauthprovider.impl.JCROAuthProviderMapperImpl.java

License:Open Source License

private void updateUserProperties(JCRUserNode userNode, Map<String, Object> mapperResult)
        throws RepositoryException {
    for (Map.Entry<String, Object> entry : mapperResult.entrySet()) {
        if (!entry.getKey().equals(JahiaOAuthConstants.TOKEN_DATA)
                && !entry.getKey().equals(JahiaOAuthConstants.CONNECTOR_NAME_AND_ID)
                && !entry.getKey().equals(JahiaOAuthConstants.PROPERTY_SITE_KEY)
                && !entry.getKey().equals(JahiaOAuthConstants.CONNECTOR_SERVICE_NAME)) {
            Map<String, Object> propertyInfo = (Map<String, Object>) entry.getValue();
            if (propertyInfo.get(JahiaOAuthConstants.PROPERTY_VALUE_TYPE).equals("date")) {
                DateTimeFormatter dtf = DateTimeFormat
                        .forPattern((String) propertyInfo.get(JahiaOAuthConstants.PROPERTY_VALUE_FORMAT));
                DateTime date = dtf
                        .parseDateTime((String) propertyInfo.get(JahiaOAuthConstants.PROPERTY_VALUE));
                GregorianCalendar c = new GregorianCalendar();
                c.setTimeInMillis(date.getMillis());
                userNode.setProperty(entry.getKey(), ISO8601.format(c));
            } else {
                userNode.setProperty(entry.getKey(),
                        (String) propertyInfo.get(JahiaOAuthConstants.PROPERTY_VALUE));
            }//from  ww w .ja v  a2 s  .c o m
        }
    }
}

From source file:org.jala.efeeder.foodmeeting.EditFoodMeetingCommand.java

@Override
public Out execute(In parameters) throws Exception {
    Out out = new DefaultOut();

    FoodMeetingManager meetingManager = new FoodMeetingManager(parameters.getConnection());
    FoodMeeting meeting = meetingManager
            .getFoodMeetingById(Integer.valueOf(parameters.getParameter("id-food-meeting")));

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMMM, yyyy HH:mm");
    DateTime dateTime = formatter
            .parseDateTime(parameters.getParameter("date") + " " + parameters.getParameter("time"));
    Timestamp eventDate = new Timestamp(dateTime.getMillis());
    Timestamp votingDate = new Timestamp(Long.parseLong(parameters.getParameter("voting-date")));
    Timestamp orderDate = new Timestamp(Long.parseLong(parameters.getParameter("order-date")));
    Timestamp paymentDate = new Timestamp(Long.parseLong(parameters.getParameter("payment-date")));

    meeting.setName(parameters.getParameter("meeting_name"));
    meeting.setImageLink(parameters.getParameter("image_link"));
    meeting.setEventDate(eventDate);//from w  ww  .java 2 s  . c  o  m
    meeting.setVotingDate(votingDate);
    meeting.setOrderDate(orderDate);
    meeting.setPaymentDate(paymentDate);

    try {
        meetingManager.updateFoodMeeting(meeting);
    } catch (SQLException ex) {
        logger.error("Error when updating meeting with id: " + meeting.getId(), ex);
    }

    return out.redirect("/action/FoodMeeting");
}

From source file:org.jasig.portlet.calendar.util.DateUtil.java

License:Apache License

public static Interval getInterval(String startDate, int days, PortletRequest request) throws ParseException {
    final PortletSession session = request.getPortletSession();
    final String timezone = (String) session.getAttribute("timezone");
    final DateTimeZone tz = DateTimeZone.forID(timezone);
    final DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern("MMddyyyy").toFormatter()
            .withZone(tz);/*from  ww w .  j a v  a 2s  .  c om*/
    final DateMidnight start = new DateMidnight(df.parseDateTime(startDate), tz);

    return getInterval(start, days);
}

From source file:org.jasig.portlet.conference.program.dao.ConferenceSessionDao.java

License:Apache License

@Scheduled(fixedRate = 900000)
protected void retrieveProgram() {
    log.debug("Requesting program data from " + this.programUrl);
    final ConferenceProgram program = restTemplate.getForObject(programUrl, ConferenceProgram.class,
            Collections.<String, String>emptyMap());

    if (program != null) {
        cache.put(new Element(PROGRAM_CACHE_KEY, program));

        final List<String> tracks = new ArrayList<String>();
        final List<String> types = new ArrayList<String>();
        final List<String> levels = new ArrayList<String>();
        final List<DateMidnight> dates = new ArrayList<DateMidnight>();

        final DateTimeFormatter providedDF = new DateTimeFormatterBuilder().appendPattern("dd-MMM-yyyy")
                .toFormatter();/*  w  w w.  j  a va 2  s  . c  o  m*/
        final DateTimeFormatter displayDF = new DateTimeFormatterBuilder().appendPattern("EEE MMMM d")
                .toFormatter();
        for (final ConferenceSession session : getProgram().getSessions()) {
            final String track = session.getTrack();
            if (shouldAddToList(track, tracks)) {
                tracks.add(track);
            }

            final String type = session.getType();
            if (shouldAddToList(type, types)) {
                types.add(type);
            }

            final String level = session.getLevel();
            if (shouldAddToList(level, levels)) {
                levels.add(level);
            }

            final String value = session.getDate();
            final DateMidnight date = providedDF.parseDateTime(value).toDateMidnight();
            if (!dates.contains(date)) {
                dates.add(date);
            }

        }
        Collections.sort(tracks);
        Collections.sort(levels);
        Collections.sort(types);

        Collections.sort(dates);
        LinkedHashMap<String, String> dateMap = new LinkedHashMap<String, String>();
        for (DateMidnight date : dates) {
            dateMap.put(providedDF.print(date), displayDF.print(date));
        }

        cache.put(new Element(PROGRAM_CACHE_KEY, program));
        cache.put(new Element(TRACK_LIST_KEY, tracks));
        cache.put(new Element(LEVEL_LIST_KEY, levels));
        cache.put(new Element(TYPE_LIST_KEY, types));
        cache.put(new Element(DATE_MAP_KEY, dateMap));

    }

}

From source file:org.jenkinsci.plugins.registry.notification.webhook.dockerregistry.DockerRegistryWebHookPayload.java

License:Open Source License

private DockerRegistryPushNotification createPushNotification(@Nonnull final String repoName,
        @Nonnull final JSONObject data) {
    return new DockerRegistryPushNotification(this, repoName) {
        {/*from  ww w .  jav a  2  s  . c o m*/
            DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
            String timestamp = data.optString("timestamp");
            setPushedAt(parser.parseDateTime(timestamp).toDate());
            setRegistryHost(data.getJSONObject("request").optString("host"));
        }
    };
}

From source file:org.jevis.commons.dataprocessing.Options.java

License:Open Source License

/**
 * Returns an list of intervals/*from w w w.j a  v a 2  s  .c o m*/
 *
 * @param task
 * @param from
 * @param until
 * @return
 */
public static List<Interval> getIntervals(Task task, DateTime from, DateTime until) {
    Period period = Period.days(1);
    DateTime offset = new DateTime(2001, 01, 01, 00, 00, 00);

    if (!task.getOptions().containsKey(PERIOD)) {
        System.out.println("Error missing period option");
    }
    if (!task.getOptions().containsKey(OFFSET)) {
        System.out.println("Error missing offset option");
        task.getOptions().put(OFFSET, "2001-01-01 00:00:00");
    }

    for (Map.Entry<String, String> entry : task.getOptions().entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        System.out.println("key: " + key);
        switch (key) {
        case PERIOD:
            System.out.println("period string: " + value);
            period = Period.parse(value);
            System.out.println("pared period: " + period);
            break;
        case OFFSET:
            //TODO check value formate
            DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
            offset = dtf.parseDateTime(value);
            break;
        }
    }

    return buildIntervals(period, offset, from, until);

}

From source file:org.jevis.commons.dataprocessing.ProcessOptions.java

License:Open Source License

/**
 * Returns an list of intervals/*  w  w  w. j a v  a  2  s . co  m*/
 *
 * @param task
 * @param from
 * @param until
 * @return
 */
public static List<Interval> getIntervals(Process task, DateTime from, DateTime until) {
    Period period = Period.days(1);
    DateTime offset = new DateTime(2001, 01, 01, 00, 00, 00);

    if (ContainsOption(task, PERIOD)) {
        System.out.println("Error missing period option");
    }
    if (ContainsOption(task, OFFSET)) {
        System.out.println("Error missing offset option");
        task.getOptions().add(new BasicProcessOption(OFFSET, "2001-01-01 00:00:00"));
    }

    for (ProcessOption option : task.getOptions()) {
        String key = option.getKey();
        String value = option.getValue();
        System.out.println("key: " + key);
        switch (key) {
        case PERIOD:
            System.out.println("period string: " + value);
            period = Period.parse(value);
            System.out.println("pared period: " + period);
            break;
        case OFFSET:
            //TODO check value formate
            DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
            offset = dtf.parseDateTime(value);
            break;
        }
    }

    return buildIntervals(period, offset, from, until);

}

From source file:org.jevis.commons.driver.DataSourceHelper.java

License:Open Source License

private static DateTime getFileTime(String name, String[] pathStream) {
    String compactDateString = getCompactDateString(name, pathStream);
    String compactDataFormatString = getCompactDateFormatString(name, pathStream);
    DateTimeFormatter dtf = DateTimeFormat.forPattern(compactDataFormatString);
    DateTime parseDateTime = dtf.parseDateTime(compactDateString);
    return parseDateTime;
}

From source file:org.jevis.commons.driver.DataSourceHelper.java

License:Open Source License

private static DateTime getFolderTime(String name, String[] pathStream) {
    String compactDateString = getCompactDateString(name, pathStream);
    String compactDataFormatString = getCompactDateFormatString(name, pathStream);

    DateTimeFormatter dtf = DateTimeFormat.forPattern(compactDataFormatString);

    DateTime parseDateTime = dtf.parseDateTime(compactDateString);
    if (parseDateTime.year().get() == parseDateTime.year().getMinimumValue()) {
        parseDateTime = parseDateTime.year().withMaximumValue();
    }/*from   w w w .ja va 2  s  .co m*/
    if (parseDateTime.monthOfYear().get() == parseDateTime.monthOfYear().getMinimumValue()) {
        parseDateTime = parseDateTime.monthOfYear().withMaximumValue();
    }
    if (parseDateTime.dayOfMonth().get() == parseDateTime.dayOfMonth().getMinimumValue()) {
        parseDateTime = parseDateTime.dayOfMonth().withMaximumValue();
    }
    if (parseDateTime.hourOfDay().get() == parseDateTime.hourOfDay().getMinimumValue()) {
        parseDateTime = parseDateTime.hourOfDay().withMaximumValue();
    }
    if (parseDateTime.minuteOfHour().get() == parseDateTime.minuteOfHour().getMinimumValue()) {
        parseDateTime = parseDateTime.minuteOfHour().withMaximumValue();
    }
    if (parseDateTime.secondOfMinute().get() == parseDateTime.secondOfMinute().getMinimumValue()) {
        parseDateTime = parseDateTime.secondOfMinute().withMaximumValue();
    }
    if (parseDateTime.millisOfSecond().get() == parseDateTime.millisOfSecond().getMinimumValue()) {
        parseDateTime = parseDateTime.millisOfSecond().withMaximumValue();
    }
    return parseDateTime;
}