Example usage for org.joda.time.format DateTimeParserBucket DateTimeParserBucket

List of usage examples for org.joda.time.format DateTimeParserBucket DateTimeParserBucket

Introduction

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

Prototype

public DateTimeParserBucket(long instantLocal, Chronology chrono, Locale locale, Integer pivotYear,
        int defaultYear) 

Source Link

Document

Constructs a bucket, with the option of specifying the pivot year for two-digit year parsing.

Usage

From source file:com.spotify.heroic.shell.Tasks.java

License:Apache License

private static long parseTodayInstant(String input, final Chronology chrono, long now) {
    final DateTime n = new DateTime(now, chrono);

    for (final DateTimeParser p : today) {
        final DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, null, null, 2000);

        bucket.saveField(chrono.year(), n.getYear());
        bucket.saveField(chrono.monthOfYear(), n.getMonthOfYear());
        bucket.saveField(chrono.dayOfYear(), n.getDayOfYear());

        try {//from  w  w  w  .  j  a  va  2 s .co m
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

    throw new IllegalArgumentException(input + " is not a valid instant");
}

From source file:com.spotify.heroic.shell.Tasks.java

License:Apache License

private static long parseFullInstant(String input, final Chronology chrono) {
    for (final DateTimeParser p : full) {
        final DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, null, null, 2000);

        try {/*from w w w  . ja  v  a  2  s  .  com*/
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

    throw new IllegalArgumentException(input + " is not a valid instant");
}

From source file:org.renjin.primitives.time.Time.java

License:Open Source License

private static DateTime parseIgnoreTrailingCharacters(DateTimeFormatter formatter, String text) {
    // this is a modified version of DateTimeFormatter.parseDateTime() that does not
    // throw an exception on trailing characters

    Chronology chronology = DateTimeUtils.getChronology(null);
    DateTimeParser parser = formatter.getParser();

    Locale locale = null;//w w w .j  a v  a  2 s  . co m
    Integer pivotYear = null;
    int defaultYear = 2000;
    DateTimeZone timeZone = null;

    DateTimeParserBucket bucket = new DateTimeParserBucket(0, chronology, locale, pivotYear, defaultYear);
    int newPos = parser.parseInto(bucket, text, 0);
    if (newPos >= 0) {
        long millis = bucket.computeMillis(true, text);
        if (formatter.isOffsetParsed() && bucket.getOffsetInteger() != null) {
            int parsedOffset = bucket.getOffsetInteger();
            DateTimeZone parsedZone = DateTimeZone.forOffsetMillis(parsedOffset);
            chronology = chronology.withZone(parsedZone);
        } else if (bucket.getZone() != null) {
            chronology = chronology.withZone(bucket.getZone());
        }
        DateTime dt = new DateTime(millis, chronology);
        if (timeZone != null) {
            dt = dt.withZone(timeZone);
        }
        return dt;
    }
    throw new IllegalArgumentException();
}