package com.mindprod.inauguration;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

/**
 * calculate hours to next inauguration. Demonstrates use of GregorianCarlendar for elapsed time calculation.
 *
 * @author Roedy Green
 * @Version 1.2 2005-06-30
 */
public final class Inauguration1
    {
// ------------------------------ FIELDS ------------------------------

    /**
     * 3,600,000 the number of milliseconds in an hour
     */
    static final int MILLISECONDS_PER_HOUR = 60 * 60 * 1000;

// --------------------------- main() method ---------------------------

    /**
     * Main method.
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        // inauguration day is Thursday 2009-01-20 noon Eastern Standard
        // Time.
        final int inaugYear = 2009;
        TimeZone est = TimeZone.getTimeZone( "America/New_York" );
        GregorianCalendar inauguration = new GregorianCalendar( est );
        inauguration.set( inaugYear, Calendar.JANUARY, 20, 12, 0 );

        // now is current time, using default timezone
        GregorianCalendar now = new GregorianCalendar();

        // milliseconds since 1970 Jan 1
        long epochInauguration = inauguration.getTime().getTime();
        long epochNow = now.getTime().getTime();

        double hours =
                ( double ) ( epochInauguration - epochNow ) / MILLISECONDS_PER_HOUR;
        System.out.println( hours + " hours until the inauguration." );
        }
    }