com.ibm.commerce.utils
Class TimestampHelper

java.lang.Object
  |
  +--java.util.Date
        |
        +--java.sql.Timestamp
              |
              +--com.ibm.commerce.utils.TimestampHelper
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

public class TimestampHelper
extends java.sql.Timestamp

TimestampHelper class contains helper methods for manipulating timestamps

See Also:
Serialized Form

Field Summary
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
TimestampHelper(int year, int month, int date, int hour, int minute, int second, int nano)
          Creates a timestamp helper object based on the parameters specified.
TimestampHelper(long time)
          Creates the timestamp helper object based on the given time in long format.
 
Method Summary
static java.sql.Timestamp getCurrentTime()
          Returns current date and time of the executing system as a timestamp value.
static java.lang.String getDateFromTimestamp(java.sql.Timestamp t)
          Will extract the date portion from the timestamp The date will be returned as follows YYYY-MM-DD.
static java.lang.String getDateFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
          Will extract the date portion from the timestamp The date will be returned in a locale specific manner.
static java.lang.String getDateTimeFromTimestamp(java.sql.Timestamp t, java.util.Locale locale)
          The date and time will be returned in a locale specific format
static java.lang.String getDayFromTimestamp(java.sql.Timestamp t)
          Will extract the day portion from the timestamp.
static java.lang.String getMonthFromTimestamp(java.sql.Timestamp t)
          Will extract the month portion from the timestamp.
static java.lang.String getSQLCurrentTimestamp()
          Returns the SQL keyword for retrieving current timestamp.
static java.lang.String getSQLSyntaxTimestampPlusInteger(java.lang.String TimeStampAttribute, java.lang.String IntegerAttribute)
          Creates SQL snippet to add an integer to a timestamp.
static java.lang.String getTimeFromTimestamp(java.sql.Timestamp t)
          Will extract the time portion from the timestamp.
static java.lang.String getTimestampString(java.lang.String pattern, java.sql.Timestamp t)
          Convert a timestamp to its string representation using the input pattern.
static java.lang.String getTimestampString(java.sql.Timestamp t)
          Convert a timestamp to its string representation using the pattern defined in the config file.
static java.lang.String getYearFromTimestamp(java.sql.Timestamp t)
          Will extract the year portion from the timestamp.
static java.sql.Timestamp now()
          Returns current date and time from database as a timestamp value.
static java.sql.Timestamp parseDateTime(java.lang.String date, java.lang.String time)
          Will convert 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)
          Will convert the date, 3 vars YYYY, MM and DD and time in the form hh:mm into a timestamp.
static java.sql.Timestamp systemCurrentTimestamp()
          Returns current date and time of the executing system as a timestamp value.
static java.sql.Timestamp timestampAdd(int interval, long numberOfIntervals, java.sql.Timestamp timestamp)
          Returns the timestamp calculated by adding numberOfIntervals intervals to timestamp.
static long timestampDiff(int interval, java.sql.Timestamp timestamp1, java.sql.Timestamp timestamp2)
          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, getNanos, getTime, setNanos, setTime, toString, valueOf
 
Methods inherited from class java.util.Date
after, before, clone, compareTo, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setYear, toGMTString, toLocaleString, UTC
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail
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)
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 nano second.

TimestampHelper

public TimestampHelper(long time)
Creates the timestamp helper object based on the given time in long format.
Parameters:
time - the time.
Method Detail

getCurrentTime

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

getDateFromTimestamp

public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t)
Will extract the date portion from the timestamp The date will be returned as follows YYYY-MM-DD.
Returns:
A string representation of the given timestamp.

getDateFromTimestamp

public static java.lang.String getDateFromTimestamp(java.sql.Timestamp t,
                                                    java.util.Locale locale)
Will extract the date portion from the timestamp The date will be returned in a locale specific manner.
Parameters:
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)
The date and time will be returned in a locale specific format
Parameters:
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)
Will extract the day portion from the timestamp.
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)
Will extract the month portion from the timestamp.
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()
Returns the SQL keyword for retrieving current timestamp.
Returns:
If the Commerce Server is using Oracle as the backend database engine, then "SYSDATE" will be returned. Otherwise "CURRENT TIMESTAMP" will be returned.

getSQLSyntaxTimestampPlusInteger

public static java.lang.String getSQLSyntaxTimestampPlusInteger(java.lang.String TimeStampAttribute,
                                                                java.lang.String IntegerAttribute)
Creates SQL snippet to add an integer to a timestamp. Returns correct syntax depending on DBMS. Creation date: (9/17/2001 3:54:13 PM)
Parameters:
TimeStampAttribute - java.lang.String
IntegerAttribute - java.lang.String
Returns:
java.lang.String

getTimeFromTimestamp

public static java.lang.String getTimeFromTimestamp(java.sql.Timestamp t)
Will extract the time portion from the timestamp. The date will be returned as follows hh:mm in 24 hour form
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)
Convert a timestamp to its string representation using the input pattern. The default pattern will be returned on error.
Parameters:
pattern - the time stamp pattern to be used.
Returns:
The string representation of the specified timestamp based on the given pattern.

getTimestampString

public static java.lang.String getTimestampString(java.sql.Timestamp t)
Convert a timestamp to its string representation using the pattern defined in the config file. If no pattern is defined or if an error occurs. The default pattern will be returned.
Returns:
A string representation of the specified timestamp.

getYearFromTimestamp

public static java.lang.String getYearFromTimestamp(java.sql.Timestamp t)
Will extract the year portion from the timestamp.
Returns:
The year contained in the specified timestamp.

now

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

parseDateTime

public static java.sql.Timestamp parseDateTime(java.lang.String date,
                                               java.lang.String time)
Will convert 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)
Will convert the date, 3 vars 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()
Returns current date and time of the executing system as a timestamp value.
Returns:
The current time.

timestampAdd

public static java.sql.Timestamp timestampAdd(int interval,
                                              long numberOfIntervals,
                                              java.sql.Timestamp timestamp)
Returns the timestamp calculated by adding numberOfIntervals intervals to timestamp. Valid values of interval are the following keywords: SQL_TSI_SECOND.
Parameters:
interval - keyword to represent unit of time such as second, minute.
numberOfIntervals - 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)
Returns the number of intervals of type interval by which timestamp1 is greater than timestamp2. Valid values of interval are the following keywords: SQL_TSI_SECOND.
Parameters:
interval - keyword to represent unit of time such as second, minute.
timestamp1 - the first timestamp.
timestamp2 - the second timestamp to subtract from the first one.
Returns:
The difference between timestamp1 and timestamp2 in interval.