public class TimeUtil extends Object
| Constructor and Description |
|---|
TimeUtil() |
| Modifier and Type | Method and Description |
|---|---|
static Duration |
adjustNanosPrecision(Duration x,
int fsp,
boolean serverRoundFracSecs) |
static LocalDateTime |
adjustNanosPrecision(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 LocalTime |
adjustNanosPrecision(LocalTime x,
int fsp,
boolean serverRoundFracSecs) |
static Timestamp |
adjustNanosPrecision(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 String |
formatNanos(int nanos,
int fsp)
Return a string representation of a fractional seconds part.
|
static String |
formatNanos(int nanos,
int fsp,
boolean truncateTrailingZeros)
Return a string representation of a fractional seconds part.
|
private static String |
getCanonicalDate(String s) |
private static String |
getCanonicalDateTime(String s) |
private static String |
getCanonicalTime(String s) |
static String |
getCanonicalTimeZone(String timezoneStr,
ExceptionInterceptor exceptionInterceptor)
Returns the 'official' Java timezone name for the given timezone
|
static long |
getCurrentTimeNanosOrMillis() |
static String |
getDurationString(Duration x) |
static SimpleDateFormat |
getSimpleDateFormat(SimpleDateFormat cachedSimpleDateFormat,
String pattern,
TimeZone tz)
Get SimpleDateFormat with a default Calendar which TimeZone is replaced with the provided one.
|
static SimpleDateFormat |
getSimpleDateFormat(String pattern,
Calendar cal)
Get SimpleDateFormat where a default Calendar is replaced with a clone of the provided one.
|
static Boolean |
hasFractionalSeconds(Time t) |
private static void |
loadTimeZoneMappings(ExceptionInterceptor exceptionInterceptor)
Loads a properties file that contains all kinds of time zone mappings.
|
static boolean |
nanoTimeAvailable() |
static Object |
parseToDateTimeObject(String s,
MysqlType targetMysqlType) |
static Time |
truncateFractionalSeconds(Time time) |
static Timestamp |
truncateFractionalSeconds(Timestamp timestamp) |
static final TimeZone GMT_TIMEZONE
public static final LocalDate DEFAULT_DATE
public static final LocalTime DEFAULT_TIME
public static final DateTimeFormatter DATE_FORMATTER
public static final DateTimeFormatter TIME_FORMATTER_NO_FRACT_NO_OFFSET
public static final DateTimeFormatter TIME_FORMATTER_WITH_NANOS_NO_OFFSET
public static final DateTimeFormatter TIME_FORMATTER_NO_FRACT_WITH_OFFSET
public static final DateTimeFormatter TIME_FORMATTER_WITH_NANOS_WITH_OFFSET
public static final DateTimeFormatter TIME_FORMATTER_WITH_OPTIONAL_MICROS
public static final DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_NO_OFFSET
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET
public static final DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_OPTIONAL_MICROS
public static final Pattern DATE_LITERAL_WITH_DELIMITERS
public static final Pattern DATE_LITERAL_NO_DELIMITERS
public static final Pattern TIME_LITERAL_WITH_DELIMITERS
public static final Pattern TIME_LITERAL_SHORT6
public static final Pattern TIME_LITERAL_SHORT4
public static final Pattern TIME_LITERAL_SHORT2
public static final Pattern DATETIME_LITERAL_WITH_DELIMITERS
public static final Pattern DATETIME_LITERAL_SHORT14
public static final Pattern DATETIME_LITERAL_SHORT12
public static final Pattern DURATION_LITERAL_WITH_DAYS
public static final Pattern DURATION_LITERAL_NO_DAYS
private static final String TIME_ZONE_MAPPINGS_RESOURCE
private static Properties timeZoneMappings
protected static final Method systemNanoTimeMethod
public static boolean nanoTimeAvailable()
public static long getCurrentTimeNanosOrMillis()
public static String getCanonicalTimeZone(String timezoneStr, ExceptionInterceptor exceptionInterceptor)
timezoneStr - the 'common' timezone nameexceptionInterceptor - exception interceptorpublic static Timestamp adjustNanosPrecision(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 LocalDateTime adjustNanosPrecision(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 LocalTime adjustNanosPrecision(LocalTime x, int fsp, boolean serverRoundFracSecs)
public static Duration adjustNanosPrecision(Duration x, int fsp, boolean serverRoundFracSecs)
public static String formatNanos(int nanos, int fsp)
nanos - fractional seconds valuefsp - required fractional part lengthpublic static 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 SimpleDateFormat getSimpleDateFormat(SimpleDateFormat cachedSimpleDateFormat, String pattern, 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 SimpleDateFormat getSimpleDateFormat(String pattern, 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 Object parseToDateTimeObject(String s, MysqlType targetMysqlType)