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:com.dataartisans.timeoutmonitoring.session.LatencyWindowFunction.java

License:Apache License

@Override
public JSONObject apply(JSONObject left, JSONObject right) {

    JSONObject result = JSONObjectExtractor.createJSONObject(left, resultFields);

    String firstTimestamp = left.getString("timestamp");
    String lastTimestamp = right.getString("timestamp");

    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
    DateTime firstDateTime = formatter.parseDateTime(firstTimestamp);
    DateTime lastDateTime = formatter.parseDateTime(lastTimestamp);

    Duration diff = new Duration(firstDateTime, lastDateTime);

    result.put("latency", diff.getMillis() + "");

    return result;
}

From source file:com.davis.bluefolder.BlueUtils.java

public static String contructDatesForSearch(String start, String end) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("MM-dd-yyyy hh:mma");
    DateTimeZone timeZone = DateTimeZone.forID("America/New_York"); // Specify or else the JVM's default will apply.
    DateTime dateTime = new DateTime(new java.util.Date(), timeZone); // Today's Date
    DateTime pastDate = dateTime.minusDays(14); // 2 weeks ago

    String endDate = null;//from  w w w  . j av a 2s .  co m
    String startDate = null;
    if (start != null && !start.trim().equalsIgnoreCase("")) {
        if (end != null && !end.trim().equalsIgnoreCase("")) {
            startDate = fmt.parseDateTime(start).toString();
            endDate = fmt.parseDateTime(end).toString();
        } else {
            endDate = fmt.print(dateTime);
            startDate = fmt.print(pastDate);
        }
    } else {
        endDate = fmt.print(dateTime);
        startDate = fmt.print(pastDate);
    }

    //dateTimeClosed
    String date = " <dateRange dateField=\"dateTimeCreated\">" + "<startDate>" + startDate + "</startDate>"
            + "<endDate>" + endDate + "</endDate>" + "</dateRange>";

    return date;

}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/** 
 * Parses the to zone calendar.//from  w w  w  .java  2s  .  c om
 * @param timestamp the timestamp
 * @param pattern the pattern
 * @param timeZone the time zone
 * @return the calendar
 */
public static Calendar parseToZoneCalendar(String timestamp, String pattern, String timeZone) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    fmt = fmt.withZoneUTC();
    DateTime dt = fmt.parseDateTime(timestamp);
    dt = dt.toDateTime(DateTimeZone.forID(timeZone));
    return dt.toCalendar(Locale.ENGLISH);
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Format./* w  w  w .  j a  v a 2 s. com*/
 * @param timestamp the timestamp
 * @param pattern the pattern
 * @return the string
 */
public static Calendar parseToCalendar(String timestamp, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    DateTime dt = fmt.parseDateTime(timestamp);
    return dt.toCalendar(Locale.ENGLISH);
}

From source file:com.enitalk.configs.DateCache.java

@Bean(name = "skipCache")
public LoadingCache<String, ConcurrentSkipListSet<DateTime>> datesMap() {
    CacheBuilder<Object, Object> ccc = CacheBuilder.newBuilder();
    ccc.expireAfterWrite(2, TimeUnit.MINUTES);

    LoadingCache<String, ConcurrentSkipListSet<DateTime>> cache = ccc
            .build(new CacheLoader<String, ConcurrentSkipListSet<DateTime>>() {

                @Override//from   www  .ja  va  2s .  c o m
                public ConcurrentSkipListSet<DateTime> load(String key) throws Exception {
                    try {
                        HashMap teachers = mongo.findOne(Query.query(Criteria.where("i").is(key)),
                                HashMap.class, "teachers");
                        ObjectNode teacherJson = jackson.convertValue(teachers, ObjectNode.class);
                        String timeZone = teacherJson.at("/calendar/timeZone").asText();

                        NavigableSet<DateTime> set = days(teacherJson.path("schedule"), timeZone, teacherJson);

                        DateTimeZone dzz = DateTimeZone.forID(timeZone);
                        DateTimeFormatter df = ISODateTimeFormat.dateTimeNoMillis().withZone(dzz);

                        byte[] events = calendar.busyEvents(jackson.createObjectNode().put("id", key));
                        JsonNode evs = jackson.readTree(events);
                        Iterator<JsonNode> its = evs.iterator();
                        TreeSet<DateTime> dates = new TreeSet<>();
                        while (its.hasNext()) {
                            String date = its.next().asText();
                            DateTime av = df.parseDateTime(date).toDateTime(DateTimeZone.UTC);
                            dates.add(av);
                        }

                        set.removeAll(dates);

                        logger.info("Dates for i {} {}", key, set);

                        return new ConcurrentSkipListSet<>(set);

                    } catch (Exception e) {
                        logger.error(ExceptionUtils.getFullStackTrace(e));
                    }
                    return null;
                }

            });

    return cache;
}

