Example usage for org.joda.time DateMidnight monthOfYear

List of usage examples for org.joda.time DateMidnight monthOfYear

Introduction

In this page you can find the example usage for org.joda.time DateMidnight monthOfYear.

Prototype

public Property monthOfYear() 

Source Link

Document

Get the month of year property which provides access to advanced functionality.

Usage

From source file:org.filteredpush.qc.date.DateUtils.java

License:Apache License

/**
 * Identify whether an event date and a year, month, and day are consistent, where consistent 
 * means that either the eventDate is a single day and the year-month-day represent the same day
 * or that eventDate is a date range that defines the same date range as year-month (where day is 
 * null) or the same date range as year (where day and month are null).  If all of eventDate, 
 * year, month, and day are null or empty, then returns true.  If eventDate specifies an interval
 * of more than one day and day is specified, then result is true if the day is the first day of the 
 * interval.  If eventDate is not null and year, month, and day are, then result is false (data is 
 * not consistent with no data).//from w w w .ja  va  2 s  . c  o  m
 * 
 * Provides: EVENTDATE_CONSISTENT_WITH_DAY_MONTH_YEAR 
 * 
 * @param eventDate dwc:eventDate
 * @param year dwc:year
 * @param month dwc:month
 * @param day dwc:day
 * 
 * @return true if eventDate is consistent with year-month-day.
 */
public static boolean isConsistent(String eventDate, String year, String month, String day) {
    boolean result = false;
    StringBuffer date = new StringBuffer();
    if (!isEmpty(eventDate)) {
        if (!isEmpty(year) && !isEmpty(month) && !isEmpty(day)) {
            date.append(year).append("-").append(month).append("-").append(day);
            if (!isRange(eventDate)) {
                DateMidnight eventDateDate = extractDate(eventDate);
                DateMidnight bitsDate = extractDate(date.toString());
                if (eventDateDate != null && bitsDate != null) {
                    if (eventDateDate.year().compareTo(bitsDate) == 0
                            && eventDateDate.monthOfYear().compareTo(bitsDate) == 0
                            && eventDateDate.dayOfMonth().compareTo(bitsDate) == 0) {
                        result = true;
                    }
                }
            } else {
                Interval eventDateDate = extractDateInterval(eventDate);
                DateMidnight bitsDate = extractDate(date.toString());
                if (eventDateDate != null && bitsDate != null) {
                    if (eventDateDate.getStart().year().compareTo(bitsDate) == 0
                            && eventDateDate.getStart().monthOfYear().compareTo(bitsDate) == 0
                            && eventDateDate.getStart().dayOfMonth().compareTo(bitsDate) == 0) {
                        result = true;
                    }
                }

            }
        }
        if (!isEmpty(year) && !isEmpty(month) && isEmpty(day)) {
            date.append(year).append("-").append(month);
            Interval eventDateInterval = extractDateInterval(eventDate);
            Interval bitsInterval = extractDateInterval(date.toString());
            if (eventDateInterval.equals(bitsInterval)) {
                result = true;
            }
        }
        if (!isEmpty(year) && isEmpty(month) && isEmpty(day)) {
            date.append(year);
            Interval eventDateInterval = extractDateInterval(eventDate);
            Interval bitsInterval = extractDateInterval(date.toString());
            if (eventDateInterval.equals(bitsInterval)) {
                result = true;
            }
        }
    } else {
        if (isEmpty(year) && isEmpty(month) && isEmpty(day)) {
            // eventDate, year, month, and day are all empty, treat as consistent.
            result = true;
        }
    }
    return result;
}