/** * @param date the date. */ public Cal( Date date ) { dateTimeUnit = DateTimeUnit.fromJdkDate( date ); }
@Override public DateTimeUnit fromIso( Date date ) { return fromIso( DateTimeUnit.fromJdkDate( date ) ); }
@Override public DateTimeUnit fromIso( Date date ) { return fromIso( DateTimeUnit.fromJdkDate( date ) ); }
@Override public DateTimeUnit fromIso( Date date ) { return fromIso( DateTimeUnit.fromJdkDate( date ) ); }
/** * Sets the current time. * * @param date the date to base time on. */ public Cal set( Date date ) { dateTimeUnit = getCalendar().fromIso( DateTimeUnit.fromJdkDate( date ) ); return this; }
@Override public Date getRewindedDate( Date date, Integer rewindedPeriods ) { Calendar cal = getCalendar(); date = date != null ? date : new Date(); rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1; DateTimeUnit dateTimeUnit = cal.fromIso( DateTimeUnit.fromJdkDate( date ) ); dateTimeUnit = cal.minusMonths( dateTimeUnit, rewindedPeriods ); return cal.toIso( dateTimeUnit ).toJdkDate(); }
@Override public Date getRewindedDate( Date date, Integer rewindedPeriods ) { Calendar cal = getCalendar(); date = date != null ? date : new Date(); rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1; DateTimeUnit dateTimeUnit = cal.fromIso( DateTimeUnit.fromJdkDate( date ) ); dateTimeUnit = cal.minusMonths( dateTimeUnit, rewindedPeriods ); return cal.toIso( dateTimeUnit ).toJdkDate(); } }
/** * Creates a valid Period based on the given date. E.g. the given date is * February 10. 2007, a monthly PeriodType should return February 2007. This * method is intended for use in situations where a huge number of of periods * will be generated and its desirable to re-use the calendar. * * @param date the date which is contained by the created period. * @param calendar the calendar implementation to use. * @return the valid Period based on the given date */ public Period createPeriod( final Date date, final org.hisp.dhis.calendar.Calendar calendar ) { return PERIOD_CACHE.get( getCacheKey( calendar, date ), p -> createPeriod( calendar.fromIso( DateTimeUnit.fromJdkDate( date ) ), calendar ) ); }