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

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

Introduction

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

Prototype

public DateTimeZone getZone() 

Source Link

Document

Gets the zone to use as an override.

Usage

From source file:org.logstash.filters.parser.JodaParser.java

License:Apache License

private Instant parseAndGuessYear(DateTimeFormatter parser, String value) {
    // if we get here, we need to do some special handling at the time each event is handled
    // because things like the current year could be different, etc.
    DateTime dateTime;/*from  w  w w. ja v  a  2s  .  com*/
    if (hasZone) {
        dateTime = parser.parseDateTime(value);
    } else {
        dateTime = parser.withZoneUTC().parseLocalDateTime(value).toDateTime(parser.getZone());
    }

    // The time format we have has no year listed, so we'll have to guess the year.
    int month = dateTime.getMonthOfYear();
    DateTime now = clock.read();
    int eventYear;

    if (month == 12 && now.getMonthOfYear() == 1) {
        // Now is January, event is December. Assume it's from last year.
        eventYear = now.getYear() - 1;
    } else if (month == 1 && now.getMonthOfYear() == 12) {
        // Now is December, event is January. Assume it's from next year.
        eventYear = now.getYear() + 1;
    } else {
        // Otherwise, assume it's from this year.
        eventYear = now.getYear();
    }

    return dateTime.withYear(eventYear).toInstant();
}