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:ch.icclab.cyclops.util.Time.java

License:Open Source License

public static Long fromNovaTimeToMills(String time) {
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS").withZoneUTC();
    DateTime date = format.parseDateTime(time);

    return date.getMillis();
}

From source file:ch.icclab.cyclops.util.Time.java

License:Open Source License

public static Long fromOpenstackTimeToMills(String time) {
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd' 'HH:mm:ss.SSSSSS").withZoneUTC();
    DateTime date = format.parseDateTime(time);

    return date.getMillis();
}

From source file:ch.silviowangler.dox.DoxVersion.java

License:Apache License

public String formatVersion() {

    if (this.version.contains("-")) {

        String[] tokens = this.version.split("-");

        if (tokens.length == 3 && this.version.matches("(\\d\\.?)+-[A-Za-z0-9]+-\\d{14}")) {

            DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss");
            DateTime dateTime = dateTimeFormatter.parseDateTime(tokens[tokens.length - 1]);

            StringBuilder sb = new StringBuilder(tokens[0]);
            sb.append("-").append(tokens[1]).append(" (").append(dateTime.toString("dd.MM.yyyy HH:mm:ss"))
                    .append(")");

            return sb.toString();

        } else if (tokens.length == 2 && tokens[1].matches("\\d{14}")) {

            DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMddHHmmss");

            DateTime dateTime = dateTimeFormatter.parseDateTime(tokens[tokens.length - 1]);

            StringBuilder sb = new StringBuilder(tokens[0]);
            sb.append(" (").append(dateTime.toString("dd.MM.yyyy HH:mm:ss")).append(")");

            return sb.toString();
        }//  w ww .  j ava  2  s .  co m
    }

    if ("@dox.app.version@".equals(this.version)) {
        return "<development mode>";
    }

    return "invalid";
}

From source file:ching.icecreaming.action.ResourceDescriptors.java

License:Open Source License

