//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MODULE: TimePeriod           AUTHOR: Tim Sabin                       //
// DESCRIPTION:  TimePeriod is an ADC that represents a period of time. //
// DATE CREATED: 06/11/1998     LAST UPDATED: 07/28/1998                //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

import java.util.Calendar;

/**
 * The <code>TimePeriod</code> class represents an arbitrary time period,
 * represented by beginning and end dates. Time periods can also be
 * identified as Accounting Period, Weekly, or Daily, and can have an ID
 * associated with them (e.g., Week 09). All <code>TimePeriod</code>
 * objects are associated with a Fiscal Year.
 * <p>
 * @version 0.1
 * @author Tim Sabin
 * @since HASP Report v.1
 */
 
public abstract class TimePeriod {
    // The dates must be set by methods of inherited classes, preferrably
    // by constructors.
    /** Report type. Can be Accounting Period, Weekly, or Daily. */
    protected int tpType;
    /** Time period ID. E.g., "Week 09". */
    protected int tpID;
    /** Report Fiscal year. The USPS fiscal year that contains this
     * period. */
    protected int tpFY;
    /** Beginning date of the time period.
     * @see java.util.Calendar */
    protected Calendar begDate;
    /** End date of the time period.
     * @see java.util.Calendar */
    protected Calendar endDate;
    /** Constant. Identifies accounting periods. */
    public static final int AP = 1;
    /** Constant. Identifies week time periods. */
    public static final int WEEKLY = 2;
    /** Constant. Identifies day time periods. */
    public static final int DAILY = 3;
    
    /** Fetch the Calendar associated with the beginning date of this
     * period.
     * @see java.util.Calendar */
    public final Calendar BeginningDate () {
        return begDate;
    }
    /** Fetch the Calendar associated with the end date of this period.
     * @see java.util.Calendar */
    public final Calendar EndDate () {
        return endDate;
    }
    /** Get the report type. */
    public final int GetType () {
        return tpType;
    }
    /** Get the time period's ID. E.g., "Week 09". */
    public final int GetID () {
        return tpID;
    }
    /** Get the time period's fiscal year. All USPS fiscal years start
     * on a Saturday in September of the calendar year. */
    public final int GetFiscalYear () {
        return tpFY;
    }
    /** Print a date. This convenience routine creates a string of the
     * passed Calendar object. The format created is mm/dd/yyyy.
     * @see java.util.Calendar */
    public final static String PrintDate (Calendar dt) {
        String str = new String ();
        if (dt.get (Calendar.MONTH) < 9)
            str = str.concat ("0");
        str = str.concat ((dt.get (Calendar.MONTH) + 1) + "/");
        if (dt.get (Calendar.DATE) < 10)
            str = str.concat ("0");
        str = str.concat (dt.get (Calendar.DATE) + "/");
        if (dt.get (Calendar.YEAR) < 10)
            str = str.concat ("0");
        str = str.concat (String.valueOf (dt.get (Calendar.YEAR)));
        System.out.println ("Date printed: " + str);
        return str;
    }
        
}
