@Override public Period createPeriod( Calendar cal ) { //TODO: use local calendar instead of hard coded Gregorian cal.set( Calendar.YEAR, cal.get( Calendar.YEAR ) - cal.get( Calendar.YEAR ) % 2 ); cal.set( Calendar.DAY_OF_YEAR, 1 ); Date startDate = cal.getTime(); cal.add( Calendar.YEAR, 1 ); cal.set( Calendar.DAY_OF_YEAR, cal.getActualMaximum( Calendar.DAY_OF_YEAR ) ); return new Period( this, startDate, cal.getTime() ); }
@Override public List<Period> generateLast5Years( Date date ) { //TODO: use local calendar instead of hard coded Gregorian Calendar cal = createCalendarInstance( date ); cal.add( Calendar.YEAR, cal.get( Calendar.YEAR ) % 2 == 0 ? -10 : -9 ); cal.set( Calendar.DAY_OF_YEAR, 1 ); ArrayList<Period> twoYears = new ArrayList<>(); for ( int i = 0; i < 5; ++i ) { Date startDate = cal.getTime(); cal.add( Calendar.YEAR, 1 ); cal.set( Calendar.DAY_OF_YEAR, cal.getActualMaximum( Calendar.DAY_OF_YEAR ) ); twoYears.add( new Period( this, startDate, cal.getTime() ) ); cal.add( Calendar.DAY_OF_YEAR, 1 ); } return twoYears; }
/** * Generates two-yearly Periods for the last 10, current and next 10 years. */ @Override public List<Period> generatePeriods( Date date ) { //TODO: use local calendar instead of hard coded Gregorian Calendar cal = createCalendarInstance( date ); cal.add( Calendar.YEAR, cal.get( Calendar.YEAR ) % 2 == 0 ? -10 : -9 ); cal.set( Calendar.DAY_OF_YEAR, 1 ); ArrayList<Period> twoYears = new ArrayList<>(); for ( int i = 0; i < 11; ++i ) { Date startDate = cal.getTime(); cal.add( Calendar.YEAR, 1 ); cal.set( Calendar.DAY_OF_YEAR, cal.getActualMaximum( Calendar.DAY_OF_YEAR ) ); twoYears.add( new Period( this, startDate, cal.getTime() ) ); cal.add( Calendar.DAY_OF_YEAR, 1 ); } return twoYears; }
/** * @param type The PeriodType. * @param startDate The start date. */ public static Period createPeriod( PeriodType type, Date startDate ) { Period period = new Period(); period.setAutoFields(); period.setPeriodType( type ); period.setStartDate( startDate ); return period; }
/** * Returns partitions for the given start and end date. * * @param startDate the start date. * @param endDate the end date. * @return partitions for the given start and end date. */ public static Partitions getPartitions( Date startDate, Date endDate ) { Period period = new Period(); period.setStartDate( startDate ); period.setEndDate( endDate ); return getPartitions( period ); }
private Period setPeriodDateRange( PeriodType periodType ) throws ParseException { Period period = new Period(); Calendar currentDate = Calendar.getInstance(); int currYear = currentDate.get( Calendar.YEAR ); int startYear = currYear - PERIODRANGE_PREVYEARS; int endYear = currYear + PERIODRANGE_FUTUREYEARS; if ( periodType.getName().equals( QuarterlyPeriodType.NAME ) || periodType.getName().equals( SixMonthlyPeriodType.NAME ) || periodType.getName().equals( SixMonthlyAprilPeriodType.NAME ) || periodType.getName().equals( YearlyPeriodType.NAME ) || periodType.getName().equals( FinancialAprilPeriodType.NAME ) || periodType.getName().equals( FinancialJulyPeriodType.NAME ) || periodType.getName().equals( FinancialOctoberPeriodType.NAME ) ) { startYear = currYear - PERIODRANGE_PREVYEARS_YEARLY; endYear = currYear + PERIODRANGE_FUTUREYEARS_YEARLY; } period.setStartDate( DateUtils.getMediumDate( String.valueOf( startYear ) + "-01-01" ) ); period.setEndDate( DateUtils.getMediumDate( String.valueOf( endYear ) + "-01-01" ) ); return period; }
/** * @param type The PeriodType. * @param startDate The start date. * @param endDate The end date. */ public static Period createPeriod( PeriodType type, Date startDate, Date endDate ) { Period period = new Period(); period.setAutoFields(); period.setPeriodType( type ); period.setStartDate( startDate ); period.setEndDate( endDate ); return period; }
protected Period toIsoPeriod( DateTimeUnit start, DateTimeUnit end, org.hisp.dhis.calendar.Calendar calendar ) { DateTimeUnit from = calendar.toIso( start ); DateTimeUnit to = calendar.toIso( end ); return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( start, calendar ) ); }
/** * @param startDate The start date. * @param endDate The end date. */ public static Period createPeriod( Date startDate, Date endDate ) { Period period = new Period(); period.setAutoFields(); period.setPeriodType( new MonthlyPeriodType() ); period.setStartDate( startDate ); period.setEndDate( endDate ); return period; }
@Override public DataValue mapRow( ResultSet resultSet ) throws SQLException { final DataValue dataValue = new DataValue(); dataValue.setDataElement( new DataElement() ); dataValue.setCategoryOptionCombo( new CategoryOptionCombo() ); dataValue.setAttributeOptionCombo( new CategoryOptionCombo() ); dataValue.setSource( new OrganisationUnit() ); dataValue.setPeriod( new Period() ); dataValue.getDataElement().setId( resultSet.getInt( "dataelementid" ) ); dataValue.getPeriod().setId( resultSet.getInt( "periodid" ) ); dataValue.getSource().setId( resultSet.getInt( "sourceid" ) ); dataValue.getCategoryOptionCombo().setId( resultSet.getInt( "categoryoptioncomboid" ) ); dataValue.setValue( resultSet.getString( "value" ) ); dataValue.setStoredBy( resultSet.getString( "storedby" ) ); dataValue.setCreated( resultSet.getDate( "created" ) ); dataValue.setLastUpdated( resultSet.getDate( "lastupdated" ) ); dataValue.setComment( resultSet.getString( "comment" ) ); return dataValue; }
/** * Generates weekly Periods for the whole year in which the given Period's * startDate exists. */ @Override public List<Period> generatePeriods( DateTimeUnit start ) { Calendar calendar = getCalendar(); List<Period> periods = new ArrayList<>(); start = new DateTimeUnit( start ); // create clone so we don't modify the original start DT start.setMonth( 1 ); start.setDay( 4 ); start = adjustToStartOfWeek( start, calendar ); for ( int i = 0; i < calendar.weeksInYear( start.getYear() ); i++ ) { DateInterval interval = calendar.toInterval( start, DateIntervalType.ISO8601_WEEK ); periods.add( new Period( this, interval.getFrom().toJdkDate(), interval.getTo().toJdkDate() ) ); start = calendar.plusWeeks( start, 1 ); } return periods; }
/** * @param dateInterval DateInterval to create period from * @return the period. */ public Period createPeriod( DateInterval dateInterval ) { if ( dateInterval == null || dateInterval.getFrom() == null || dateInterval.getTo() == null ) { return null; } org.hisp.dhis.calendar.Calendar cal = getCalendar(); final DateTimeUnit from = cal.toIso( dateInterval.getFrom() ); final DateTimeUnit to = cal.toIso( dateInterval.getTo() ); return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( from ) ); }