From source file:com.enitalk.configs.DateCache.java

public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) {
    ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>();

    Iterator<JsonNode> els = tree.elements();
    DateTimeZone dz = DateTimeZone.forID(tz);
    DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz);

    DateTime today = DateTime.now().millisOfDay().setCopy(0);
    while (els.hasNext()) {

        JsonNode el = els.next();/* w w w  .j  a v a  2s .co  m*/
        String day = el.path("day").asText();

        boolean plus = today.getDayOfWeek() > days.get(day);
        if (el.has("start") && el.has("end")) {
            DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
            DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);

            Hours hours = Hours.hoursBetween(start, end);
            int hh = hours.getHours() + 1;

            while (hh-- > 0) {
                dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC));
            }
        } else {
            List<String> datesAv = jackson.convertValue(el.path("times"), List.class);
            logger.info("Array of dates {} {}", datesAv, day);

            datesAv.forEach((String dd) -> {
                DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear()
                        .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear())
                        .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
                dates.add(date.toDateTime(DateTimeZone.UTC));
            });

        }

    }

    final TreeSet<DateTime> addWeek = new TreeSet<>();
    for (int i = 1; i < 2; i++) {
        for (DateTime e : dates) {
            addWeek.add(e.plusWeeks(i));

        }
    }

    dates.addAll(addWeek);

    DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC);
    nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2));

    NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true);

    return ss;

}

From source file:com.enonic.cms.business.core.content.ContentParser.java

License:Open Source License

private Date parseDate(String dateString) {
    if (dateString == null || dateString.trim().length() == 0) {
        return null;
    }//from   w  w  w .  ja v  a2  s .co  m
    DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_PATTERN);
    DateTime date = fmt.parseDateTime(dateString);
    return date.toDate();
}

From source file:com.enonic.cms.core.content.imports.ImportValueFormater.java

License:Open Source License

public static Date getDate(final AbstractSourceValue value, final String format) throws ImportException {
    String strValue = getStringValue(value);
    if (StringUtils.isEmpty(strValue)) {
        return null;
    }//from  w  ww . ja va  2s  . c o m

    String pattern = "yyyy-MM-dd";
    try {
        if (StringUtils.isNotEmpty(format)) {
            pattern = format;
        }
        final DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);
        return formatter.parseDateTime(strValue).toDate();
    } catch (IllegalArgumentException ex) {
        try {
            return new SimpleDateFormat(pattern, Locale.ENGLISH).parse(strValue);
        } catch (ParseException e) {
            throw new ImportException(
                    "Failed to parse date from value '" + strValue + "', using pattern: " + pattern, ex);
        }
    }
}

From source file:com.enonic.cms.core.search.query.IndexValueConverter.java

License:Open Source License

private static DateTime toDateTime(String value, DateTimeFormatter format) {
    try {/*w  w w.  j av  a2  s.  c o m*/
        return format.parseDateTime(value);
    } catch (IllegalArgumentException e) {
        return null;
    }
}

From source file:com.enonic.cms.core.user.field.UserFieldHelper.java

License:Open Source License

private Date parseDate(String value, DateTimeFormatter format) {
    try {/*from w  ww .  ja v a 2  s .c o  m*/
        return format.parseDateTime(value).toDate();
    } catch (Exception e) {
        return null;
    }
}