com.ibm.tivoli.maximo.skd.common.util

Class DateTimeUtility

  • java.lang.Object
    • com.ibm.tivoli.maximo.skd.common.util.DateTimeUtility


  • public class DateTimeUtility
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor and Description
      DateTimeUtility() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.util.Date addDays(java.util.Date date, int plusDays)
      Add a number of days to a date.
      static java.util.Date addHours(java.util.Date date, double hours)
      Add a number of hours to a date.
      static java.util.Date addTime(java.util.Date date, java.util.Date dateTime)
      Adds the time portion of a given date to another one.
      static ilog.views.gantt.IlvTimeInterval centerDuration(ilog.views.gantt.IlvTimeInterval ti, ilog.views.gantt.IlvDuration dur)
      Centers the time interval inside the duration
      static java.util.Date convertDateToUserTimezone(java.util.Date d, java.util.Locale userLocale, java.util.TimeZone userTimeZone)
      Returns the date in user timezone and locale
      static int convertToMinutes(double hours) 
      static double durationBetweenTwoDates(java.util.Date startTime, java.util.Date endTime)
      Calculate the duration between two dates.
      static java.lang.String formatDate(java.util.Date date)
      Formats a given date that according to the U.S.
      static java.util.Calendar getLastHourMinuteForDate(java.util.Calendar cal) 
      static java.util.Date getLastHourMinuteForDate(java.util.Date date) 
      static int getMinutes(java.util.Date date)
      Convenience method for extracting just the Minutes from a Date object
      static java.util.Date parseDate(java.lang.String format, java.lang.String date) 
      static java.util.Date returnEarliest(java.util.Date date1, java.util.Date date2) 
      static java.util.Date returnLatest(java.util.Date date1, java.util.Date date2) 
      static java.util.Date roundMinutes(java.util.Date in, int minuteBlock)
      Rounds a Date to the nearest Minute block using default RoundingMode of HALF_UP.
      static java.util.Date roundMinutes(java.util.Date in, int minuteBlock, java.math.RoundingMode roundingMode)
      Rounds a Date to the nearest Minute block while accounting for the RoundingMode.
      static int timeDiff(java.util.Date date1, java.util.Date date2) 
      static int timeDiffInDays(java.util.Date date1, java.util.Date date2)
      Time difference(in days) between date1 and date2 in days.
      static java.util.Calendar trimToDay(java.util.Calendar calendar)
      Trims a Calendar date to the start of the day
      static java.util.Date trimToDay(java.util.Date in)
      Trims a Date to the start of the day
      static java.util.Date trimToHourMinute(java.util.Date in)
      Trims a Date to the start of the day
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DateTimeUtility

        public DateTimeUtility()
    • Method Detail

      • roundMinutes

        public static java.util.Date roundMinutes(java.util.Date in,
                                                  int minuteBlock)
        Rounds a Date to the nearest Minute block using default RoundingMode of HALF_UP.
        Parameters:
        in - Date
        minuteBlock - Minute block, 5, 10, 15, 20 or 30, 60
        Returns:
        new Date instance rounded to the nearest block of time
      • roundMinutes

        public static java.util.Date roundMinutes(java.util.Date in,
                                                  int minuteBlock,
                                                  java.math.RoundingMode roundingMode)
        Rounds a Date to the nearest Minute block while accounting for the RoundingMode. HALF_UP means that times that are exactly half of the minute block will be rounded up. HALF_DOWN means that times that are exactly half of the minuteBlock will be rounded down. For example, if the minute block is 10 and the time has 5 minutes, then the time will be rounded to 10 when HALF_UP and 0 when HALF_DOWN.
        Parameters:
        in - Date
        minuteBlock - Minute block, 5, 10, 15, 20 or 30, 60
        Returns:
        new Date instance rounded to the nearest block of time
      • trimToDay

        public static java.util.Date trimToDay(java.util.Date in)
        Trims a Date to the start of the day
        Parameters:
        in - Date
        Returns:
        Date trimmed to the start of the day
      • trimToDay

        public static java.util.Calendar trimToDay(java.util.Calendar calendar)
        Trims a Calendar date to the start of the day
        Parameters:
        calendar - date
        Returns:
        Same calendar instance that was passed in, but trimmed.
      • trimToHourMinute

        public static java.util.Date trimToHourMinute(java.util.Date in)
        Trims a Date to the start of the day
        Parameters:
        in - Date
        Returns:
        Date trimmed to the start of the day
      • getMinutes

        public static int getMinutes(java.util.Date date)
        Convenience method for extracting just the Minutes from a Date object
        Parameters:
        date - Date object
        Returns:
        minutes
      • centerDuration

        public static ilog.views.gantt.IlvTimeInterval centerDuration(ilog.views.gantt.IlvTimeInterval ti,
                                                                      ilog.views.gantt.IlvDuration dur)
        Centers the time interval inside the duration
        Parameters:
        ti -
        dur -
        Returns:
      • addDays

        public static java.util.Date addDays(java.util.Date date,
                                             int plusDays)
        Add a number of days to a date. return the new date
        Parameters:
        date -
        days - to add
        Returns:
        date
      • addTime

        public static java.util.Date addTime(java.util.Date date,
                                             java.util.Date dateTime)
        Adds the time portion of a given date to another one.
        Parameters:
        date -
        dateTime -
        Returns:
      • timeDiff

        public static int timeDiff(java.util.Date date1,
                                   java.util.Date date2)
      • timeDiffInDays

        public static int timeDiffInDays(java.util.Date date1,
                                         java.util.Date date2)
        Time difference(in days) between date1 and date2 in days. The other parts of the dates are ignored
      • convertToMinutes

        public static int convertToMinutes(double hours)
      • addHours

        public static java.util.Date addHours(java.util.Date date,
                                              double hours)
        Add a number of hours to a date. return the new date
      • formatDate

        public static java.lang.String formatDate(java.util.Date date)
        Formats a given date that according to the U.S. standards.
        Parameters:
        date -
        Returns:
      • parseDate

        public static java.util.Date parseDate(java.lang.String format,
                                               java.lang.String date)
      • durationBetweenTwoDates

        public static double durationBetweenTwoDates(java.util.Date startTime,
                                                     java.util.Date endTime)
        Calculate the duration between two dates.
        Parameters:
        startDate -
        endDate -
        Returns:
        duration
        Throws:
        java.lang.Exception
      • convertDateToUserTimezone

        public static java.util.Date convertDateToUserTimezone(java.util.Date d,
                                                               java.util.Locale userLocale,
                                                               java.util.TimeZone userTimeZone)
        Returns the date in user timezone and locale
        Parameters:
        l -
        tz -
        Returns:
        Date
        Throws:
        java.rmi.RemoteException
      • getLastHourMinuteForDate

        public static java.util.Calendar getLastHourMinuteForDate(java.util.Calendar cal)
      • getLastHourMinuteForDate

        public static java.util.Date getLastHourMinuteForDate(java.util.Date date)
      • returnEarliest

        public static java.util.Date returnEarliest(java.util.Date date1,
                                                    java.util.Date date2)
      • returnLatest

        public static java.util.Date returnLatest(java.util.Date date1,
                                                  java.util.Date date2)