private DateInterval toDayIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTime from = dateTimeUnit.toJodaDateTime( chronology ); if ( offset > 0 ) { from = from.plusDays( offset ); } else if ( offset < 0 ) { from = from.minusDays( -offset ); } DateTime to = new DateTime( from ).plusDays( length ); DateTimeUnit fromDateTimeUnit = DateTimeUnit.fromJodaDateTime( from ); DateTimeUnit toDateTimeUnit = DateTimeUnit.fromJodaDateTime( to ); fromDateTimeUnit.setDayOfWeek( isoWeekday( fromDateTimeUnit ) ); toDateTimeUnit.setDayOfWeek( isoWeekday( toDateTimeUnit ) ); return new DateInterval( toIso( fromDateTimeUnit ), toIso( toDateTimeUnit ), DateIntervalType.ISO8601_DAY ); }
/** * @param dateInterval DateInterval to create period from * @return the period. */ public Period createPeriod( DateInterval dateInterval ) { if ( dateInterval == null || dateInterval.getFrom() == null || dateInterval.getTo() == null ) { return null; } org.hisp.dhis.calendar.Calendar cal = getCalendar(); final DateTimeUnit from = cal.toIso( dateInterval.getFrom() ); final DateTimeUnit to = cal.toIso( dateInterval.getTo() ); return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( from ) ); }
private DateInterval toDayIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset > 0 ) { from = plusDays( from, offset ); } else if ( offset < 0 ) { from = minusDays( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusDays( to, length ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_DAY ); }
/** * Generates weekly Periods for the whole year in which the given Period's * startDate exists. */ @Override public List<Period> generatePeriods( DateTimeUnit start ) { Calendar calendar = getCalendar(); List<Period> periods = new ArrayList<>(); start = new DateTimeUnit( start ); // create clone so we don't modify the original start DT start.setMonth( 1 ); start.setDay( 4 ); start = adjustToStartOfWeek( start, calendar ); for ( int i = 0; i < calendar.weeksInYear( start.getYear() ); i++ ) { DateInterval interval = calendar.toInterval( start, DateIntervalType.ISO8601_WEEK ); periods.add( new Period( this, interval.getFrom().toJdkDate(), interval.getTo().toJdkDate() ) ); start = calendar.plusWeeks( start, 1 ); } return periods; }
private DateInterval toMonthIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTime from = dateTimeUnit.toJodaDateTime( chronology ); if ( offset > 0 ) { from = from.plusMonths( offset ); } else if ( offset < 0 ) { from = from.minusMonths( -offset ); } DateTime to = new DateTime( from ).plusMonths( length ).minusDays( 1 ); DateTimeUnit fromDateTimeUnit = DateTimeUnit.fromJodaDateTime( from ); DateTimeUnit toDateTimeUnit = DateTimeUnit.fromJodaDateTime( to ); fromDateTimeUnit.setDayOfWeek( isoWeekday( fromDateTimeUnit ) ); toDateTimeUnit.setDayOfWeek( isoWeekday( toDateTimeUnit ) ); return new DateInterval( toIso( fromDateTimeUnit ), toIso( toDateTimeUnit ), DateIntervalType.ISO8601_MONTH ); }
private DateInterval toWeekIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTime from = dateTimeUnit.toJodaDateTime( chronology ); if ( offset > 0 ) { from = from.plusWeeks( offset ); } else if ( offset < 0 ) { from = from.minusWeeks( -offset ); } DateTime to = new DateTime( from ).plusWeeks( length ).minusDays( 1 ); DateTimeUnit fromDateTimeUnit = DateTimeUnit.fromJodaDateTime( from ); DateTimeUnit toDateTimeUnit = DateTimeUnit.fromJodaDateTime( to ); fromDateTimeUnit.setDayOfWeek( isoWeekday( fromDateTimeUnit ) ); toDateTimeUnit.setDayOfWeek( isoWeekday( toDateTimeUnit ) ); return new DateInterval( toIso( fromDateTimeUnit ), toIso( toDateTimeUnit ), DateIntervalType.ISO8601_WEEK ); }
private DateInterval toYearIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTime from = dateTimeUnit.toJodaDateTime( chronology ); if ( offset > 0 ) { from = from.plusYears( offset ); } else if ( offset < 0 ) { from = from.minusYears( -offset ); } DateTime to = new DateTime( from ).plusYears( length ).minusDays( 1 ); DateTimeUnit fromDateTimeUnit = DateTimeUnit.fromJodaDateTime( from ); DateTimeUnit toDateTimeUnit = DateTimeUnit.fromJodaDateTime( to ); fromDateTimeUnit.setDayOfWeek( isoWeekday( fromDateTimeUnit ) ); toDateTimeUnit.setDayOfWeek( isoWeekday( toDateTimeUnit ) ); return new DateInterval( toIso( fromDateTimeUnit ), toIso( toDateTimeUnit ), DateIntervalType.ISO8601_YEAR ); }
private DateInterval toDayIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset >= 0 ) { from = plusDays( from, offset ); } else if ( offset < 0 ) { from = minusDays( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusDays( to, length ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_DAY ); }
private DateInterval toMonthIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset > 0 ) { from = plusMonths( from, offset ); } else if ( offset < 0 ) { from = minusMonths( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusMonths( to, length ); to = minusDays( to, 1 ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_MONTH ); }
private DateInterval toYearIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset > 0 ) { from = plusYears( from, offset ); } else if ( offset < 0 ) { from = minusYears( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusYears( to, length ); to = minusDays( to, length ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_YEAR ); }
private DateInterval toMonthIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset > 0 ) { from = plusMonths( from, offset ); } else if ( offset < 0 ) { from = minusMonths( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusMonths( to, length ); to = minusDays( to, 1 ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_MONTH ); }
private DateInterval toYearIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset > 0 ) { from = plusYears( from, offset ); } else if ( offset < 0 ) { from = minusYears( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusYears( to, length ); to = minusDays( to, length ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_YEAR ); }
private DateInterval toWeekIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset > 0 ) { from = plusWeeks( from, offset ); } else if ( offset < 0 ) { from = minusWeeks( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusWeeks( to, length ); to = minusDays( to, 1 ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_WEEK ); }
private DateInterval toWeekIsoInterval( DateTimeUnit dateTimeUnit, int offset, int length ) { DateTimeUnit from = new DateTimeUnit( dateTimeUnit ); if ( offset > 0 ) { from = plusWeeks( from, offset ); } else if ( offset < 0 ) { from = minusWeeks( from, -offset ); } DateTimeUnit to = new DateTimeUnit( from ); to = plusWeeks( to, length ); to = minusDays( to, 1 ); from = toIso( from ); to = toIso( to ); return new DateInterval( from, to, DateIntervalType.ISO8601_WEEK ); }
return new DateInterval( dateTimeUnit, dateTimeUnit ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end ); return new DateInterval( start, end );