Class TravelDateUtils

java.lang.Object
de.hybris.platform.travelservices.utils.TravelDateUtils

public final class TravelDateUtils extends Object
Class which provides Date utility methods
  • Method Details

    • convertStringDateToDate

      public static Date convertStringDateToDate(String date, String pattern)
      Method takes a String dateTime and pattern and returns a Date object. The method will return null if parsing fails.
      Parameters:
      date - the String dateTime to be converted
      pattern - the pattern
      Returns:
      Date
    • convertStringDateToDate

      public static Date convertStringDateToDate(String date, String pattern, String zoneId)
      Method takes a String dateTime and pattern and returns a Date object. The method will return null if parsing fails. The default zone ID considered will be UTC
      Parameters:
      date - the String dateTime to be converted
      pattern - the pattern
      zoneId - the zone id
      Returns:
      Date
    • convertDateToStringDate

      public static String convertDateToStringDate(Date date, String pattern)
      Method takes a Date and return a string representation based on the pattern.
      Parameters:
      date - the Date to be converted
      pattern - the pattern
      Returns:
      String
    • addHours

      public static Date addHours(Date date, int hours)
      Increase the hours in the Date by the specified amount
      Parameters:
      date - the Date object to increment by x hours
      hours - the number of hours to increment by
      Returns:
      Date date
    • convertInstantToXMLGregorianCalendar

      public static XMLGregorianCalendar convertInstantToXMLGregorianCalendar(Instant paymentTimeLimit) throws DatatypeConfigurationException
      Convert instant to xml gregorian calendar xml gregorian calendar.
      Parameters:
      paymentTimeLimit - the payment time limit
      Returns:
      the xml gregorian calendar
      Throws:
      DatatypeConfigurationException - the datatype configuration exception
    • addHours

      public static Instant addHours(Instant date, long hours)
      Add hours instant.
      Parameters:
      date - the date
      hours - the hours
      Returns:
      the instant
    • isSameDate

      public static boolean isSameDate(Date date1, Date date2)
      Check to see if two dates are the same
      Parameters:
      date1 - the date to compare
      date2 - the date to be compared with
      Returns:
      true if dates are the same
    • addDays

      public static Date addDays(Date date, int amount)
      Method to increment the date by the given number of days
      Parameters:
      date - the date to increment
      amount - the number of days to increment by
      Returns:
      incremented date
    • addMonths

      public static Date addMonths(Date date, int amount)
      Method to increment the date by the given number of months
      Parameters:
      date - the date to increment
      amount - the number of months to increment by
      Returns:
      incremented date
    • getYearsBetweenDates

      public static long getYearsBetweenDates(Date startDate, Date endDate)
      Method to find the difference in years between two dates
      Parameters:
      startDate - the start date
      endDate - the end date
      Returns:
      difference in years
    • getUtcZonedDateTime

      public static ZonedDateTime getUtcZonedDateTime(Date date, ZoneId zoneId)
      Method to get the ZoneDateTime with the UTC time-zone given a Date and its ZoneId.
      Parameters:
      date - the date to be converted in the UTC ZonedDateTime
      zoneId - the zoneId of the date
      Returns:
      the ZonedDateTime with the UTC time-zone.
    • getZonedDateTime

      public static ZonedDateTime getZonedDateTime(Date date, ZoneId zoneId)
      Method to get the ZonedDateTime object from a date and its zoneId.
      Parameters:
      date - the date to be converted in a ZonedDateTime
      zoneId - the zoneId of the date
      Returns:
      the ZonedDateTime calculated from the date and its zoneId.
    • isBefore

      public static boolean isBefore(Date date1, ZoneId zoneId1, Date date2, ZoneId zoneId2)
      Check if date1 is before date2 based on the their UTC time.
      Parameters:
      date1 - the date to compare
      zoneId1 - the zoneId of date1
      date2 - the date to be compared with
      zoneId2 - the zoneId of date2
      Returns:
      true if date1 is before date2 based on their UTC time, false otherwise.
    • isAfter

      public static boolean isAfter(Date date1, ZoneId zoneId1, Date date2, ZoneId zoneId2)
      Check if date1 is after date2 based on the their UTC time.
      Parameters:
      date1 - the date to compare
      zoneId1 - the zoneId of date1
      date2 - the date to be compared with
      zoneId2 - the zoneId of date2
      Returns:
      true if date1 is after date2 based on their UTC time, false otherwise.
    • getDaysBetweenDates

      public static long getDaysBetweenDates(Date startDate, Date endDate)
      Gets days between dates.
      Parameters:
      startDate - the start date
      endDate - the end date
      Returns:
      the days between dates
    • getDateWithTime

      public static Date getDateWithTime(Date date, String time, String pattern)
      Sets hours, minutes and period in a date and returns the updated date
      Parameters:
      date - the date
      time - the time
      pattern - the pattern
      Returns:
      date with time
    • getDate

      public static Date getDate(String date, String pattern)
      Returns a date object based the String, formatted according to the pattern.
      Parameters:
      date - the date
      pattern - the pattern
      Returns:
      date date
    • getTimeForDate

      public static String getTimeForDate(Date date, String pattern)
      Returns a time based on Date, formatted according to the pattern.
      Parameters:
      date - the date with time
      pattern - the pattern
      Returns:
      time time for date
    • getValidDates

      public static List<Date> getValidDates(String cronJobExpression, Date fromDate, Date toDate)
      Returns a list of dates from 'fromDate' to 'toDate'(both dates excluded) based on cronJobExpression.
      Parameters:
      cronJobExpression - the cronJobExpression
      fromDate - the date to be used as a starting point reference for calculation of valid dates
      toDate - the date to be used as a ending point reference for calculation of valid dates
      Returns:
      time valid dates
    • isSameTime

      public static boolean isSameTime(Date departureTime1, Date departureTime2)
      Returns true if the time component of two date corresponds, false otherwise
      Parameters:
      departureTime1 - the first date to compare
      departureTime2 - the second date to compare
      Returns:
      boolean boolean
    • isBetweenDates

      public static boolean isBetweenDates(Date dateToCheck, Date startDate, Date endDate)
      Returns true if date belongs to the interval (startDate, endDate)
      Parameters:
      dateToCheck - date to check
      startDate - lower limit
      endDate - upper limit
      Returns:
      boolean boolean
    • dateToXMLGregorianCalendar

      public static XMLGregorianCalendar dateToXMLGregorianCalendar(Date date)
      Date to xml gregorian calendar.SimpleDateFormat
      Parameters:
      date - the date
      Returns:
      xml gregorian calendar
    • convertToISODuration

      public static String convertToISODuration(Long duration)
      Convert the milliseconds to ISO-8601 representation
      Parameters:
      duration - the duration
      Returns:
      string string
    • createDateFromIsoDateFormat

      public static Date createDateFromIsoDateFormat(String dateParameter, String pattern)
      Returns a date object based the String, formatted according to the pattern.
      Parameters:
      dateParameter - the dateParameter
      pattern - the pattern
      Returns:
      the date from param
    • convertStringDateToGivenFormat

      public static String convertStringDateToGivenFormat(String inputDateString, String dateFormat)
      Returns a date String , formatted into given Format.
      Parameters:
      inputDateString - the input date string
      dateFormat - the date format
      Returns:
      the Formatted Date String
    • convertDateToGivenTimeOffset

      public static String convertDateToGivenTimeOffset(Date inputDate, ZoneId inputZone)
      Sets a date Object to given ZoneOffset.
      Parameters:
      inputDate - the input date
      inputZone - the input zone
      Returns:
      the Offset Date String