/*
 * [TestMillis.java]
 *
 * Summary: Calculations in milliseconds.
 *
 * Copyright: (c) 2012-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2012-03-23 initial version.
 */
package com.mindprod.example;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import static java.lang.System.*;

/**
 * Calculations in milliseconds.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2012-03-23 initial version.
 * @since 2012-03-23
 */
public final class TestMillis
    {
    private static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L; /* 86,400,000 */

    private static final long MILLIS_PER_HOUR = 60 * 60 * 1000L;  /* 3,600,000 */

    private static final long MILLIS_PER_MINUTE = 60 * 1000L; /* 60,000 */

    private static final long MILLIS_PER_MONTH = ( long ) ( 30.4375 * 24 * 60 * 60 * 1000L ); /* 2,629,800,000 */

    private static final long MILLIS_PER_SECOND = 1000L; /* 1,000 */

    private static final long MILLIS_PER_YEAR = ( long ) ( 365.25d * 24 * 60 * 60 * 1000L ); /* 31,557,600,000 */

    private static final DecimalFormat DF = new DecimalFormat( "###,##0" );

    /**
     * Modified Zulu format mask 2008-06-22T07:57+46.438
     */
    private static final SimpleDateFormat SDF = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm'+'ss'.'SSS" );

    /**
     * Calculations in milliseconds
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        long now = System.currentTimeMillis(); // current UTC time in millis since 1970-01-01 0:00
        // display in calendar format:
        // Leave SDF TimeZone at the default locale.
        // Adjusts for local TimeZone and DST
        out.println( SDF.format( new Date( now ) ) );  /* 2012-03-23T12:09+19.862 */
        out.println( "----- using static final constants -----" );
        out.println( "millis/second:"
                     + DF.format( MILLIS_PER_SECOND ) ); /* millis/second:1,000 */
        out.println( "millis/minute:"
                     + DF.format( MILLIS_PER_MINUTE ) ); /* millis/minute:60,000 */
        out.println( "millis/hour:"
                     + DF.format( MILLIS_PER_HOUR ) ); /* millis/hour:3,600,000  */
        out.println( "millis/day:"
                     + DF.format( MILLIS_PER_DAY ) );  /* millis/day:86,400,000 */
        out.println( "millis/month:"
                     + DF.format( MILLIS_PER_MONTH ) ); /* millis/month:2,629,800,000 */
        out.println( "millis/year:"
                     + DF.format( MILLIS_PER_YEAR ) ); /* millis/year:31,557,600,000  */
        out.println( "millis that can fit in a long:"
                     + DF.format( Long.MAX_VALUE )
                     + " i.e. "
                     + DF.format( Long.MAX_VALUE / MILLIS_PER_YEAR )
                     + " years worth" );  /* millis that can fit in a long:9,223,372,036,854,775,807 i.e. 292,271,
                     023 years worth */
        out.println( "millis that can fit in an int:"
                     + DF.format( Integer.MAX_VALUE )
                     + " i.e. "
                     + DF.format( Integer.MAX_VALUE / MILLIS_PER_DAY )
                     + " days worth" );  /* millis that can fit in an int:2,147,483,647 i.e. 24 days worth */
        out.println( "----- using java.util.concurrent.TimeUnit -----" );
        out.println( "millis/second:"
                     + DF.format( TimeUnit.SECONDS.toMillis( 1 ) ) ); /* millis/second:1,000 */
        out.println( "millis/minute:"
                     + DF.format( TimeUnit.MINUTES.toMillis( 1 ) ) ); /* millis/minute:60,000 */
        out.println( "millis/hour:"
                     + DF.format( TimeUnit.HOURS.toMillis( 1 ) ) ); /* millis/hour:3,600,000  */
        out.println( "millis/day:"
                     + DF.format( TimeUnit.DAYS.toMillis( 1 ) ) );  /* millis/day:86,400,000 */
        }
    }