use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class QuarterlyPeriodType method createPeriod.
@Override
public Period createPeriod(DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar) {
DateTimeUnit start = new DateTimeUnit(dateTimeUnit);
start.setMonth(((dateTimeUnit.getMonth() - 1) - ((dateTimeUnit.getMonth() - 1) % 3)) + 1);
start.setDay(1);
if (start.getMonth() > 12) {
start.setYear(start.getYear() + 1);
start.setMonth(1);
}
DateTimeUnit end = new DateTimeUnit(start);
end = calendar.plusMonths(end, 2);
end.setDay(calendar.daysInMonth(end.getYear(), end.getMonth()));
return toIsoPeriod(start, end, calendar);
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class GetReportParamsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
if (mode == null || uid == null) {
return SUCCESS;
}
RelativePeriods relatives = null;
if (MODE_REPORT_TABLE.equals(mode)) {
ReportTable reportTable = reportTableService.getReportTable(uid);
if (reportTable != null) {
reportParams = reportTable.getReportParams();
relatives = reportTable.getRelatives();
}
} else if (MODE_REPORT.equals(mode)) {
Report report = reportService.getReport(uid);
if (report != null && report.isTypeReportTable()) {
reportParams = report.getReportTable().getReportParams();
relatives = report.getReportTable().getRelatives();
} else if (report != null && (report.isTypeJdbc() || report.isTypeHtml())) {
reportParams = report.getReportParams();
relatives = report.getRelatives();
}
if (type == null && report != null) {
// Set type based on report
type = report.getType();
}
}
if (reportParams != null && reportParams.isParamReportingMonth() && relatives != null) {
CalendarPeriodType periodType = (CalendarPeriodType) relatives.getPeriodType();
List<Period> periods = periodType.generateLast5Years(new Date());
Collections.reverse(periods);
FilterUtils.filter(periods, new PastAndCurrentPeriodFilter());
Calendar calendar = PeriodType.getCalendar();
for (Period period_ : periods) {
BaseIdentifiableObject period = new BaseIdentifiableObject();
if (calendar.isIso8601()) {
period.setUid(period_.getIsoDate());
period.setDisplayName(format.formatPeriod(period_));
} else {
DateTimeUnit dateTimeUnit = calendar.fromIso(period_.getStartDate());
period.setUid(period_.getPeriodType().getIsoDate(dateTimeUnit));
period.setDisplayName(format.formatPeriod(period_));
}
this.periods.add(period);
}
}
return SUCCESS;
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class PartitionUtils method getEarliestDate.
public static Date getEarliestDate(Integer lastYears) {
Date earliest = null;
if (lastYears != null) {
Calendar calendar = PeriodType.getCalendar();
DateTimeUnit dateTimeUnit = calendar.today();
dateTimeUnit = calendar.minusYears(dateTimeUnit, lastYears - 1);
dateTimeUnit.setMonth(1);
dateTimeUnit.setDay(1);
earliest = dateTimeUnit.toJdkDate();
}
return earliest;
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class PartitionUtils method getPeriod.
public static Period getPeriod(Calendar calendar, Integer year) {
DateTimeUnit startOfYear = calendar.isoStartOfYear(year);
DateTime time = new DateTime(year, startOfYear.getMonth(), startOfYear.getDay(), 1, 1);
return PERIODTYPE.createPeriod(time.toDate(), calendar);
}
use of org.hisp.dhis.calendar.DateTimeUnit in project dhis2-core by dhis2.
the class NepaliCalendar method toIso.
@Override
public DateTimeUnit toIso(DateTimeUnit dateTimeUnit) {
if (dateTimeUnit.isIso8601()) {
return dateTimeUnit;
}
DateTime dateTime = START_ISO.toJodaDateTime();
int totalDays = 0;
for (int year = START_NEPAL.getYear(); year < dateTimeUnit.getYear(); year++) {
totalDays += getYearTotal(year);
}
for (int month = START_NEPAL.getMonth(); month < dateTimeUnit.getMonth(); month++) {
totalDays += CONVERSION_MAP.get(dateTimeUnit.getYear())[month];
}
totalDays += dateTimeUnit.getDay() - START_NEPAL.getDay();
dateTime = dateTime.plusDays(totalDays);
return new DateTimeUnit(DateTimeUnit.fromJodaDateTime(dateTime), true);
}
Aggregations