Top Description Fields Constructors Methods
com.mysql.cj.util

public Class TimeUtil

extends Object
Class Inheritance
Imports
java.io.IOException, java.lang.reflect.InvocationTargetException, .Method, java.sql.Time, .Timestamp, java.text.SimpleDateFormat, java.time.Duration, .LocalDate, .LocalDateTime, .LocalTime, java.time.format.DateTimeFormatter, .DateTimeFormatterBuilder, java.time.temporal.ChronoField, java.util.Calendar, .Locale, .Properties, .TimeZone, java.util.concurrent.locks.Lock, .ReentrantLock, java.util.regex.Pattern, com.mysql.cj.Messages, .MysqlType, com.mysql.cj.exceptions.ExceptionFactory, .ExceptionInterceptor, .InvalidConnectionAttributeException, .WrongArgumentException

Time zone conversion routines and other time related methods

Field Summary

Modifier and TypeField and Description
public static final DateTimeFormatter
public static final Pattern
public static final Pattern
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final Pattern
public static final Pattern
public static final Pattern
public static final LocalDate
public static final LocalTime
public static final Pattern
public static final Pattern
pack-priv static final TimeZone
pack-priv static final Lock
protected static final Method
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final DateTimeFormatter
public static final Pattern
public static final Pattern
public static final Pattern
public static final Pattern
private static final String
private static Properties

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Timestamp

Returns:

A new Timestamp object cloned from the original one and then rounded or truncated according to required fsp value
adjustNanosPrecision
(Timestamp
an original Timestamp object, not modified by this method
ts
,
int
value in the range from 0 to 6 specifying fractional seconds precision
fsp
,
boolean
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.
serverRoundFracSecs
)

Return a new Timestamp object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.

public static LocalDateTime

Returns:

A new LocalDateTime object cloned from the original one and then rounded or truncated according to required fsp value
adjustNanosPrecision
(LocalDateTime
an original LocalDateTime object, not modified by this method
x
,
int
value in the range from 0 to 6 specifying fractional seconds precision
fsp
,
boolean
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.
serverRoundFracSecs
)

Return a new LocalDateTime object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.

public static LocalTime
adjustNanosPrecision(LocalTime x, int fsp, boolean serverRoundFracSecs)

public static Duration
adjustNanosPrecision(Duration x, int fsp, boolean serverRoundFracSecs)

public static String

Returns:

fractional seconds part as a string
formatNanos
(int
fractional seconds value
nanos
,
int
required fractional part length
fsp
)

Return a string representation of a fractional seconds part.

public static String

Returns:

fractional seconds part as a string
formatNanos
(int
fractional seconds value
nanos
,
int
required fractional part length
fsp
,
boolean
whether to remove trailing zero characters in a fractional part after formatting
truncateTrailingZeros
)

Return a string representation of a fractional seconds part.

private static String
private static String
private static String
public static String

Returns:

the Java timezone name for the given timezone
getCanonicalTimeZone
(String
the 'common' timezone name
timezoneStr
,
ExceptionInterceptor
exception interceptor
exceptionInterceptor
)

Returns the 'official' Java timezone name for the given timezone

public static long
public static String
public static SimpleDateFormat

Returns:

SimpleDateFormat object
getSimpleDateFormat
(SimpleDateFormat
existing SimpleDateFormat to use instead of creating a new one
cachedSimpleDateFormat
,
String
format pattern
pattern
,
TimeZone
TimeZone object replacing the default one
tz
)

Get SimpleDateFormat with a default Calendar which TimeZone is replaced with the provided one.

public static SimpleDateFormat

Returns:

SimpleDateFormat object
getSimpleDateFormat
(String
format pattern
pattern
,
Calendar
Calendar object which clone is replacing the default Calendar
cal
)

Get SimpleDateFormat where a default Calendar is replaced with a clone of the provided one.

public static Boolean
private static void
loadTimeZoneMappings(ExceptionInterceptor
exception interceptor
exceptionInterceptor
)

Loads a properties file that contains all kinds of time zone mappings.

