Search in sources :

Example 1 with BiWeeklyPeriodType

use of org.hisp.dhis.period.BiWeeklyPeriodType in project dhis2-core by dhis2.

the class DataApprovalWorkflowTest method testGetWorkflowSqlCoEnddateExtension.

/**
 * Note that as part of the following test, we are checking to be sure that
 * the longest extension to the category option end date is returned from
 * data sets that are successively added to the workflow. The total
 * extension length (period length times number of periods) is always
 * increasing as we add data sets to the workflow. The most recently-added
 * data set always has the longest total extension so far.
 */
@Test
void testGetWorkflowSqlCoEnddateExtension() {
    DataSet noPeriodsAfterCoEndDate = createDataSet("noPeriodsAfterCoEndDate", new MonthlyPeriodType(), 0);
    DataSet dailyDs = createDataSet("dailyDs", new DailyPeriodType(), 3);
    DataSet weeklyDs = createDataSet("weeklyDs", new WeeklyPeriodType(), 3);
    DataSet weeklyWedDs = createDataSet("weeklyWedDs", new WeeklyWednesdayPeriodType(), 4);
    DataSet weeklyThuDs = createDataSet("weeklyThuDs", new WeeklyThursdayPeriodType(), 5);
    DataSet weeklySatDs = createDataSet("weeklySatDs", new WeeklySaturdayPeriodType(), 6);
    DataSet weeklySunDs = createDataSet("weeklySunDs", new WeeklySundayPeriodType(), 7);
    DataSet biWeeklyDs = createDataSet("biWeeklyDs", new BiWeeklyPeriodType(), 4);
    DataSet monthlyDs = createDataSet("monthlyDs", new MonthlyPeriodType(), 3);
    DataSet biMonthlyDs = createDataSet("biMonthlyDs", new BiMonthlyPeriodType(), 3);
    DataSet querterlyDs = createDataSet("querterlyDs", new QuarterlyPeriodType(), 3);
    DataSet sixMonthlyDs = createDataSet("sixMonthlyDs", new SixMonthlyPeriodType(), 3);
    DataSet sixMonthlyAprDs = createDataSet("sixMonthlyAprDs", new SixMonthlyAprilPeriodType(), 4);
    DataSet sixMonthlyNovDs = createDataSet("sixMonthlyNovDs", new SixMonthlyNovemberPeriodType(), 5);
    DataSet yearlyDs = createDataSet("yearlyDs", new YearlyPeriodType(), 3);
    DataSet financialAprDs = createDataSet("financialAprDs", new FinancialAprilPeriodType(), 4);
    DataSet financialJulDs = createDataSet("financialJulDs", new FinancialJulyPeriodType(), 5);
    DataSet financialOctDs = createDataSet("financialOctDs", new FinancialOctoberPeriodType(), 6);
    DataSet financialNovDs = createDataSet("financialNovDs", new FinancialNovemberPeriodType(), 7);
    DataSet twoYearlyDs = createDataSet("twoYearlyDs", new TwoYearlyPeriodType(), 4);
    DataApprovalWorkflow workflow = new DataApprovalWorkflow("test workflow", new DailyPeriodType(), newHashSet());
    assertEquals("", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(noPeriodsAfterCoEndDate);
    assertEquals("", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(dailyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 day'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyWedDs);
    assertEquals(" + 4 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklyThuDs);
    assertEquals(" + 5 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklySatDs);
    assertEquals(" + 6 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(weeklySunDs);
    assertEquals(" + 7 * INTERVAL '+ 1 week'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(biWeeklyDs);
    assertEquals(" + 4 * INTERVAL '+ 2 weeks'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(monthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 month'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(biMonthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 2 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(querterlyDs);
    assertEquals(" + 3 * INTERVAL '+ 3 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyDs);
    assertEquals(" + 3 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyAprDs);
    assertEquals(" + 4 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(sixMonthlyNovDs);
    assertEquals(" + 5 * INTERVAL '+ 6 months'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(yearlyDs);
    assertEquals(" + 3 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialAprDs);
    assertEquals(" + 4 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialJulDs);
    assertEquals(" + 5 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialOctDs);
    assertEquals(" + 6 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(financialNovDs);
    assertEquals(" + 7 * INTERVAL '+ 1 year'", workflow.getSqlCoEndDateExtension());
    workflow.getDataSets().add(twoYearlyDs);
    assertEquals(" + 4 * INTERVAL '+ 2 years'", workflow.getSqlCoEndDateExtension());
}
Also used : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) WeeklySaturdayPeriodType(org.hisp.dhis.period.WeeklySaturdayPeriodType) SixMonthlyNovemberPeriodType(org.hisp.dhis.period.SixMonthlyNovemberPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) TwoYearlyPeriodType(org.hisp.dhis.period.TwoYearlyPeriodType) WeeklySundayPeriodType(org.hisp.dhis.period.WeeklySundayPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) FinancialNovemberPeriodType(org.hisp.dhis.period.FinancialNovemberPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) WeeklyWednesdayPeriodType(org.hisp.dhis.period.WeeklyWednesdayPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) TwoYearlyPeriodType(org.hisp.dhis.period.TwoYearlyPeriodType) WeeklyThursdayPeriodType(org.hisp.dhis.period.WeeklyThursdayPeriodType) Test(org.junit.jupiter.api.Test)

Example 2 with BiWeeklyPeriodType

use of org.hisp.dhis.period.BiWeeklyPeriodType in project dhis2-core by dhis2.

the class AdxPeriod method parse.

public static Period parse(String periodString) throws AdxException {
    String[] tokens = periodString.split("/");
    if (tokens.length != 2) {
        throw new AdxException(periodString + " not in valid <date>/<duration> format");
    }
    try {
        Period period;
        PeriodType periodType = null;
        Date startDate = DateUtils.getMediumDate(tokens[0]);
        Calendar cal = Calendar.getInstance();
        cal.setTime(startDate);
        Duration duration = Duration.valueOf(tokens[1]);
        switch(duration) {
            case P1D:
                periodType = new DailyPeriodType();
                break;
            case P7D:
                switch(cal.get(Calendar.DAY_OF_WEEK)) {
                    case MONDAY:
                        periodType = new WeeklyPeriodType();
                        break;
                    case WEDNESDAY:
                        periodType = new WeeklyWednesdayPeriodType();
                        break;
                    case THURSDAY:
                        periodType = new WeeklyThursdayPeriodType();
                        break;
                    case SATURDAY:
                        periodType = new WeeklySaturdayPeriodType();
                        break;
                    case SUNDAY:
                        periodType = new WeeklySundayPeriodType();
                        break;
                    default:
                        throw new AdxException(periodString + " is invalid weekly type");
                }
                break;
            case P14D:
                periodType = new BiWeeklyPeriodType();
                break;
            case P1M:
                periodType = new MonthlyPeriodType();
                break;
            case P2M:
                periodType = new BiMonthlyPeriodType();
                break;
            case P3M:
                periodType = new QuarterlyPeriodType();
                break;
            case P6M:
                switch(cal.get(Calendar.MONTH)) {
                    case JANUARY:
                    case JULY:
                        periodType = new SixMonthlyPeriodType();
                        break;
                    case APRIL:
                    case OCTOBER:
                        periodType = new SixMonthlyAprilPeriodType();
                        break;
                    case NOVEMBER:
                    case MAY:
                        periodType = new SixMonthlyNovemberPeriodType();
                        break;
                    default:
                        throw new AdxException(periodString + " is invalid sixmonthly type");
                }
                break;
            case P1Y:
                switch(cal.get(Calendar.MONTH)) {
                    case JANUARY:
                        periodType = new YearlyPeriodType();
                        break;
                    case APRIL:
                        periodType = new FinancialAprilPeriodType();
                        break;
                    case JULY:
                        periodType = new FinancialJulyPeriodType();
                        break;
                    case OCTOBER:
                        periodType = new FinancialOctoberPeriodType();
                        break;
                    case NOVEMBER:
                        periodType = new FinancialNovemberPeriodType();
                        break;
                    default:
                        throw new AdxException(periodString + " is invalid yearly type");
                }
                break;
        }
        if (periodType != null) {
            period = periodType.createPeriod(startDate);
        } else {
            throw new AdxException("Failed to create period type from " + duration);
        }
        return period;
    } catch (IllegalArgumentException ex) {
        throw new AdxException(tokens[1] + " is not a supported duration type");
    }
}
Also used : SixMonthlyNovemberPeriodType(org.hisp.dhis.period.SixMonthlyNovemberPeriodType) WeeklyWednesdayPeriodType(org.hisp.dhis.period.WeeklyWednesdayPeriodType) FinancialNovemberPeriodType(org.hisp.dhis.period.FinancialNovemberPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) WeeklyThursdayPeriodType(org.hisp.dhis.period.WeeklyThursdayPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) WeeklySundayPeriodType(org.hisp.dhis.period.WeeklySundayPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) WeeklySaturdayPeriodType(org.hisp.dhis.period.WeeklySaturdayPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) WeeklySaturdayPeriodType(org.hisp.dhis.period.WeeklySaturdayPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) WeeklyThursdayPeriodType(org.hisp.dhis.period.WeeklyThursdayPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) SixMonthlyNovemberPeriodType(org.hisp.dhis.period.SixMonthlyNovemberPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) Calendar(java.util.Calendar) Period(org.hisp.dhis.period.Period) WeeklySundayPeriodType(org.hisp.dhis.period.WeeklySundayPeriodType) Date(java.util.Date) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) FinancialNovemberPeriodType(org.hisp.dhis.period.FinancialNovemberPeriodType) WeeklyWednesdayPeriodType(org.hisp.dhis.period.WeeklyWednesdayPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType)

Example 3 with BiWeeklyPeriodType

use of org.hisp.dhis.period.BiWeeklyPeriodType in project dhis2-core by dhis2.

the class DateUnitPeriodTypeParser method parseInternal.

private DateInterval parseInternal(Calendar calendar, String period, DateUnitType.DateUnitTypeWithPattern dateUnitTypeWithPattern) {
    Pattern pattern = dateUnitTypeWithPattern.getPattern();
    DateUnitType dateUnitType = dateUnitTypeWithPattern.getDateUnitType();
    Matcher matcher = pattern.matcher(period);
    boolean match = matcher.find();
    if (!match) {
        return null;
    }
    if (DateUnitType.DAILY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int month = Integer.parseInt(matcher.group(2));
        int day = Integer.parseInt(matcher.group(3));
        DateTimeUnit dateTimeUnit = new DateTimeUnit(year, month, day, calendar.isIso8601());
        dateTimeUnit.setDayOfWeek(calendar.weekday(dateTimeUnit));
        return new DateInterval(dateTimeUnit, dateTimeUnit);
    } else if (DateUnitType.WEEKLY == dateUnitType || DateUnitType.WEEKLY_WEDNESDAY == dateUnitType || DateUnitType.WEEKLY_THURSDAY == dateUnitType || DateUnitType.WEEKLY_SATURDAY == dateUnitType || DateUnitType.WEEKLY_SUNDAY == dateUnitType) {
        DateTimeUnit start;
        DateTimeUnit end;
        int year = Integer.parseInt(matcher.group(1));
        int week = Integer.parseInt(matcher.group(2));
        WeeklyAbstractPeriodType periodType = (WeeklyAbstractPeriodType) PeriodType.getByNameIgnoreCase(dateUnitType.getName());
        if (periodType == null || week < 1 || week > calendar.weeksInYear(year)) {
            return null;
        }
        start = getDateTimeFromWeek(year, week, calendar, PeriodType.MAP_WEEK_TYPE.get(periodType.getName()), new DateTimeUnit(year, 1, 1));
        end = calendar.plusWeeks(start, 1);
        end = calendar.minusDays(end, 1);
        return new DateInterval(start, end);
    } else if (DateUnitType.BI_WEEKLY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int week = Integer.parseInt(matcher.group(2)) * 2 - 1;
        BiWeeklyPeriodType periodType = (BiWeeklyPeriodType) PeriodType.getByNameIgnoreCase(dateUnitType.getName());
        if (periodType == null || week < 1 || week > calendar.weeksInYear(year)) {
            return null;
        }
        DateTimeUnit start = getDateTimeFromWeek(year, week, calendar, DayOfWeek.MONDAY, new DateTimeUnit(year, 1, 1));
        DateTimeUnit end = calendar.plusWeeks(start, 2);
        end = calendar.minusDays(end, 1);
        return new DateInterval(start, end);
    } else if (DateUnitType.MONTHLY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int month = Integer.parseInt(matcher.group(2));
        DateTimeUnit start = new DateTimeUnit(year, month, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(year, month, calendar.daysInMonth(start.getYear(), start.getMonth()), calendar.isIso8601());
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.BI_MONTHLY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int month = Integer.parseInt(matcher.group(2));
        if (month < 1 || month > 6) {
            return null;
        }
        DateTimeUnit start = new DateTimeUnit(year, (month * 2) - 1, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusMonths(end, 2);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.QUARTERLY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int quarter = Integer.parseInt(matcher.group(2));
        // valid quarters are from 1 - 4
        if (quarter < 1 || quarter > 4) {
            return null;
        }
        DateTimeUnit start = new DateTimeUnit(year, ((quarter - 1) * 3) + 1, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusMonths(end, 3);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.SIX_MONTHLY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int semester = Integer.parseInt(matcher.group(2));
        // valid six-monthly are from 1 - 2
        if (semester < 1 || semester > 2) {
            return null;
        }
        DateTimeUnit start = new DateTimeUnit(year, semester == 1 ? 1 : 7, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusMonths(end, 6);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.SIX_MONTHLY_APRIL == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int semester = Integer.parseInt(matcher.group(2));
        // valid six-monthly are from 1 - 2
        if (semester < 1 || semester > 2) {
            return null;
        }
        DateTimeUnit start = new DateTimeUnit(year, semester == 1 ? 4 : 10, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusMonths(end, 6);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.SIX_MONTHLY_NOVEMBER == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        int semester = Integer.parseInt(matcher.group(2));
        // valid six-monthly are from 1 - 2
        if (semester < 1 || semester > 2) {
            return null;
        }
        DateTimeUnit start = new DateTimeUnit(semester == 1 ? year - 1 : year, semester == 1 ? 11 : 5, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusMonths(end, 6);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.YEARLY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        DateTimeUnit start = new DateTimeUnit(year, 1, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(year, calendar.monthsInYear(), calendar.daysInMonth(start.getYear(), calendar.monthsInYear()), calendar.isIso8601());
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.FINANCIAL_APRIL == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        DateTimeUnit start = new DateTimeUnit(year, 4, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusYears(end, 1);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.FINANCIAL_JULY == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        DateTimeUnit start = new DateTimeUnit(year, 7, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusYears(end, 1);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.FINANCIAL_OCTOBER == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        DateTimeUnit start = new DateTimeUnit(year, 10, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusYears(end, 1);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    } else if (DateUnitType.FINANCIAL_NOVEMBER == dateUnitType) {
        int year = Integer.parseInt(matcher.group(1));
        DateTimeUnit start = new DateTimeUnit(year - 1, 11, 1, calendar.isIso8601());
        DateTimeUnit end = new DateTimeUnit(start);
        end = calendar.plusYears(end, 1);
        end = calendar.minusDays(end, 1);
        start.setDayOfWeek(calendar.weekday(start));
        end.setDayOfWeek(calendar.weekday(end));
        return new DateInterval(start, end);
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BiWeeklyPeriodType(org.hisp.dhis.period.BiWeeklyPeriodType) WeeklyAbstractPeriodType(org.hisp.dhis.period.WeeklyAbstractPeriodType)

Aggregations

BiWeeklyPeriodType (org.hisp.dhis.period.BiWeeklyPeriodType)3 BiMonthlyPeriodType (org.hisp.dhis.period.BiMonthlyPeriodType)2 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)2 FinancialAprilPeriodType (org.hisp.dhis.period.FinancialAprilPeriodType)2 FinancialJulyPeriodType (org.hisp.dhis.period.FinancialJulyPeriodType)2 FinancialNovemberPeriodType (org.hisp.dhis.period.FinancialNovemberPeriodType)2 FinancialOctoberPeriodType (org.hisp.dhis.period.FinancialOctoberPeriodType)2 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)2 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)2 SixMonthlyAprilPeriodType (org.hisp.dhis.period.SixMonthlyAprilPeriodType)2 SixMonthlyNovemberPeriodType (org.hisp.dhis.period.SixMonthlyNovemberPeriodType)2 SixMonthlyPeriodType (org.hisp.dhis.period.SixMonthlyPeriodType)2 WeeklyPeriodType (org.hisp.dhis.period.WeeklyPeriodType)2 WeeklySaturdayPeriodType (org.hisp.dhis.period.WeeklySaturdayPeriodType)2 WeeklySundayPeriodType (org.hisp.dhis.period.WeeklySundayPeriodType)2 WeeklyThursdayPeriodType (org.hisp.dhis.period.WeeklyThursdayPeriodType)2 WeeklyWednesdayPeriodType (org.hisp.dhis.period.WeeklyWednesdayPeriodType)2 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1