private boolean searchFilter(String searchField, String searchOper, String searchString, Object object1) {
    boolean result1 = true;
    String string1 = null;/* w w w  .ja  va 2 s .co m*/
    Integer integer1 = null;
    java.sql.Timestamp timestamp1 = null;
    org.joda.time.DateTime dateTime1 = null, dateTime2 = null;
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm");
    java.util.Date date1 = null;

    if (object1 instanceof String) {
        string1 = (String) object1;
        switch (searchOper) {
        case "eq":
            result1 = StringUtils.equals(string1, searchString);
            break;
        case "ne":
            result1 = !StringUtils.equals(string1, searchString);
            break;
        case "bw":
            result1 = StringUtils.startsWith(string1, searchString);
            break;
        case "bn":
            result1 = !StringUtils.startsWith(string1, searchString);
            break;
        case "ew":
            result1 = StringUtils.endsWith(string1, searchString);
            break;
        case "en":
            result1 = !StringUtils.endsWith(string1, searchString);
            break;
        case "cn":
            result1 = StringUtils.contains(string1, searchString);
            break;
        case "nc":
            result1 = !StringUtils.contains(string1, searchString);
            break;
        case "nu":
            result1 = StringUtils.isBlank(string1);
            break;
        case "nn":
            result1 = StringUtils.isNotBlank(string1);
            break;
        case "in":
        case "ni":
        case "lt":
        case "le":
        case "gt":
        case "ge":
        default:
            break;
        }
    } else if (object1 instanceof Integer) {
        if (NumberUtils.isNumber(searchString)) {
            integer1 = (Integer) object1;
            switch (searchOper) {
            case "eq":
                result1 = (NumberUtils.toInt(searchString, 0) == integer1.intValue());
                break;
            case "ne":
                result1 = (NumberUtils.toInt(searchString, 0) != integer1.intValue());
                break;
            case "lt":
                result1 = (NumberUtils.toInt(searchString, 0) > integer1.intValue());
                break;
            case "le":
                result1 = (NumberUtils.toInt(searchString, 0) >= integer1.intValue());
                break;
            case "gt":
                result1 = (NumberUtils.toInt(searchString, 0) < integer1.intValue());
                break;
            case "ge":
                result1 = (NumberUtils.toInt(searchString, 0) <= integer1.intValue());
                break;
            case "bw":
            case "bn":
            case "ew":
            case "en":
            case "cn":
            case "nc":
            case "in":
            case "ni":
            case "nu":
            case "nn":
            default:
                break;
            }
        }
    } else if (object1 instanceof java.sql.Timestamp || object1 instanceof java.util.Date) {
        if (object1 instanceof java.sql.Timestamp) {
            timestamp1 = (java.sql.Timestamp) object1;
            dateTime1 = new org.joda.time.DateTime(timestamp1.getTime());
        } else if (object1 instanceof java.util.Date) {
            date1 = (java.util.Date) object1;
            if (date1 != null)
                dateTime1 = new org.joda.time.DateTime(date1);
        }
        try {
            dateTime2 = dateTimeFormatter.parseDateTime(searchString);
        } catch (java.lang.IllegalArgumentException exception1) {
            dateTime2 = null;
        }
        if (dateTime2 != null && dateTime1 != null) {
            switch (searchOper) {
            case "eq":
                result1 = dateTime1.equals(dateTime2);
                break;
            case "ne":
                result1 = !dateTime1.equals(dateTime2);
                break;
            case "lt":
                result1 = dateTime1.isBefore(dateTime2);
                break;
            case "le":
                result1 = (dateTime1.isBefore(dateTime2) || dateTime1.equals(dateTime2));
                break;
            case "gt":
                result1 = dateTime1.isAfter(dateTime2);
                break;
            case "ge":
                result1 = (dateTime1.isAfter(dateTime2) || dateTime1.equals(dateTime2));
                break;
            case "bw":
            case "bn":
            case "ew":
            case "en":
            case "cn":
            case "nc":
            case "in":
            case "ni":
                break;
            case "nu":
                result1 = (timestamp1 == null);
                break;
            case "nn":
                result1 = (timestamp1 != null);
                break;
            default:
                break;
            }
        }
    }
    return !result1;
}

From source file:co.bluepass.web.rest.ClubResource.java

/**
 * Gets customers by club id.//  www.j  a v a 2 s .  c  o m
 *
 * @param id        the id
 * @param yearMonth the year month
 * @param response  the response
 * @return the customers by club id
 * @throws URISyntaxException the uri syntax exception
 */
@RequestMapping(value = "/clubs/{id}/customers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<User>> getCustomersByClubId(@PathVariable Long id, @RequestParam String yearMonth,
        HttpServletResponse response) throws URISyntaxException {
    log.debug("REST request to get Actions by club id : {}", id);

    List<User> users = new ArrayList<User>();
    List<ReservationHistory> reservationHistories = null;

    if (StringUtils.isNotEmpty(yearMonth)) {
        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyMM");
        DateTime monthStartDate = formatter.parseDateTime(yearMonth);
        DateTime monthEndDate = monthStartDate.dayOfMonth().withMaximumValue();
        monthEndDate = monthEndDate.withTime(23, 59, 59, 59);
        reservationHistories = reservationHistoryRepository.findByClubIdAndUsedAndStartTimeBetween(id, true,
                monthStartDate, monthEndDate);
    } else {
        reservationHistories = reservationHistoryRepository.findByClubIdAndUsed(id, true);
    }

    if (reservationHistories == null || reservationHistories.isEmpty()) {
        return new ResponseEntity<List<User>>(users, HttpStatus.OK);
    }

    Set<Long> userIds = new HashSet<>();
    for (ReservationHistory history : reservationHistories) {
        userIds.add(history.getUserId());
    }

    users = userRepository.findAll(userIds);

    return new ResponseEntity<List<User>>(users, HttpStatus.OK);
}

From source file:colossal.pipe.BaseOptions.java

License:Apache License

