org.apache.oozie.util
Class DateUtils

java.lang.Object
  extended by org.apache.oozie.util.DateUtils

public class DateUtils
extends Object


Constructor Summary
DateUtils()
           
 
Method Summary
static String convertDateToString(Date date)
          Return the UTC date and time in W3C format down to second (yyyy-MM-ddTHH:mm:ssZ).
static String convertDateToString(long timeStamp)
          Return the UTC date and time in W3C format down to second (yyyy-MM-ddTHH:mm:ssZ).
static Timestamp convertDateToTimestamp(Date d)
          Convert java.util.Date to java.sql.Timestamp
static String formatDateCustom(Date d, String format)
           
static String formatDateUTC(Calendar c)
           
static String formatDateUTC(Date d)
           
static Calendar getCalendar(String dateString)
          Create a Calendar instance for UTC time zone using the specified date.
static Calendar getCalendar(String dateString, TimeZone tz)
          Create a Calendar instance using the specified date and Time zone
static TimeZone getTimeZone(String tzId)
           
static int hoursInDay(Calendar cal)
          This function returns number of hour in a day when given a Calendar with appropriate TZ.
static boolean isDSTChangeDay(Calendar cal)
          Determine whether a specific date is on DST change day
static void moveToEnd(Calendar cal, TimeUnit endOfFlag)
          Move the any date-time to the end of the duration.
static Date parseDateUTC(String s)
           
static Date toDate(Timestamp timestamp)
          Convert java.sql.Timestamp to java.util.Date
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateUtils

public DateUtils()
Method Detail

getTimeZone

public static TimeZone getTimeZone(String tzId)

parseDateUTC

public static Date parseDateUTC(String s)
                         throws Exception
Throws:
Exception

formatDateUTC

public static String formatDateUTC(Date d)
                            throws Exception
Throws:
Exception

formatDateCustom

public static String formatDateCustom(Date d,
                                      String format)
                               throws Exception
Throws:
Exception

formatDateUTC

public static String formatDateUTC(Calendar c)
                            throws Exception
Throws:
Exception

hoursInDay

public static int hoursInDay(Calendar cal)
This function returns number of hour in a day when given a Calendar with appropriate TZ. It consider DST to find the number of hours. Generally it is 24. At some tZ, in one day of a year it is 23 and another day it is 25

Parameters:
cal: - The date for which the number of hours is requested
Returns:
number of hour in that day.

isDSTChangeDay

public static boolean isDSTChangeDay(Calendar cal)
Determine whether a specific date is on DST change day

Parameters:
cal: - Date to know if it is DST change day. Appropriate TZ is specified
Returns:
true , if it DST change date otherwise false

moveToEnd

public static void moveToEnd(Calendar cal,
                             TimeUnit endOfFlag)
Move the any date-time to the end of the duration. If endOfFlag == day, move the date to the end of day (24:00 on the same day or 00:00 on the next day) If endOf Flag = month. move the date to then end of current month Otherwise do nothing

Parameters:
cal - : Date-time needs to be moved to the end
endOfFlag - : day (for end of day) or month (for end of month) or empty

getCalendar

public static Calendar getCalendar(String dateString,
                                   TimeZone tz)
                            throws Exception
Create a Calendar instance using the specified date and Time zone

Parameters:
dateString -
tz - : TimeZone
Returns:
appropriate Calendar object
Throws:
Exception

getCalendar

public static Calendar getCalendar(String dateString)
                            throws Exception
Create a Calendar instance for UTC time zone using the specified date.

Parameters:
dateString -
Returns:
appropriate Calendar object
Throws:
Exception

toDate

public static Date toDate(Timestamp timestamp)
Convert java.sql.Timestamp to java.util.Date

Parameters:
timestamp - java.sql.Timestamp
Returns:
java.util.Date

convertDateToTimestamp

public static Timestamp convertDateToTimestamp(Date d)
Convert java.util.Date to java.sql.Timestamp

Parameters:
d - java.util.Date
Returns:
java.sql.Timestamp

convertDateToString

public static String convertDateToString(Date date)
Return the UTC date and time in W3C format down to second (yyyy-MM-ddTHH:mm:ssZ). i.e.: 1997-07-16T19:20:30Z

Returns:
the formatted time string.

convertDateToString

public static String convertDateToString(long timeStamp)
Return the UTC date and time in W3C format down to second (yyyy-MM-ddTHH:mm:ssZ). i.e.: 1997-07-16T19:20:30Z The input date is a long (Unix Time Stamp)

Returns:
the formatted time string.


Copyright © 2012 Apache Software Foundation. All Rights Reserved.