use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.
the class MonthlyPeriodType method getRewindedDate.
@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();
}
use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.
the class WeeklyAbstractPeriodType method generatePeriods.
/**
* 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 = 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;
}
use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.
the class YearlyPeriodType method getRewindedDate.
@Override
public Date getRewindedDate(Date date, Integer rewindedPeriods) {
Calendar calendar = getCalendar();
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
DateTimeUnit dateTimeUnit = createLocalDateUnitInstance(date);
dateTimeUnit = calendar.minusYears(dateTimeUnit, rewindedPeriods);
return calendar.toIso(dateTimeUnit).toJdkDate();
}
use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.
the class YearlyPeriodType method generateLast5Years.
/**
* Generates the last 5 years where the last one is the year which the given
* date is inside.
*/
@Override
public List<Period> generateLast5Years(Date date) {
Calendar calendar = getCalendar();
DateTimeUnit dateTimeUnit = createLocalDateUnitInstance(date);
dateTimeUnit = calendar.minusYears(dateTimeUnit, 4);
dateTimeUnit.setDay(1);
dateTimeUnit.setMonth(1);
List<Period> periods = Lists.newArrayList();
for (int i = 0; i < 5; ++i) {
periods.add(createPeriod(dateTimeUnit, calendar));
dateTimeUnit = calendar.plusYears(dateTimeUnit, 1);
}
return periods;
}
use of org.hisp.dhis.calendar.Calendar in project dhis2-core by dhis2.
the class AnalyticsUtils method getDimensionItemNameMap.
/**
* Returns a mapping between identifiers and names for the given query.
*
* @param params the data query parameters.
* @return a mapping between identifiers and names.
*/
public static Map<String, String> getDimensionItemNameMap(DataQueryParams params) {
List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
Map<String, String> map = new HashMap<>();
Calendar calendar = PeriodType.getCalendar();
for (DimensionalObject dimension : dimensions) {
for (DimensionalItemObject item : dimension.getItems()) {
if (DimensionType.PERIOD.equals(dimension.getDimensionType()) && !calendar.isIso8601()) {
Period period = (Period) item;
DateTimeUnit dateTimeUnit = calendar.fromIso(period.getStartDate());
map.put(period.getPeriodType().getIsoDate(dateTimeUnit), period.getDisplayName());
} else {
map.put(item.getDimensionItem(), item.getDisplayProperty(params.getDisplayProperty()));
}
if (DimensionType.ORGANISATION_UNIT.equals(dimension.getDimensionType()) && params.isHierarchyMeta()) {
OrganisationUnit unit = (OrganisationUnit) item;
map.putAll(NameableObjectUtils.getUidDisplayPropertyMap(unit.getAncestors(), params.getDisplayProperty()));
}
}
map.put(dimension.getDimension(), dimension.getDisplayProperty(params.getDisplayProperty()));
}
return map;
}
Aggregations