public List < DateTimePeriod > toYears ( ) { ArrayList < DateTimePeriod > list = new ArrayList < DateTimePeriod > ( ) ; // default "current" year to start datetime DateTime currentStart = getStart ( ) ; // calculate "next" year DateTime nextStart = currentStart . plusYears ( 1 ) ; // continue adding until we've reached the end while ( nextStart . isBefore ( getEnd ( ) ) || nextStart . isEqual ( getEnd ( ) ) ) { // its okay to add the current list . add ( new DateTimeYear ( currentStart , nextStart ) ) ; // increment both currentStart = nextStart ; nextStart = currentStart . plusYears ( 1 ) ; } return list ; }
Converts this period to a list of year periods . Partial years will not be included . For example a period of 2009 - 2010 will return a list of 2 years - one for 2009 and one for 2010 . On the other hand a period of January 2009 would return an empty list since partial years are not included .