public class DateTimeUtils extends Object
Used by the JDBC driver.
TODO: review methods for performance. Due to allocations required, it may be preferable to introduce a "formatter" with the required state.
| Modifier and Type | Class and Description |
|---|---|
static class |
DateTimeUtils.PrecisionTime
|
| Modifier and Type | Field and Description |
|---|---|
static String |
DATE_FORMAT_STRING
The SimpleDateFormat string for ISO dates, "yyyy-MM-dd".
|
static TimeZone |
DEFAULT_ZONE
The Java default time zone.
|
static int |
EPOCH_JULIAN
The julian date of the epoch, 1970-01-01.
|
static TimeZone |
GMT_ZONE
The GMT time zone.
|
static long |
MILLIS_PER_DAY
The number of milliseconds in a day.
|
static long |
MILLIS_PER_HOUR
The number of milliseconds in an hour.
|
static long |
MILLIS_PER_MINUTE
The number of milliseconds in a minute.
|
static long |
MILLIS_PER_SECOND
The number of milliseconds in a second.
|
static String |
TIME_FORMAT_STRING
The SimpleDateFormat string for ISO times, "HH:mm:ss".
|
static String |
TIMESTAMP_FORMAT_STRING
The SimpleDateFormat string for ISO timestamps, "yyyy-MM-dd HH:mm:ss".
|
static Calendar |
ZERO_CALENDAR
Calendar set to the epoch (1970-01-01 00:00:00 UTC).
|
| Modifier and Type | Method and Description |
|---|---|
static void |
checkDateFormat(String pattern)
Checks if the date/time format is valid
|
static int |
dateStringToUnixDate(String s) |
static int |
digitCount(int v) |
static TimeZone |
getTimeZone(Calendar cal)
Gets the active time zone based on a Calendar argument
|
static String |
intervalDayTimeToString(long v,
TimeUnitRange range,
int scale) |
static String |
intervalYearMonthToString(int v,
TimeUnitRange range) |
static SimpleDateFormat |
newDateFormat(String format)
Creates a new date formatter with Farrago specific options.
|
static StringBuilder |
number(StringBuilder buf,
int v,
int n) |
static Calendar |
parseDateFormat(String s,
String pattern,
TimeZone tz)
Parses a string using
SimpleDateFormat and a given pattern. |
static DateTimeUtils.PrecisionTime |
parsePrecisionDateTimeLiteral(String s,
String pattern,
TimeZone tz)
Parses a string using
SimpleDateFormat and a given pattern, and
if present, parses a fractional seconds component. |
static long |
powerX(long a,
long b)
Cheap, unsafe, long power.
|
static long |
timestampStringToUnixDate(String s) |
static int |
timeStringToUnixDate(String v) |
static int |
timeStringToUnixDate(String v,
int start) |
static long |
unixDateCeil(TimeUnitRange range,
long date) |
static long |
unixDateExtract(TimeUnitRange range,
long date) |
static long |
unixDateFloor(TimeUnitRange range,
long date) |
static String |
unixDateToString(int date)
Helper for CAST({date} AS VARCHAR(n)).
|
static long |
unixTimestamp(int year,
int month,
int day,
int hour,
int minute,
int second) |
static long |
unixTimestampCeil(TimeUnitRange range,
long timestamp) |
static long |
unixTimestampFloor(TimeUnitRange range,
long timestamp) |
static String |
unixTimestampToString(long timestamp)
Helper for CAST({timestamp} AS VARCHAR(n)).
|
static String |
unixTimeToString(int time)
Helper for CAST({timestamp} AS VARCHAR(n)).
|
static int |
ymdToJulian(int year,
int month,
int day) |
static int |
ymdToUnixDate(int year,
int month,
int day) |
public static final int EPOCH_JULIAN
public static final String DATE_FORMAT_STRING
public static final String TIME_FORMAT_STRING
public static final String TIMESTAMP_FORMAT_STRING
public static final TimeZone GMT_ZONE
public static final TimeZone DEFAULT_ZONE
public static final long MILLIS_PER_SECOND
public static final long MILLIS_PER_MINUTE
public static final long MILLIS_PER_HOUR
public static final long MILLIS_PER_DAY
This is the modulo 'mask' used when converting TIMESTAMP values to DATE and TIME values.
public static final Calendar ZERO_CALENDAR
public static Calendar parseDateFormat(String s, String pattern, TimeZone tz)
SimpleDateFormat and a given pattern. The
entire string must match the pattern specified.s - string to be parsedpattern - SimpleDateFormat patterntz - time zone in which to interpret string. Defaults to the Java
default time zonepublic static DateTimeUtils.PrecisionTime parsePrecisionDateTimeLiteral(String s, String pattern, TimeZone tz)
SimpleDateFormat and a given pattern, and
if present, parses a fractional seconds component. The fractional seconds
component must begin with a decimal point ('.') followed by numeric
digits. The precision is rounded to a maximum of 3 digits of fractional
seconds precision (to obtain milliseconds).s - string to be parsedpattern - SimpleDateFormat patterntz - time zone in which to interpret string. Defaults to the
local time zonePrecisionTime initialized
with the parsed value, or null if parsing failed. The PrecisionTime
contains a GMT Calendar and a precision.public static TimeZone getTimeZone(Calendar cal)
public static void checkDateFormat(String pattern)
pattern - SimpleDateFormat patternIllegalArgumentException - if the given pattern is invalidpublic static SimpleDateFormat newDateFormat(String format)
format - SimpleDateFormat patternpublic static String unixTimestampToString(long timestamp)
public static String unixTimeToString(int time)
public static String unixDateToString(int date)
public static String intervalYearMonthToString(int v, TimeUnitRange range)
public static StringBuilder number(StringBuilder buf, int v, int n)
public static int digitCount(int v)
public static long powerX(long a,
long b)
public static String intervalDayTimeToString(long v, TimeUnitRange range, int scale)
public static int dateStringToUnixDate(String s)
public static int timeStringToUnixDate(String v)
public static int timeStringToUnixDate(String v, int start)
public static long timestampStringToUnixDate(String s)
public static long unixDateExtract(TimeUnitRange range, long date)
public static long unixTimestampFloor(TimeUnitRange range, long timestamp)
public static long unixDateFloor(TimeUnitRange range, long date)
public static long unixTimestampCeil(TimeUnitRange range, long timestamp)
public static long unixDateCeil(TimeUnitRange range, long date)
public static int ymdToUnixDate(int year,
int month,
int day)
public static int ymdToJulian(int year,
int month,
int day)
public static long unixTimestamp(int year,
int month,
int day,
int hour,
int minute,
int second)
Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.