com.ibm.commerce.utils

Class TimestampHelper

  • java.lang.Object
    • java.util.Date
      • java.sql.Timestamp
        • com.ibm.commerce.utils.TimestampHelper
  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.util.Date>


    public class TimestampHelper
    extends java.sql.Timestamp
    This class contains helper methods for manipulating timestamps.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String COPYRIGHT
      IBM Copyright notice field.
      static int MILLIS_IN_SECOND
      The number of milliseconds in a second (1000).
      static int SQL_TSI_SECOND
      Has a value of 2.
    • Constructor Summary

      Constructors 
      Constructor and Description
      TimestampHelper(int year, int month, int date, int hour, int minute, int second, int nano)
      This is a constructor for this class.
      TimestampHelper(long time)
      This is a constructor for this class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.sql.Timestamp getCurrentTime()
      This method returns the current date and time of the executing system as a timestamp value.
      static java.sql.Timestamp getCurrentTime(ActivityToken aToken)
      This method returns a date.
      static java.lang.String getDateFromTimestamp(java.sql.Timestamp t)
      This method extracts the date portion from the timestamp.
      static java.lang.String getDateFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
      This method extracts the date portion from the timestamp.
      static java.lang.String getDateTimeFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
      This method returns the date and time in a locale-specific format.
      static java.lang.String getDayFromTimestamp(java.sql.Timestamp t)
      This method extracts the day portion from the timestamp.
      static java.lang.String getMonthFromTimestamp(java.sql.Timestamp t)
      This method extracts the month portion from the timestamp.
      static java.lang.String getSQLCurrentTimestamp()
      This method returns the SQL keyword for retrieving current timestamp.
      static java.lang.String getSQLSyntaxTimestampPlusInteger(java.util.List parameters, java.lang.String TimeStampAttribute, java.lang.String IntegerAttribute)
      This method creates a parameterized SQL snippet to add an integer to a timestamp.
      static java.lang.String getSQLSyntaxTimestampPlusInteger(java.lang.String TimeStampAttribute, java.lang.String IntegerAttribute)
      This method creates an SQL snippet to add an integer to a timestamp.
      static java.lang.String getTimeFromTimestamp(java.sql.Timestamp t)
      This method extracts the time portion from the timestamp.
      static java.lang.String getTimeFromTimestampWithSeconds(java.sql.Timestamp t)
      This method extracts the time with second portion from the timestamp.
      static java.lang.String getTimestampString(java.lang.String pattern, java.sql.Timestamp t)
      This method convert a timestamp to its String representation using the input pattern.
      static java.lang.String getTimestampString(java.sql.Timestamp t)
      This method converts a timestamp to its String representation using the pattern defined in the configuration file.
      static java.lang.String getYearFromTimestamp(java.sql.Timestamp t)
      This method extracts the year portion from the timestamp.
      static java.sql.Timestamp now()
      This method returns current date and time from database as a timestamp value.
      static java.sql.Timestamp parseDateTime(java.lang.String date, java.lang.String time)
      This method converts the date (YYYY-MM-DD) and time (hh:mm) into a timestamp.
      static java.sql.Timestamp parseDateTime(java.lang.String year, java.lang.String month, java.lang.String day, java.lang.String time)
      This method converts the date, 3 variables YYYY, MM and DD and time in the form hh:mm into a timestamp.
      static java.sql.Timestamp systemCurrentTimestamp()
      This method returns current time of the executing system as a timestamp value.
      static java.sql.Timestamp timestampAdd(int interval, long numberOfIntervals, java.sql.Timestamp timestamp)
      This method returns the timestamp calculated by adding numberOfIntervals to the timestamp.
      static long timestampDiff(int interval, java.sql.Timestamp timestamp1, java.sql.Timestamp timestamp2)
      This method returns the number of intervals of type interval by which timestamp1 is greater than timestamp2.
      static long timestampDifference(int interval, java.sql.Timestamp timestamp1, java.sql.Timestamp timestamp2)
      This method returns the number of intervals of type interval by which timestamp1 is greater than timestamp2.
      • Methods inherited from class java.sql.Timestamp

        after, before, compareTo, compareTo, equals, equals, from, getNanos, getTime, hashCode, setNanos, setTime, toInstant, toLocalDateTime, toString, valueOf, valueOf
      • Methods inherited from class java.util.Date

        after, before, clone, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTimezoneOffset, getYear, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setYear, toGMTString, toLocaleString, UTC
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM Copyright notice field.
        See Also:
        Constant Field Values
      • SQL_TSI_SECOND

        public static final int SQL_TSI_SECOND
        Has a value of 2.
        See Also:
        Constant Field Values
      • MILLIS_IN_SECOND

        public static final int MILLIS_IN_SECOND
        The number of milliseconds in a second (1000).
        See Also:
        Constant Field Values
    • Constructor Detail

      • TimestampHelper

        public TimestampHelper(int year,
                               int month,
                               int date,
                               int hour,
                               int minute,
                               int second,
                               int nano)
        This is a constructor for this class. It creates a timestamp helper object based on the parameters specified.
        Parameters:
        year - The year.
        month - The month.
        date - The day.
        hour - The hour.
        minute - The minute.
        second - The second.
        nano - The nanosecond.
      • TimestampHelper

        public TimestampHelper(long time)
        This is a constructor for this class. It creates a timestamp helper object based on the given time in long format.
        Parameters:
        time - The time.
    • Method Detail

      • getCurrentTime

        public static java.sql.Timestamp getCurrentTime()
        This method returns the current date and time of the executing system as a timestamp value.
        Returns:
        The current date and time.
      • getCurrentTime

        public static java.sql.Timestamp getCurrentTime(ActivityToken aToken)
        This method returns a date. In preview mode it will return a user-specified preview date. Otherwise, it will return the current date.
        Parameters:
        aToken - An activity token for this request.
        Returns:
        This method returns the preview date if in preview mode and the current date otherwise.
      • getDateFromTimestamp

        public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t)
        This method extracts the date portion from the timestamp. The date will be returned as follows: YYYY-MM-DD.
        Parameters:
        timestamp - The Timestamp object to convert.
        Returns:
        A String representation of the given Timestamp.
      • getDateFromTimestamp

        public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t,
                                                            java.util.Locale locale)
        This method extracts the date portion from the timestamp. The date will be returned in a locale-specific manner.
        Parameters:
        timestamp - The Timestamp object to parse.
        locale - The locale to use for display.
        Returns:
        A String representation of the given timestamp.
      • getDateTimeFromTimestamp

        public static java.lang.String getDateTimeFromTimestamp(java.sql.Timestamp t,
                                                                java.util.Locale locale)
        This method returns the date and time in a locale-specific format.
        Parameters:
        timestamp - The Timestamp object to parse.
        locale - The locale to use for display.
        Returns:
        A String representation of the specified timestamp.
      • getDayFromTimestamp

        public static java.lang.String getDayFromTimestamp(java.sql.Timestamp t)
        This method extracts the day portion from the timestamp.
        Parameters:
        timestamp - The Timestamp object to parse.
        Returns:
        The day of the month from the given timestamp. If the day is less then 10, a 0 will be prefix to the returned value, for example, 1 would be "01".
      • getMonthFromTimestamp

        public static java.lang.String getMonthFromTimestamp(java.sql.Timestamp t)
        This method extracts the month portion from the timestamp.
        Parameters:
        timestamp - The Timestamp object to parse.
        Returns:
        The month of the given timestamp. If the month is less then 10, a 0 will be prefix to the returned value, for example, 1 would be "01".
      • getSQLCurrentTimestamp

        public static java.lang.String getSQLCurrentTimestamp()
        This method returns the SQL keyword for retrieving current timestamp.
        Returns:
        If the Commerce Server is using Oracle as the backend database engine, then "CURRENT_TIMESTAMP" will be returned. Otherwise "CURRENT TIMESTAMP" will be returned.
      • getSQLSyntaxTimestampPlusInteger

        public static java.lang.String getSQLSyntaxTimestampPlusInteger(java.lang.String TimeStampAttribute,
                                                                        java.lang.String IntegerAttribute)
        This method creates an SQL snippet to add an integer to a timestamp. It is returned in the correct syntax depending on DBMS. Creation date: (9/17/2001 3:54:13 PM)
        Parameters:
        TimeStampAttribute - A java.lang.String object.
        IntegerAttribute - A java.lang.String object.
        Returns:
        A java.lang.String object.
      • getSQLSyntaxTimestampPlusInteger

        public static java.lang.String getSQLSyntaxTimestampPlusInteger(java.util.List parameters,
                                                                        java.lang.String TimeStampAttribute,
                                                                        java.lang.String IntegerAttribute)
        This method creates a parameterized SQL snippet to add an integer to a timestamp. It is returned in the correct syntax depending on DBMS. It adds the integer to a list of parameters. Creation date: (9/17/2001 3:54:13 PM)
        Parameters:
        parameters - A list of parameters.
        TimeStampAttribute - A java.lang.String object.
        IntegerAttribute - A java.lang.String object.
        Returns:
        The SQL snippet as a java.lang.String object.
      • getTimeFromTimestamp

        public static java.lang.String getTimeFromTimestamp(java.sql.Timestamp t)
        This method extracts the time portion from the timestamp. The date will be returned as follows: hh:mm in 24 hour form.
        Parameters:
        timestamp - The Timestamp object to parse.
        Returns:
        The String representation of the time contained in the given timestamp.
      • getTimeFromTimestampWithSeconds

        public static java.lang.String getTimeFromTimestampWithSeconds(java.sql.Timestamp t)
        This method extracts the time with second portion from the timestamp. The date will be returned as follows: hh:mm:ss in 24 hour form
        Parameters:
        timestamp - The Timestamp object to parse.
        Returns:
        The String representation of the time contained in the given timestamp.
      • getTimestampString

        public static java.lang.String getTimestampString(java.lang.String pattern,
                                                          java.sql.Timestamp t)
        This method convert a timestamp to its String representation using the input pattern. The default pattern will be returned on error.
        Parameters:
        pattern - The timestamp pattern to be used.
        timestamp - The Timestamp object to parse.
        Returns:
        The String representation of the specified timestamp based on the given pattern.
      • getTimestampString

        public static java.lang.String getTimestampString(java.sql.Timestamp t)
        This method converts a timestamp to its String representation using the pattern defined in the configuration file. If no pattern is defined or if an error occurs, the default pattern will be returned.
        Parameters:
        timestamp - The Timestamp object to parse.
        Returns:
        A String representation of the specified timestamp.
      • getYearFromTimestamp

        public static java.lang.String getYearFromTimestamp(java.sql.Timestamp t)
        This method extracts the year portion from the timestamp.
        Parameters:
        timestamp - The Timestamp object to parse.
        Returns:
        The year contained in the specified timestamp.
      • now

        public static java.sql.Timestamp now()
        This method returns current date and time from database as a timestamp value.
        Returns:
        The current date and time.
      • parseDateTime

        public static java.sql.Timestamp parseDateTime(java.lang.String date,
                                                       java.lang.String time)
        This method converts the date (YYYY-MM-DD) and time (hh:mm) into a timestamp.
        Parameters:
        date - The date to use to create the timestamp.
        time - The time to use to create the timestamp.
        Returns:
        A Timestamp object that represents the given date and time.
      • parseDateTime

        public static java.sql.Timestamp parseDateTime(java.lang.String year,
                                                       java.lang.String month,
                                                       java.lang.String day,
                                                       java.lang.String time)
        This method converts the date, 3 variables YYYY, MM and DD and time in the form hh:mm into a timestamp.
        Parameters:
        year - The year to use to create the timestamp.
        month - The month to use to create the timestamp.
        day - The day to use to create the timestamp.
        time - The time to use to create timestamp
        Returns:
        A Timestamp object that represents the given year, month, day and time.
      • systemCurrentTimestamp

        public static java.sql.Timestamp systemCurrentTimestamp()
        This method returns current time of the executing system as a timestamp value.
        Returns:
        The current date and time.
      • timestampAdd

        public static java.sql.Timestamp timestampAdd(int interval,
                                                      long numberOfIntervals,
                                                      java.sql.Timestamp timestamp)
        This method returns the timestamp calculated by adding numberOfIntervals to the timestamp. Valid values for an interval are the following keywords: SQL_TSI_SECOND.
        Parameters:
        interval - A keyword to represent a unit of time such as second or a minute.
        numberOfIntervals - The number of units of time.
        timestamp - The base timestamp.
        Returns:
        The calculated timestamp.
      • timestampDiff

        public static long timestampDiff(int interval,
                                         java.sql.Timestamp timestamp1,
                                         java.sql.Timestamp timestamp2)
        This method returns the number of intervals of type interval by which timestamp1 is greater than timestamp2. Valid values for an interval are the following keywords: SQL_TSI_SECOND.
        Parameters:
        interval - A keyword to represent a unit of time such as second or a minute.
        timestamp1 - The first timestamp.
        timestamp2 - The second timestamp to subtract from the first one.
        Returns:
        The difference between timestamp1 and timestamp2 in intervals.
      • timestampDifference

        public static long timestampDifference(int interval,
                                               java.sql.Timestamp timestamp1,
                                               java.sql.Timestamp timestamp2)
        This method returns the number of intervals of type interval by which timestamp1 is greater than timestamp2. Valid values for an interval are specified in seconds. So, if the interval required is a day, 86400 is specified.
        Parameters:
        interval - The interval required in seconds
        timestamp1 - A java.sql.Timestamp object.
        timestamp2 - A java.sql.Timestamp object.
        Returns:
        The difference between timestamp1 and timestamp2 in intervals.