List of usage examples for org.joda.time DateMidnight dayOfMonth
public Property dayOfMonth()
From source file:com.billing.ng.entities.BillingCycle.java
License:Open Source License
/** * The initial starting instant of the entire billing cycle. The start instant is * the first instance of the cycle start day after (or equal to) the cycle start date. * * @return starting instant of this billing cycle */// www . j av a2s. co m public DateMidnight getStartInstant() { DateMidnight start = new DateMidnight(getStart()); Period period = getBillingPeriod().getPeriodOfTime(); // first possible start date for a period DateMidnight calculated = getCycleStartDay() != LAST_DAY_OF_MONTH ? start.dayOfMonth().setCopy(getCycleStartDay()) : start.dayOfMonth().withMaximumValue(); // increment by billing period interval until a valid start date is found while (calculated.isBefore(start)) { calculated = calculated.plus(period); } return calculated; }
From source file:com.latlab.common.model.PeriodUtils.java
/** * Obtains a Map of {@link YearQuarterDate} for all the quarters of the * specified year. If <code>year</code> value is 0 or less, it is assumed * that the year is the current year.// w ww .ja va 2s . c o m * * @param year * @return */ public static Map<Period, DateRange> getQuarterDates(int year) { Map<Period, DateRange> quarterMap = new HashMap<>(); DateMidnight refDate = new DateMidnight(); if (year > 0) { refDate = refDate.withYear(year); } refDate = refDate.withMonthOfYear(1).withDayOfMonth(1); Date startDate1 = refDate.toDate(); refDate = refDate.plusMonths(2); refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue()); Date endDate1 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59) .withSecondOfMinute(59).toDate(); DateRange quarterDate = new DateRange(Period.FIRST_QUARTER, year, startDate1, endDate1); quarterMap.put(quarterDate.getPeriod(), quarterDate); refDate = refDate.withMonthOfYear(4).withDayOfMonth(1); Date starteDate2 = refDate.toDate(); refDate = refDate.plusMonths(2); refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue()); Date endDate2 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59) .withSecondOfMinute(59).toDate(); DateRange quarterDate2 = new DateRange(Period.SECOND_QUARTER, year, starteDate2, endDate2); quarterMap.put(quarterDate2.getPeriod(), quarterDate2); refDate = refDate.withMonthOfYear(7).withDayOfMonth(1); Date starteDate3 = refDate.toDate(); refDate = refDate.plusMonths(2); refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue()); Date endDate3 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59) .withSecondOfMinute(59).toDate(); DateRange quarterDate3 = new DateRange(Period.THIRD_QUARTER, year, starteDate3, endDate3); quarterMap.put(quarterDate3.getPeriod(), quarterDate3); refDate = refDate.withMonthOfYear(10).withDayOfMonth(1); Date starteDate4 = refDate.toDate(); refDate = refDate.plusMonths(2); refDate = refDate.withDayOfMonth(refDate.dayOfMonth().getMaximumValue()); Date endDate4 = new DateTime(refDate.toDateTime()).withHourOfDay(23).withMinuteOfHour(59) .withSecondOfMinute(59).toDate(); DateRange quarterDate4 = new DateRange(Period.LAST_QUARTER, refDate.getYear(), starteDate4, endDate4); quarterMap.put(quarterDate4.getPeriod(), quarterDate4); return quarterMap; }
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)./* w ww . j a v a2 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; }