/*
 * @topic T10120 GregorianCalendar and Date demo 2/3/2014
 * @brief main driver program
*/
package wk03calendardemo;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class AppMain {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        GregorianCalendar endDate =
                new GregorianCalendar(2010, Calendar.FEBRUARY, 30);
        display_date( endDate ); // March 2, 2010
        
        endDate.set(2010, 2, 30);              // March 2, 2010
        display_date( endDate );
        
        endDate.set(2010, Calendar.MARCH, 30); // March 30, 2010
        display_date( endDate );
        
        endDate.set(Calendar.MONTH, Calendar.JANUARY);
        display_date( endDate );
        
        // January 30, 2010
        endDate.add(Calendar.MONTH, 1);        // June 30, 2010
        display_date( endDate );
        
        endDate.add(Calendar.MONTH, 14);       // August 30, 2011
        display_date( endDate );
        
        endDate.roll(Calendar.MONTH, 14);      // October 30, 2011
        display_date( endDate );
        
        endDate.roll(Calendar.MONTH, true);    // November 30, 2011: +1 tick
        display_date( endDate );
        
        endDate.roll(Calendar.DAY_OF_MONTH, false);
        display_date( endDate );
        
        // November 29, 2011: -1 tick
        
        endDate.set(2014, Calendar.JANUARY, 1, 0, 33, 5 );
        System.out.println(
                "Day of year: " + endDate.get( Calendar.DAY_OF_YEAR ) );
        
        Date myDate = endDate.getTime();
        DateFormat dateFormat = DateFormat.getDateTimeInstance(
                DateFormat.FULL, DateFormat.FULL);
        System.out.println( dateFormat.format( myDate ) );

        dateFormat = DateFormat.getDateTimeInstance(
                DateFormat.SHORT, DateFormat.SHORT);
        System.out.println( dateFormat.format( myDate ) );
    }//main
    
    public static void display_date( GregorianCalendar aCalendarDate )
    {
        System.out.print( get_month( aCalendarDate.get(Calendar.MONTH) ) );
        System.out.print( " " + aCalendarDate.get(Calendar.DAY_OF_MONTH) );
        System.out.println( ", " + aCalendarDate.get(Calendar.YEAR) );
    }
    
    public static String get_month( int aMonth )
    {
        switch ( aMonth ) {
            case 0: return "Jan";
            case 1: return "Feb";
            case 2: return "Mar";
            case 3: return "Apr";
            case 4: return "May";
            case 5: return "Jun";
            case 6: return "Jul";
            case 7: return "Aug";
            case 8: return "Sep";
            case 9: return "Oct";
            case 10: return "Nov";
            case 11: return "Dec";
            default: return "Unknown";
        }
    }
}//class AppMain