Package de.gebit.integrity.utils

## Class DateUtil

- java.lang.Object
- - de.gebit.integrity.utils.DateUtil

-     public final class DateUtil
      extends Object

  A utility class to handle date/time parsing and other date stuff. Sorry for the uglyness, but date/time handling just IS ugly crap, especially when using Java's built-in functionality :-(.
  Author:
    Rene Schneider - initial API and implementation

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static Calendar` | `convertDateAndTimeValue​(DateAndTimeValue aValue)` | Converts a given date and time to a `Calendar`.
    `static Calendar` | `convertDateValue​(DateValue aValue)` | Converts a given date value to a `Calendar`.
    `static String` | `convertNanosecondTimespanToHumanReadableFormat​(long aTimespan, boolean aShortFormat, boolean aLongFormat)` | Converts a duration in nanoseconds to a human-readable, nicely formatted string.
    `static List<org.eclipse.xtext.util.Pair<Long,​TemporalUnit>>` | `convertTimeDifference​(TimeDifference aDifference, ValueConverter aValueConverter)` | Converts a `TimeDifference` to a list of `Pair` with value plus `TemporalUnit`.
    `static BigDecimal` | `convertTimeSetProgressionFactor​(TimeSet aTimeSet, ValueConverter aValueConverter, ConversionContext aConversionContext)` | Converts the timeset commands' progression factor.
    `static Calendar` | `convertTimeValue​(TimeValue aValue)` | Converts a given time value to a `Calendar`.
    `static String` | `formatDateWithMilliseconds​(DateFormat aFormat, Date aDate)` | Performs date formatting using the provided format, but injects millisecond precision if the millisecond value is not "000".
    `static Date` | `stripDateFromTime​(Date aTime)` | Strips the date information from a given `Date` (sets all time fields to zero).
    `static Date` | `stripTimeFromDate​(Date aDate)` | Strips the time information from a given `Date` (sets all time fields to zero).

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

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

- - ### Method Detail

    - #### convertDateValue

          public static Calendar convertDateValue​(DateValue aValue)
                                           throws ParseException

      Converts a given date value to a `Calendar`.
      Parameters:
        `aValue` - the date value
      Returns:
        the calendar set to the specified date
      Throws:
        `ParseException` - if the value cannot be parsed because it is of wrong format or depicts an illegal date/time

    - #### convertTimeValue

          public static Calendar convertTimeValue​(TimeValue aValue)
                                           throws ParseException

      Converts a given time value to a `Calendar`.
      Parameters:
        `aValue` - the time value
      Returns:
        the calendar set to the specified date
      Throws:
        `ParseException` - if the value cannot be parsed because it is of wrong format or depicts an illegal date/time

    - #### convertDateAndTimeValue

          public static Calendar convertDateAndTimeValue​(DateAndTimeValue aValue)
                                                  throws ParseException

      Converts a given date and time to a `Calendar`.
      Parameters:
        `aValue` - the date value
      Returns:
        the calendar set to the specified date
      Throws:
        `ParseException` - if the value cannot be parsed because it is of wrong format or depicts an illegal date/time

    - #### stripTimeFromDate

          public static Date stripTimeFromDate​(Date aDate)

      Strips the time information from a given `Date` (sets all time fields to zero).
      Parameters:
        `aDate` - the date
      Returns:
        a new Date without time information

    - #### stripDateFromTime

          public static Date stripDateFromTime​(Date aTime)

      Strips the date information from a given `Date` (sets all time fields to zero).
      Parameters:
        `aTime` - the time
      Returns:
        a new Time without the date information

    - #### formatDateWithMilliseconds

          public static String formatDateWithMilliseconds​(DateFormat aFormat,
                                                          Date aDate)

      Performs date formatting using the provided format, but injects millisecond precision if the millisecond value is not "000". This is intended to be used with the standard date/time formats returned by DateFormat factory methods, which don't include milliseconds in most cases unfortunately. It employs a rather ugly hack to enhance the pattern which only works with `SimpleDateFormat`, but as far as I know there's no better method to achieve this result.
      Parameters:
        `aFormat` - the base format
        `aDate` - the date to format
      Returns:
        the formatted string

    - #### convertNanosecondTimespanToHumanReadableFormat

          public static String convertNanosecondTimespanToHumanReadableFormat​(long aTimespan,
                                                                              boolean aShortFormat,
                                                                              boolean aLongFormat)

      Converts a duration in nanoseconds to a human-readable, nicely formatted string.
      Parameters:
        `aTimespan` - the timespan in nanoseconds
        `aShortFormat` - if true, a short format for the units is chosen
        `aLongFormat` - if true, a long format for the units is chosen
      Returns:
        the formatted string

    - #### convertTimeDifference

          public static List<org.eclipse.xtext.util.Pair<Long,​TemporalUnit>> convertTimeDifference​(TimeDifference aDifference,
                                                                                                         ValueConverter aValueConverter)

      Converts a `TimeDifference` to a list of `Pair` with value plus `TemporalUnit`. This is not directly converting to a `Duration` because certain units' absolute length depends on the actual date/time (like months and years). Their length can only be evaluated when we know the "current" date/time.

      In case of an overall negative difference, all values are negated on conversion.

      Parameters:
        `aDifference` - the time difference object
        `aValueConverter` - the value converter instance (necessary in case of calculated time difference values)
      Returns:
        the converted duration

    - #### convertTimeSetProgressionFactor

          public static BigDecimal convertTimeSetProgressionFactor​(TimeSet aTimeSet,
                                                                   ValueConverter aValueConverter,
                                                                   ConversionContext aConversionContext)

      Converts the timeset commands' progression factor.
      Parameters:
        `aTimeSet` -
        `aValueConverter` -
      Returns:
      Throws:
        `ParameterUtil.UnresolvableVariableException`
        `UnexecutableException`