public static boolean
public static Object
public static Timestamp
public static Time
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DATE_FORMATTERback to summary
public static final DateTimeFormatter DATE_FORMATTER
DATE_LITERAL_NO_DELIMITERSback to summary
public static final Pattern DATE_LITERAL_NO_DELIMITERS
DATE_LITERAL_WITH_DELIMITERSback to summary
public static final Pattern DATE_LITERAL_WITH_DELIMITERS
DATETIME_FORMATTER_NO_FRACT_NO_OFFSETback to summary
public static final DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_NO_OFFSET
DATETIME_FORMATTER_NO_FRACT_WITH_OFFSETback to summary
public static final DateTimeFormatter DATETIME_FORMATTER_NO_FRACT_WITH_OFFSET
DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSETback to summary
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_MILLIS_NO_OFFSET
DATETIME_FORMATTER_WITH_NANOS_NO_OFFSETback to summary
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_NO_OFFSET
DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSETback to summary
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_NANOS_WITH_OFFSET
DATETIME_FORMATTER_WITH_OPTIONAL_MICROSback to summary
public static final DateTimeFormatter DATETIME_FORMATTER_WITH_OPTIONAL_MICROS
DATETIME_LITERAL_SHORT12back to summary
public static final Pattern DATETIME_LITERAL_SHORT12
DATETIME_LITERAL_SHORT14back to summary
public static final Pattern DATETIME_LITERAL_SHORT14
DATETIME_LITERAL_WITH_DELIMITERSback to summary
public static final Pattern DATETIME_LITERAL_WITH_DELIMITERS
DEFAULT_DATEback to summary
public static final LocalDate DEFAULT_DATE
DEFAULT_TIMEback to summary
public static final LocalTime DEFAULT_TIME
DURATION_LITERAL_NO_DAYSback to summary
public static final Pattern DURATION_LITERAL_NO_DAYS
DURATION_LITERAL_WITH_DAYSback to summary
public static final Pattern DURATION_LITERAL_WITH_DAYS
GMT_TIMEZONEback to summary
pack-priv static final TimeZone GMT_TIMEZONE
LOCKback to summary
pack-priv static final Lock LOCK
systemNanoTimeMethodback to summary
protected static final Method systemNanoTimeMethod
TIME_FORMATTER_NO_FRACT_NO_OFFSETback to summary
public static final DateTimeFormatter TIME_FORMATTER_NO_FRACT_NO_OFFSET
TIME_FORMATTER_NO_FRACT_WITH_OFFSETback to summary
public static final DateTimeFormatter TIME_FORMATTER_NO_FRACT_WITH_OFFSET
TIME_FORMATTER_WITH_NANOS_NO_OFFSETback to summary
public static final DateTimeFormatter TIME_FORMATTER_WITH_NANOS_NO_OFFSET
TIME_FORMATTER_WITH_NANOS_WITH_OFFSETback to summary
public static final DateTimeFormatter TIME_FORMATTER_WITH_NANOS_WITH_OFFSET
TIME_FORMATTER_WITH_OPTIONAL_MICROSback to summary
public static final DateTimeFormatter TIME_FORMATTER_WITH_OPTIONAL_MICROS
TIME_LITERAL_SHORT2back to summary
public static final Pattern TIME_LITERAL_SHORT2
TIME_LITERAL_SHORT4back to summary
public static final Pattern TIME_LITERAL_SHORT4
TIME_LITERAL_SHORT6back to summary
public static final Pattern TIME_LITERAL_SHORT6
TIME_LITERAL_WITH_DELIMITERSback to summary
public static final Pattern TIME_LITERAL_WITH_DELIMITERS
TIME_ZONE_MAPPINGS_RESOURCEback to summary
private static final String TIME_ZONE_MAPPINGS_RESOURCE
timeZoneMappingsback to summary
private static Properties timeZoneMappings

Constructor Detail

TimeUtilback to summary
public TimeUtil()

Method Detail

adjustNanosPrecisionback to summary
public 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.

Parameters
ts:Timestamp

an original Timestamp object, not modified by this method

fsp:int

value in the range from 0 to 6 specifying fractional seconds precision

serverRoundFracSecs:boolean

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.

