//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MODULE: Day                      AUTHOR: Tim Sabin                   //
// DESCRIPTION:  Day is a TimePeriod class that represents one day.     //
// DATE CREATED: 06/12/1998         LAST UPDATED: 12/09/1998            //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

import TimePeriod;
import java.util.GregorianCalendar;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.ParsePosition;

/** <code>Day</code> is a TimePeriod that represents one day. */
public class Day extends TimePeriod {
    /** Create a Day object.
     * @param year    Calendar year of day.
     * @param month    Month of date.
     * @param day    Exact day of month & year */
    public Day (int year, int month, int day) {
        int yr = 0;
        int mon = 0;
        int dy = 0;
        String line;
        RandomAccessFile YearStartDate;
        DecimalFormat dp;
        ParsePosition pos;
        begDate = new GregorianCalendar ();
        begDate.set (year, month - 1, day);
        endDate = begDate;
        tpType = TimePeriod.DAILY;
        // Read in start day of fiscal year into local variables
        try {
            YearStartDate = new RandomAccessFile ("YearStart.date", "r");
            while (true) {
                line = YearStartDate.readLine ();
                pos = new ParsePosition (0);
                dp = new DecimalFormat ();
                yr = ((Long)dp.parse (line, pos)).intValue ();
                if (yr == year) {
                    break;
                }
            }
            pos.setIndex (pos.getIndex () + 1);
            mon = ((Long)dp.parse (line, pos)).intValue () - 1;
            pos.setIndex (pos.getIndex () + 1);
            dy = ((Long)dp.parse (line, pos)).intValue ();
            pos.setIndex (pos.getIndex () + 1);
            yr = ((Long)dp.parse (line, pos)).intValue ();// Start yr not same as FY!
            YearStartDate.close ();
            GregorianCalendar td = new GregorianCalendar ();
            td.set (yr, mon - 1, dy);
            if (td.before (begDate))
                year++;
            tpFY = year;
        } catch (IOException e) {
            System.out.println ("Can't open YearStart.date");
        }    // end try block
    }
    public Day () {
        begDate = new GregorianCalendar ();
        endDate = begDate;
        tpType = TimePeriod.DAILY;
    }
}
