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

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

Introduction

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

Prototype

public void saveField(DateTimeFieldType fieldType, int value) 

Source Link

Document

Saves a datetime field value.

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  ww  .  j  av a  2 s.c  o  m*/
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

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