Returns:Timestamp

A new Timestamp object cloned from the original one and then rounded or truncated according to required fsp value

adjustNanosPrecisionback to summary
public 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.

Parameters
x:LocalDateTime

an original LocalDateTime object, not modified by this method

fsp:int

value in the range from 0 to 6 specifying fractional seconds precision

serverRoundFracSecs:boolean

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.

Returns:LocalDateTime

A new LocalDateTime object cloned from the original one and then rounded or truncated according to required fsp value

adjustNanosPrecisionback to summary
public static LocalTime adjustNanosPrecision(LocalTime x, int fsp, boolean serverRoundFracSecs)
adjustNanosPrecisionback to summary
public static Duration adjustNanosPrecision(Duration x, int fsp, boolean serverRoundFracSecs)
formatNanosback to summary
public static String formatNanos(int nanos, int fsp)

Return a string representation of a fractional seconds part. This method assumes that all Timestamp adjustments are already done before, thus no rounding is needed, only a proper "0" padding to be done.

Parameters
nanos:int

fractional seconds value

fsp:int

required fractional part length

Returns:String

fractional seconds part as a string

formatNanosback to summary
public static String formatNanos(int nanos, int fsp, boolean truncateTrailingZeros)

Return a string representation of a fractional seconds part. This method assumes that all Timestamp adjustments are already done before, thus no rounding is needed, only a proper "0" padding to be done.

Parameters
nanos:int

fractional seconds value

fsp:int

required fractional part length

truncateTrailingZeros:boolean

whether to remove trailing zero characters in a fractional part after formatting

Returns:String

fractional seconds part as a string

getCanonicalDateback to summary
private static String getCanonicalDate(String s)
getCanonicalDateTimeback to summary
private static String getCanonicalDateTime(String s)
getCanonicalTimeback to summary
private static String getCanonicalTime(String s)
getCanonicalTimeZoneback to summary
public static String getCanonicalTimeZone(String timezoneStr, ExceptionInterceptor exceptionInterceptor)

Returns the 'official' Java timezone name for the given timezone

Parameters
timezoneStr:String

the 'common' timezone name

exceptionInterceptor:ExceptionInterceptor

exception interceptor

Returns:String

the Java timezone name for the given timezone

getCurrentTimeNanosOrMillisback to summary
public static long getCurrentTimeNanosOrMillis()
getDurationStringback to summary
public static String getDurationString(Duration x)
getSimpleDateFormatback to summary
public static SimpleDateFormat getSimpleDateFormat(SimpleDateFormat cachedSimpleDateFormat, String pattern, TimeZone tz)

Get SimpleDateFormat with a default Calendar which TimeZone is replaced with the provided one.

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.

Parameters
cachedSimpleDateFormat:SimpleDateFormat

existing SimpleDateFormat to use instead of creating a new one

pattern:String

format pattern

tz:TimeZone

TimeZone object replacing the default one

Returns:SimpleDateFormat

SimpleDateFormat object

getSimpleDateFormatback to summary
public static SimpleDateFormat getSimpleDateFormat(String pattern, Calendar cal)

Get SimpleDateFormat where a default Calendar is replaced with a clone of the provided one.

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).

Parameters
pattern:String

format pattern

cal:Calendar

Calendar object which clone is replacing the default Calendar

Returns:SimpleDateFormat

SimpleDateFormat object

hasFractionalSecondsback to summary
public static Boolean hasFractionalSeconds(Time t)
loadTimeZoneMappingsback to summary
private static void loadTimeZoneMappings(ExceptionInterceptor exceptionInterceptor)

Loads a properties file that contains all kinds of time zone mappings.

Parameters
exceptionInterceptor:ExceptionInterceptor

exception interceptor

nanoTimeAvailableback to summary
public static boolean nanoTimeAvailable()
parseToDateTimeObjectback to summary
public static Object parseToDateTimeObject(String s, MysqlType targetMysqlType)
truncateFractionalSecondsback to summary
public static Timestamp truncateFractionalSeconds(Timestamp timestamp)
truncateFractionalSecondsback to summary
public static Time truncateFractionalSeconds(Time time)