Search in sources :

Example 1 with FinancialOctoberPeriodType

use of org.hisp.dhis.period.FinancialOctoberPeriodType 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 = null;
        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:
                periodType = new WeeklyPeriodType();
                break;
            case P1M:
                periodType = new MonthlyPeriodType();
                break;
            case P2M:
                periodType = new BiMonthlyPeriodType();
                break;
            case P1Q:
                periodType = new QuarterlyPeriodType();
                break;
            case P6M:
                switch(cal.get(Calendar.MONTH)) {
                    case 0:
                        periodType = new SixMonthlyPeriodType();
                        break;
                    case 6:
                        periodType = new SixMonthlyAprilPeriodType();
                        break;
                    default:
                        throw new AdxException(periodString + "is invalid sixmonthly type");
                }
            case P1Y:
                switch(cal.get(Calendar.MONTH)) {
                    case 0:
                        periodType = new YearlyPeriodType();
                        break;
                    case 3:
                        periodType = new FinancialAprilPeriodType();
                        break;
                    case 6:
                        periodType = new FinancialJulyPeriodType();
                        break;
                    case 9:
                        periodType = new FinancialOctoberPeriodType();
                        break;
                    default:
                        throw new AdxException(periodString + "is invalid yearly type");
                }
        }
        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 : DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) FinancialJulyPeriodType(org.hisp.dhis.period.FinancialJulyPeriodType) Calendar(java.util.Calendar) Period(org.hisp.dhis.period.Period) SixMonthlyAprilPeriodType(org.hisp.dhis.period.SixMonthlyAprilPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Date(java.util.Date) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) BiMonthlyPeriodType(org.hisp.dhis.period.BiMonthlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialOctoberPeriodType(org.hisp.dhis.period.FinancialOctoberPeriodType) SixMonthlyPeriodType(org.hisp.dhis.period.SixMonthlyPeriodType) FinancialAprilPeriodType(org.hisp.dhis.period.FinancialAprilPeriodType)

Aggregations

Calendar (java.util.Calendar)1 Date (java.util.Date)1 BiMonthlyPeriodType (org.hisp.dhis.period.BiMonthlyPeriodType)1 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)1 FinancialAprilPeriodType (org.hisp.dhis.period.FinancialAprilPeriodType)1 FinancialJulyPeriodType (org.hisp.dhis.period.FinancialJulyPeriodType)1 FinancialOctoberPeriodType (org.hisp.dhis.period.FinancialOctoberPeriodType)1 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)1 Period (org.hisp.dhis.period.Period)1 PeriodType (org.hisp.dhis.period.PeriodType)1 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)1 SixMonthlyAprilPeriodType (org.hisp.dhis.period.SixMonthlyAprilPeriodType)1 SixMonthlyPeriodType (org.hisp.dhis.period.SixMonthlyPeriodType)1 WeeklyPeriodType (org.hisp.dhis.period.WeeklyPeriodType)1 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)1