Search in sources :

Example 6 with DateTimeUnit

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);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit)

Example 7 with DateTimeUnit

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;
}
Also used : RelativePeriods(org.hisp.dhis.period.RelativePeriods) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) Report(org.hisp.dhis.report.Report) Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) ReportTable(org.hisp.dhis.reporttable.ReportTable) Period(org.hisp.dhis.period.Period) CalendarPeriodType(org.hisp.dhis.period.CalendarPeriodType) PastAndCurrentPeriodFilter(org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter) Date(java.util.Date)

Example 8 with DateTimeUnit

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;
}
Also used : Calendar(org.hisp.dhis.calendar.Calendar) DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) Date(java.util.Date)

Example 9 with DateTimeUnit

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);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DateTime(org.joda.time.DateTime)

Example 10 with DateTimeUnit

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);
}
Also used : DateTimeUnit(org.hisp.dhis.calendar.DateTimeUnit) DateTime(org.joda.time.DateTime)

Aggregations

DateTimeUnit (org.hisp.dhis.calendar.DateTimeUnit)98 Calendar (org.hisp.dhis.calendar.Calendar)23 Test (org.junit.jupiter.api.Test)17 Date (java.util.Date)15 DateInterval (org.hisp.dhis.calendar.DateInterval)10 Period (org.hisp.dhis.period.Period)6 DateTime (org.joda.time.DateTime)5 LocalDate (java.time.LocalDate)4 DimensionalObject (org.hisp.dhis.common.DimensionalObject)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 ArrayList (java.util.ArrayList)3 WeekFields (java.time.temporal.WeekFields)2 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 InvalidCalendarParametersException (org.hisp.dhis.calendar.exception.InvalidCalendarParametersException)2 DataDimensionalItemObject (org.hisp.dhis.common.DataDimensionalItemObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)2 DateUtils.getMediumDateString (org.hisp.dhis.util.DateUtils.getMediumDateString)2