Modifier and Type | Field and Description |
---|---|
static String |
ISO8601_UTC_MASK |
static String |
OOZIE_PROCESSING_TIMEZONE_DEFAULT |
static String |
OOZIE_PROCESSING_TIMEZONE_KEY |
static TimeZone |
UTC |
Constructor and Description |
---|
DateUtils() |
Modifier and Type | Method and Description |
---|---|
static Timestamp |
convertDateToTimestamp(Date d)
Convert java.util.Date to java.sql.Timestamp
|
static String |
formatDate(Calendar c)
Formats a
Calendar as a string in ISO8601 format without adjusting its timezone. |
static String |
formatDateCustom(Date d,
String format)
Formats a
Date as a string using the specified format mask. |
static String |
formatDateEpoch(Date d,
Boolean millis)
Formats a
Date as a string containing the seconds (or millis) since the Unix epoch (Jan 1, 1970). |
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
|
public static final String ISO8601_UTC_MASK
public static final String OOZIE_PROCESSING_TIMEZONE_KEY
public static final String OOZIE_PROCESSING_TIMEZONE_DEFAULT
public DateUtils()
public static void setConf(org.apache.hadoop.conf.Configuration conf)
The OOZIE_PROCESSING_TIMEZONE_KEY
property is read and set as the Oozie processing timezone.
Valid values for this property are UTC
and GMT(+/-)####
conf
- Oozie server configuration.public static TimeZone getOozieProcessingTimeZone()
UTC
or a GMT(+/-)####
timezone.public static String getOozieTimeMask()
This mask is an ISO8601 datetime mask for the Oozie processing timezone.
public static TimeZone getTimeZone(String tzId)
TimeZone
for the given timezone ID.tzId
- timezone ID.TimeZone
for the given timezone ID.public static Date parseDateUTC(String s) throws ParseException
s
- string with the datetime to parse.Date
instance for the parsed date.ParseException
- thrown if the given string was not an ISO8601 UTC value.public static Date parseDateOozieTZ(String s) throws ParseException
s
- string with the datetime to parse.Date
instance for the parsed date.ParseException
- thrown if the given string was not an ISO8601 value for the Oozie processing timezon.public static String formatDateOozieTZ(Date d)
Date
as a string in ISO8601 format using Oozie processing timezone.public static String formatDateCustom(Date d, String format)
Date
as a string using the specified format mask.
The format mask must be a SimpleDateFormat
valid format mask.
d
- Date
to format.format
- the SimpleDateFormat
format mask to useNULL
if the Date
instance was NULL
public static String formatDateEpoch(Date d, Boolean millis)
Date
as a string containing the seconds (or millis) since the Unix epoch (Jan 1, 1970).
The format mask must be a SimpleDateFormat
valid format mask
public static String formatDateOozieTZ(Calendar c)
Calendar
as a string in ISO8601 format using Oozie processing timezone.public static String formatDate(Calendar c)
Calendar
as a string in ISO8601 format without adjusting its timezone. However, the mask will still
ensure that the returned date is in the Oozie processing timezone.public static int hoursInDay(Calendar cal)
cal
- The date for which the number of hours is requestedpublic static boolean isDSTChangeDay(Calendar cal)
cal
- Date to know if it is DST change day. Appropriate TZ is specifiedpublic static void moveToEnd(Calendar cal, TimeUnit endOfFlag)
cal
- : Date-time needs to be moved to the endendOfFlag
- : day (for end of day) or month (for end of month) or emptypublic static Calendar getCalendar(String dateString, TimeZone tz) throws Exception
dateString
- the datetz
- : TimeZoneException
- if the date can't be parsedpublic static Calendar getCalendar(String dateString) throws Exception
dateString
- the dateException
- if the date can't be parsedpublic static Date toDate(Timestamp timestamp)
timestamp
- java.sql.Timestamppublic static Timestamp convertDateToTimestamp(Date d)
d
- java.util.DateCopyright © 2018 Apache Software Foundation. All rights reserved.