use of org.hisp.dhis.period.WeeklyPeriodType in project dhis2-core by dhis2.
the class PeriodUtil method getPeriod.
public static Period getPeriod(String periodName, PeriodType periodType) throws InvalidIdentifierReferenceException {
if (periodType instanceof DailyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof WeeklyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof MonthlyPeriodType) {
int dashIndex = periodName.indexOf('-');
if (dashIndex < 0) {
return null;
}
int month = Integer.parseInt(periodName.substring(0, dashIndex));
int year = Integer.parseInt(periodName.substring(dashIndex + 1, periodName.length()));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof YearlyPeriodType) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(periodName));
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof QuarterlyPeriodType) {
Calendar cal = Calendar.getInstance();
int month = 0;
if (periodName.substring(0, periodName.indexOf(" ")).equals("Jan")) {
month = 1;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Apr")) {
month = 4;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Jul")) {
month = 6;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Oct")) {
month = 10;
}
int year = Integer.parseInt(periodName.substring(periodName.lastIndexOf(" ") + 1));
cal.set(Calendar.MONTH, month);
cal.set(Calendar.YEAR, year);
if (month != 0) {
return periodType.createPeriod(cal.getTime());
}
}
throw new InvalidIdentifierReferenceException("Couldn't make a period of type " + periodType.getName() + " and name " + periodName);
}
use of org.hisp.dhis.period.WeeklyPeriodType in project dhis2-core by dhis2.
the class J2MEDataValueSMSListener method getPeriod.
public Period getPeriod(String periodName, PeriodType periodType) throws IllegalArgumentException {
if (periodType instanceof DailyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof WeeklyPeriodType) {
return periodType.createPeriod(DateUtils.getMediumDate(periodName));
}
if (periodType instanceof MonthlyPeriodType) {
int dashIndex = periodName.indexOf('-');
if (dashIndex < 0) {
return null;
}
int month = Integer.parseInt(periodName.substring(0, dashIndex));
int year = Integer.parseInt(periodName.substring(dashIndex + 1, periodName.length()));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month);
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof YearlyPeriodType) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(periodName));
return periodType.createPeriod(cal.getTime());
}
if (periodType instanceof QuarterlyPeriodType) {
Calendar cal = Calendar.getInstance();
int month = 0;
if (periodName.substring(0, periodName.indexOf(" ")).equals("Jan")) {
month = 1;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Apr")) {
month = 4;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Jul")) {
month = 6;
} else if (periodName.substring(0, periodName.indexOf(" ")).equals("Oct")) {
month = 10;
}
int year = Integer.parseInt(periodName.substring(periodName.lastIndexOf(" ") + 1));
cal.set(Calendar.MONTH, month);
cal.set(Calendar.YEAR, year);
if (month != 0) {
return periodType.createPeriod(cal.getTime());
}
}
throw new IllegalArgumentException("Couldn't make a period of type " + periodType.getName() + " and name " + periodName);
}
Aggregations