private DateTime parseDateTime(String textTime) {
    for (DateTimeFormatter f : timeFormatters) {
        try {//from   www. ja  va2  s. c o m
            return f.parseDateTime(textTime);
        } catch (IllegalArgumentException iae) {
            // skip to next
        }
    }
    throw new IllegalArgumentException("Can't parse: " + textTime);
}

From source file:com.addthis.basis.time.Dates.java

License:Apache License

/**
 * Create an interval from two date strings
 * <p/>/* ww  w  .ja  va 2s. c  om*/
 * begStr | endStr | return
 * -------------------------
 * bad   |  bad   | (now, now)
 * bad   |   E    | (E, E)
 * B    |  bad   | (B, B)
 * B    |   E    | (B, E)
 * B(>E)|   E(<B)| (E, E)
 * <p/>
 * ("bad" in the table above indicates that the input
 * is either null or fails to parse)
 * <p/>
 * TODO: accept default beg/end parameters
 *
 * @param begStr beginning of interval
 * @param endStr end of interval
 * @return
 */
public static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format) {
    DateTime beg = null;
    DateTime end = null;
    boolean begFailed = false;
    boolean endFailed = false;

    try {
        beg = format.parseDateTime(begStr);
    } catch (Exception e) {
        begFailed = true;
    }

    try {
        end = format.parseDateTime(endStr);
    } catch (Exception e) {
        endFailed = true;
    }

    if (begFailed && endFailed) {
        end = beg = new DateTime();
    } else if (begFailed) {
        beg = end;
    } else if (endFailed) {
        end = beg;
    }

    if (beg.isAfter(end)) {
        beg = end;
    }

    return new Interval(beg, end);
}

From source file:com.addthis.hydra.data.filter.value.ValueFilterDateRangeLength.java

License:Apache License

protected Interval parseRange(String rangeString) {
    int sepIndex = rangeString.indexOf(dateSep);
    if (sepIndex <= 0 || sepIndex + 1 == rangeString.length()) {
        throw new IllegalArgumentException("Failed to parse date range: " + rangeString);
    }/*  w w w  . jav  a  2s  . com*/

    DateTimeFormatter dtf = DateTimeFormat.forPattern(dateFormat);
    DateTime beg = dtf.parseDateTime(rangeString.substring(0, sepIndex));
    DateTime end = dtf.parseDateTime(rangeString.substring(sepIndex + 1, rangeString.length()));

    return new Interval(beg, end);
}

From source file:com.addthis.hydra.data.filter.value.ValueFilterDateRangeLength.java

License:Apache License

protected int countDays(String dates) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern(dateFormat);
    String[] datesSplit = toArray(dates);
    SortedSet<DateTime> dateSet = new TreeSet<DateTime>();
    for (String strVal : datesSplit) {
        if (strVal.indexOf(dateSep) < 0) {
            dateSet.add(dtf.parseDateTime(strVal));
        } else {//  w ww  .  jav a2s . c om
            Interval interval = parseRange(strVal);
            for (DateTime dt : Dates.iterableInterval(interval, DTimeUnit.DAY)) {
                dateSet.add(dt);
            }
        }
    }
    return dateSet.size();
}

From source file:com.addthis.hydra.data.util.DateUtil.java

License:Apache License

public static DateTime getDateTime(DateTimeFormatter formatter, String date) {
    if (date.startsWith(NOW_PREFIX) && date.endsWith(NOW_POSTFIX)) {
        if (date.equals(NOW)) {
            return new DateTime();
        }//from  w w  w  . ja  v  a 2 s.  c om
        DateTime time = new DateTime();
        int pos;
        if ((pos = date.indexOf("+")) > 0) {
            time = time
                    .plusDays(Integer.parseInt(date.substring(pos + 1, date.length() - NOW_POSTFIX.length())));
        } else if ((pos = date.indexOf("-")) > 0) {
            time = time
                    .minusDays(Integer.parseInt(date.substring(pos + 1, date.length() - NOW_POSTFIX.length())));
        }
        return time;
    }
    return formatter.parseDateTime(date);
}