Class DateUtil

java.lang.Object
ubic.gemma.core.util.DateUtil

public class DateUtil extends Object
Date helpers.

Ported in-tree from ubic.basecode.util.DateUtil as part of the Phase 3 baseCode util retirement (see BASECODE_DEP_AUDIT.md). Only the three methods actually used by Gemma have been carried over: convertStringToDate(String, String), getRelativeDate(Date, String), and numberOfSecondsBetweenDates(Collection). Dropped: convertDateToString, getDateTime, getTodayDate, and the dead datePattern static.

Author:
pavlidis
  • Constructor Details

    • DateUtil

      public DateUtil()
  • Method Details

    • convertStringToDate

      public static Date convertStringToDate(String aMask, String strDate) throws ParseException
      This method generates a string representation of a date/time in the format you specify on input.
      Parameters:
      aMask - the date pattern the string is in
      strDate - a string representation of a date
      Returns:
      a converted Date object
      Throws:
      ParseException
      See Also:
    • getRelativeDate

      public static Date getRelativeDate(Date date, String dateString)
      Turn a string like '-7d' into the date equivalent to "seven days ago". Supports 'd' for day, 'h' for hour, 'm' for minutes, "M" for months and "y" for years. Start with a '-' to indicate times in the past ('+' is not necessary for future). Values must be integers.
      Parameters:
      date - to be added/subtracted to
      Returns:
      Date relative to 'now' as modified by the input date string.
    • numberOfSecondsBetweenDates

      public static long numberOfSecondsBetweenDates(Collection<Date> dates)
      Compute the number of seconds spanned by the given dates. If no or a single date is provided, returns 0.