public List < DateTimePeriod > toMonths ( ) { ArrayList < DateTimePeriod > list = new ArrayList < DateTimePeriod > ( ) ; // default "current" month to start datetime DateTime currentStart = getStart ( ) ; // calculate "next" month DateTime nextStart = currentStart . plusMonths ( 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 DateTimeMonth ( currentStart , nextStart ) ) ; // increment both currentStart = nextStart ; nextStart = currentStart . plusMonths ( 1 ) ; } return list ; }
Converts this period to a list of month periods . Partial months will not be included . For example a period of 2009 will return a list of 12 months - one for each month in 2009 . On the other hand a period of January 20 2009 would return an empty list since partial months are not included .