org.apache.oozie.util
Class DateUtils

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

public class DateUtils
extends Object

Date utility classes to parse and format datetimes in Oozie expected datetime formats.


Field Summary
static String ISO8601_UTC_MASK
           
static String OOZIE_PROCESSING_TIMEZONE_DEFAULT
           
static String OOZIE_PROCESSING_TIMEZONE_KEY
           
static TimeZone UTC
           
 
Constructor Summary
DateUtils()
           
 
Method Summary
static Timestamp convertDateToTimestamp(Date d)
          Convert java.util.Date to java.sql.Timestamp
static String formatDateCustom(Date d, String format)
          Formats a Date as a string using the specified format mask.
static String formatDateOozieTZ(Calendar c)
          Formats a Calendar as a string in ISO8601 format using Oozie processing timezone.
static String formatDateOozieTZ(Date d)
          Formats a Date as a string in ISO8601 format using Oozie processing timezone.
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 getOozieProcessingTimeZone()
          Returns Oozie processing timezone.
static String getOozieTimeMask()
          Returns Oozie processing datetime mask.
static TimeZone getTimeZone(String tzId)
          Returns the TimeZone for the given timezone ID.
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 parseDateOozieTZ(String s)
          Parses a datetime in ISO8601 format in the Oozie processing timezone.
static Date parseDateUTC(String s)
          Parses a datetime in ISO8601 format in UTC timezone
static void setConf(org.apache.hadoop.conf.Configuration conf)
          Configures the Datetime parsing with Oozie processing timezone.
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
 

Field Detail

UTC

public static final TimeZone UTC

ISO8601_UTC_MASK

public static final String ISO8601_UTC_MASK
See Also:
Constant Field Values

OOZIE_PROCESSING_TIMEZONE_KEY

public static final String OOZIE_PROCESSING_TIMEZONE_KEY
See Also:
Constant Field Values

OOZIE_PROCESSING_TIMEZONE_DEFAULT

public static final String OOZIE_PROCESSING_TIMEZONE_DEFAULT
See Also:
Constant Field Values
Constructor Detail

DateUtils

public DateUtils()
Method Detail

setConf

public static void setConf(org.apache.hadoop.conf.Configuration conf)
Configures the Datetime parsing with Oozie processing timezone.

The OOZIE_PROCESSING_TIMEZONE_KEY property is read and set as the Oozie processing timezone. Valid values for this property are UTC and GMT(+/-)####

Parameters:
conf - Oozie server configuration.

getOozieProcessingTimeZone

public static TimeZone getOozieProcessingTimeZone()
Returns Oozie processing timezone.

Returns:
Oozie processing timezone. The returned timezone is UTC or a GMT(+/-)#### timezone.

getOozieTimeMask

public static String getOozieTimeMask()
Returns Oozie processing datetime mask.

This mask is an ISO8601 datetime mask for the Oozie processing timezone.

Returns:
Oozie processing datetime mask.

getTimeZone

public static TimeZone getTimeZone(String tzId)
Returns the TimeZone for the given timezone ID.

Parameters:
tzId - timezone ID.
Returns:
the TimeZone for the given timezone ID.

parseDateUTC

public static Date parseDateUTC(String s)
                         throws ParseException
Parses a datetime in ISO8601 format in UTC timezone

Parameters:
s - string with the datetime to parse.
Returns:
the corresponding Date instance for the parsed date.
Throws:
ParseException - thrown if the given string was not an ISO8601 UTC value.

parseDateOozieTZ

public static Date parseDateOozieTZ(String s)
                             throws ParseException
Parses a datetime in ISO8601 format in the Oozie processing timezone.

Parameters:
s - string with the datetime to parse.
Returns:
the corresponding Date instance for the parsed date.
Throws:
ParseException - thrown if the given string was not an ISO8601 value for the Oozie processing timezon.

formatDateOozieTZ

public static String formatDateOozieTZ(Date d)
Formats a Date as a string in ISO8601 format using Oozie processing timezone.

Parameters:
d - Date to format.
Returns:
the ISO8601 string for the given date, NULL if the Date instance was NULL

formatDateCustom

public static String formatDateCustom(Date d,
                                      String format)
Formats a Date as a string using the specified format mask.

The format mask must be a SimpleDateFormat valid format mask.

Parameters:
d - Date to format.
Returns:
the string for the given date using the specified format mask, NULL if the Date instance was NULL

formatDateOozieTZ

public static String formatDateOozieTZ(Calendar c)
Formats a Calendar as a string in ISO8601 format using Oozie processing timezone.

Parameters:
c - Calendar to format.
Returns:
the ISO8601 string for the given date, NULL if the Calendar instance was NULL

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


Copyright © 2013 Apache Software Foundation. All Rights Reserved.