edu.cmu.pslc.logging.util

## Class DateTools

- java.lang.Object
- - edu.cmu.pslc.logging.util.DateTools

-     public final class DateTools
      extends java.lang.Object

  Utility class for Date conversions.
  Version:
    $Revision: 8770 $
    Last modified by: $Author: ctipper $
    Last modified on: $Date: 2013-02-28 15:34:36 -0500 (Thu, 28 Feb 2013) $
  Author:
    Alida Skogsholm

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `checkDate(java.lang.String timeString, java.lang.String timeZone)` Determines if the provided timeString and timeZone are of a valid Date format.
    `static int` | `dateComparison(java.util.Date o1, java.util.Date o2, boolean ascFlag)` Compare two Date objects, ignoring all but day, month and year information.
    `static int` | `dateComparison(java.util.Date o1, java.util.Date o2, boolean ascFlag, boolean dateOnly)` Compare two Date objects, with the option to use the date only, cropping hours, minutes and seconds off the Date before comparing.
    `static java.util.Date` | `getDate(java.lang.String timeString)` Try to create a Date object given a time string and a time zone.
    `static java.util.Date` | `getDate(java.lang.String timeString, java.lang.String timeZone)` Try to create a Date object given a time string and a time zone.
    `static java.lang.String` | `getElapsedTimeString(long startTime)` Elapsed time string from start time to right now.
    `static java.lang.String` | `getElapsedTimeString(long startTime, long endTime)` Return the elapsed time in HH:mm:ss.
    `static java.lang.String` | `getTimeStringWithOutTimeZone(java.util.Date date)` Return the date as a String without the time zone.
    `static java.lang.String` | `getTimeStringWithTimeZone(java.util.Date date)` Return the date as a String with the time zone.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getDate

          public static java.util.Date getDate(java.lang.String timeString,
                               java.lang.String timeZone)

      Try to create a Date object given a time string and a time zone.
      Parameters:
        `timeString` - string containing the time
        `timeZone` - the time zone
      Returns:
        a date object using the time string if possible, now otherwise

    - #### getDate

          public static java.util.Date getDate(java.lang.String timeString)

      Try to create a Date object given a time string and a time zone. Time zone defaults to null.
      Parameters:
        `timeString` - string containing the time
      Returns:
        a date object using the time string if possible, now otherwise

    - #### checkDate

          public static boolean checkDate(java.lang.String timeString,
                          java.lang.String timeZone)

      Determines if the provided timeString and timeZone are of a valid Date format. Returns true if valid, false otherwise. Used by DatasetVerificationTool.
      Parameters:
        `timeString` - string of the time
        `timeZone` - string of the time zone.
      Returns:
        boolean

    - #### getTimeStringWithTimeZone

          public static java.lang.String getTimeStringWithTimeZone(java.util.Date date)

      Return the date as a String with the time zone.
      Parameters:
        `date` - the date to convert to a string
      Returns:
        a time string with the time zone

    - #### getTimeStringWithOutTimeZone

          public static java.lang.String getTimeStringWithOutTimeZone(java.util.Date date)

      Return the date as a String without the time zone.
      Parameters:
        `date` - the date to convert to a string
      Returns:
        a time string without the time zone

    - #### getElapsedTimeString

          public static java.lang.String getElapsedTimeString(long startTime,
                                              long endTime)

      Return the elapsed time in HH:mm:ss.
      Parameters:
        `startTime` - the start time in milliseconds
        `endTime` - the end time in milliseconds
      Returns:
        a string with the elapsed time in HH:mm:ss

    - #### getElapsedTimeString

          public static java.lang.String getElapsedTimeString(long startTime)

      Elapsed time string from start time to right now.
      Parameters:
        `startTime` - the start time
      Returns:
        the elapsed time string from start time to right now

    - #### dateComparison

          public static int dateComparison(java.util.Date o1,
                           java.util.Date o2,
                           boolean ascFlag)

      Compare two Date objects, ignoring all but day, month and year information.
      Parameters:
        `o1` - the first Date object
        `o2` - the second Date object
        `ascFlag` - flag indicating sort direction, ascending or descending
      Returns:
        result the comparator value

    - #### dateComparison

          public static int dateComparison(java.util.Date o1,
                           java.util.Date o2,
                           boolean ascFlag,
                           boolean dateOnly)

      Compare two Date objects, with the option to use the date only, cropping hours, minutes and seconds off the Date before comparing.
      Parameters:
        `o1` - the first Date object
        `o2` - the second Date object
        `ascFlag` - flag indicating sort direction, ascending or descending
        `dateOnly` - flag indicating hours, minutes and seconds are ignored
      Returns:
        result the comparator value

Copyright (c) 2015 - Pittsburgh Science of Learning Center