public class TimeUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.time.format.DateTimeFormatter |
DATE_FORMATTER |
static java.util.regex.Pattern |
DATE_LITERAL_NO_DELIMITERS |
static java.util.regex.Pattern |
DATE_LITERAL_WITH_DELIMITERS |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_NO_FRACT_NO_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET |
static java.time.format.DateTimeFormatter |
DATETIME_FORMATTER_WITH_OPTIONAL_MICROS |
static java.util.regex.Pattern |
DATETIME_LITERAL_SHORT12 |
static java.util.regex.Pattern |
DATETIME_LITERAL_SHORT14 |
static java.util.regex.Pattern |
DATETIME_LITERAL_WITH_DELIMITERS |
static java.time.LocalDate |
DEFAULT_DATE |
static java.time.LocalTime |
DEFAULT_TIME |
static java.util.regex.Pattern |
DURATION_LITERAL_NO_DAYS |
static java.util.regex.Pattern |
DURATION_LITERAL_WITH_DAYS |
(package private) static java.util.TimeZone |
GMT_TIMEZONE |
protected static java.lang.reflect.Method |
systemNanoTimeMethod |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_NO_FRACT_NO_OFFSET |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_NO_FRACT_WITH_OFFSET |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_WITH_NANOS_NO_OFFSET |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_WITH_NANOS_WITH_OFFSET |
static java.time.format.DateTimeFormatter |
TIME_FORMATTER_WITH_OPTIONAL_MICROS |
static java.util.regex.Pattern |
TIME_LITERAL_SHORT2 |
static java.util.regex.Pattern |
TIME_LITERAL_SHORT4 |
static java.util.regex.Pattern |
TIME_LITERAL_SHORT6 |
static java.util.regex.Pattern |
TIME_LITERAL_WITH_DELIMITERS |
private static java.lang.String |
TIME_ZONE_MAPPINGS_RESOURCE |
private static java.util.Properties |
timeZoneMappings |
| Constructor and Description |
|---|
TimeUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.time.Duration |
adjustNanosPrecision(java.time.Duration x,
int fsp,
boolean serverRoundFracSecs) |
static java.time.LocalDateTime |
adjustNanosPrecision(java.time.LocalDateTime x,
int fsp,
boolean serverRoundFracSecs)
Return a new LocalDateTime object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.
|
static java.time.LocalTime |
adjustNanosPrecision(java.time.LocalTime x,
int fsp,
boolean serverRoundFracSecs) |
static java.sql.Timestamp |
adjustNanosPrecision(java.sql.Timestamp ts,
int fsp,
boolean serverRoundFracSecs)
Return a new Timestamp object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.
|
static java.lang.String |
formatNanos(int nanos,
int fsp)
Return a string representation of a fractional seconds part.
|
static java.lang.String |
formatNanos(int nanos,
int fsp,
boolean truncateTrailingZeros)
Return a string representation of a fractional seconds part.
|
private static java.lang.String |
getCanonicalDate(java.lang.String s) |
private static java.lang.String |
getCanonicalDateTime(java.lang.String s) |
private static java.lang.String |
getCanonicalTime(java.lang.String s) |
static java.lang.String |
getCanonicalTimeZone(java.lang.String timezoneStr,
ExceptionInterceptor exceptionInterceptor)
Returns the 'official' Java timezone name for the given timezone
|
static long |
getCurrentTimeNanosOrMillis() |
static java.lang.String |
getDurationString(java.time.Duration x) |
static java.text.SimpleDateFormat |
getSimpleDateFormat(java.text.SimpleDateFormat cachedSimpleDateFormat,
java.lang.String pattern,
java.util.TimeZone tz)
Get SimpleDateFormat with a default Calendar which TimeZone is replaced with the provided one.
|
static java.text.SimpleDateFormat |
getSimpleDateFormat(java.lang.String pattern,
java.util.Calendar cal)
Get SimpleDateFormat where a default Calendar is replaced with a clone of the provided one.
|
static java.lang.Boolean |
hasFractionalSeconds(java.sql.Time t) |
private static void |
loadTimeZoneMappings(ExceptionInterceptor exceptionInterceptor)
Loads a properties file that contains all kinds of time zone mappings.
|
static boolean |
nanoTimeAvailable() |
static java.lang.Object |
parseToDateTimeObject(java.lang.String s,
MysqlType targetMysqlType) |
static java.sql.Time |
truncateFractionalSeconds(java.sql.Time time) |
static java.sql.Timestamp |
truncateFractionalSeconds(java.sql.Timestamp timestamp) |
static final java.util.TimeZone GMT_TIMEZONE
public static final java.time.LocalDate DEFAULT_DATE
public static final java.time.LocalTime DEFAULT_TIME
public static final java.time.format.DateTimeFormatter DATE_FORMATTER
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_NO_FRACT_NO_OFFSET
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_NANOS_NO_OFFSET
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_NO_FRACT_WITH_OFFSET
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_NANOS_WITH_OFFSET
public static final java.time.format.DateTimeFormatter TIME_FORMATTER_WITH_OPTIONAL_MICROS
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_NO_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET
public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER_WITH_OPTIONAL_MICROS
public static final java.util.regex.Pattern DATE_LITERAL_WITH_DELIMITERS
public static final java.util.regex.Pattern DATE_LITERAL_NO_DELIMITERS
public static final java.util.regex.Pattern TIME_LITERAL_WITH_DELIMITERS
public static final java.util.regex.Pattern TIME_LITERAL_SHORT6
public static final java.util.regex.Pattern TIME_LITERAL_SHORT4
public static final java.util.regex.Pattern TIME_LITERAL_SHORT2
public static final java.util.regex.Pattern DATETIME_LITERAL_WITH_DELIMITERS
public static final java.util.regex.Pattern DATETIME_LITERAL_SHORT14
public static final java.util.regex.Pattern DATETIME_LITERAL_SHORT12
public static final java.util.regex.Pattern DURATION_LITERAL_WITH_DAYS
public static final java.util.regex.Pattern DURATION_LITERAL_NO_DAYS
private static final java.lang.String TIME_ZONE_MAPPINGS_RESOURCE
private static java.util.Properties timeZoneMappings
protected static final java.lang.reflect.Method systemNanoTimeMethod
public static boolean nanoTimeAvailable()
public static long getCurrentTimeNanosOrMillis()
public static java.lang.String getCanonicalTimeZone(java.lang.String timezoneStr,
ExceptionInterceptor exceptionInterceptor)
timezoneStr - the 'common' timezone nameexceptionInterceptor - exception interceptorpublic static java.sql.Timestamp adjustNanosPrecision(java.sql.Timestamp ts,
int fsp,
boolean serverRoundFracSecs)
ts - an original Timestamp object, not modified by this methodfsp - value in the range from 0 to 6 specifying fractional seconds precisionserverRoundFracSecs - Flag indicating whether rounding or truncation occurs on server when inserting a TIME, DATE, or TIMESTAMP value with a fractional seconds part
into a column having the same type but fewer fractional digits: true means rounding, false means truncation. The proper value should be
detected by analyzing sql_mode server variable for TIME_TRUNCATE_FRACTIONAL presence.public static java.time.LocalDateTime adjustNanosPrecision(java.time.LocalDateTime x,
int fsp,
boolean serverRoundFracSecs)
x - an original LocalDateTime object, not modified by this methodfsp - value in the range from 0 to 6 specifying fractional seconds precisionserverRoundFracSecs - Flag indicating whether rounding or truncation occurs on server when inserting a TIME, DATE, or TIMESTAMP value with a fractional seconds part
into a column having the same type but fewer fractional digits: true means rounding, false means truncation. The proper value should be
detected by analyzing sql_mode server variable for TIME_TRUNCATE_FRACTIONAL presence.public static java.time.LocalTime adjustNanosPrecision(java.time.LocalTime x,
int fsp,
boolean serverRoundFracSecs)
public static java.time.Duration adjustNanosPrecision(java.time.Duration x,
int fsp,
boolean serverRoundFracSecs)
public static java.lang.String formatNanos(int nanos,
int fsp)
nanos - fractional seconds valuefsp - required fractional part lengthpublic static java.lang.String formatNanos(int nanos,
int fsp,
boolean truncateTrailingZeros)
nanos - fractional seconds valuefsp - required fractional part lengthtruncateTrailingZeros - whether to remove trailing zero characters in a fractional part after formattingprivate static void loadTimeZoneMappings(ExceptionInterceptor exceptionInterceptor)
exceptionInterceptor - exception interceptorpublic static java.sql.Timestamp truncateFractionalSeconds(java.sql.Timestamp timestamp)
public static java.sql.Time truncateFractionalSeconds(java.sql.Time time)
public static java.lang.Boolean hasFractionalSeconds(java.sql.Time t)
public static java.text.SimpleDateFormat getSimpleDateFormat(java.text.SimpleDateFormat cachedSimpleDateFormat,
java.lang.String pattern,
java.util.TimeZone tz)
Note: The SimpleDateFormat object returned by this method contains a default Calendar with an altered TimeZone. It's safe to cache it between this method calls because the Calendar object itself is not altered.
cachedSimpleDateFormat - existing SimpleDateFormat to use instead of creating a new onepattern - format patterntz - TimeZone object replacing the default oneSimpleDateFormat objectpublic static java.text.SimpleDateFormat getSimpleDateFormat(java.lang.String pattern,
java.util.Calendar cal)
Note: Don't cache the SimpleDateFormat object returned by this method. Other methods could rely on assumption that the cached SimpleDateFormat has a
default Calendar and that it is safe to change only it's time zone (see getSimpleDateFormat(SimpleDateFormat, String, TimeZone).
pattern - format patterncal - Calendar object which clone is replacing the default CalendarSimpleDateFormat objectpublic static java.lang.Object parseToDateTimeObject(java.lang.String s,
MysqlType targetMysqlType)
private static java.lang.String getCanonicalDate(java.lang.String s)
private static java.lang.String getCanonicalTime(java.lang.String s)
private static java.lang.String getCanonicalDateTime(java.lang.String s)
public static java.lang.String getDurationString(java.time.Duration x)