Class TimeUtil
java.lang.Object
com.mysql.jdbc.TimeUtil
Timezone conversion routines and other time related methods
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TimestampadjustTimestampNanosPrecision(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 TimechangeTimezone(MySQLConnection conn, Calendar sessionCalendar, Calendar targetCalendar, Time t, TimeZone fromTz, TimeZone toTz, boolean rollForward) Change the given times from one timezone to anotherstatic TimestampchangeTimezone(MySQLConnection conn, Calendar sessionCalendar, Calendar targetCalendar, Timestamp tstamp, TimeZone fromTz, TimeZone toTz, boolean rollForward) Change the given timestamp from one timezone to another(package private) static final DatefastDateCreate(boolean useGmtConversion, Calendar gmtCalIfNeeded, Calendar cal, int year, int month, int day) (package private) static final DatefastDateCreate(int year, int month, int day, Calendar targetCalendar) (package private) static final TimefastTimeCreate(int hour, int minute, int second, Calendar targetCalendar, ExceptionInterceptor exceptionInterceptor) (package private) static final TimefastTimeCreate(Calendar cal, int hour, int minute, int second, ExceptionInterceptor exceptionInterceptor) (package private) static final TimestampfastTimestampCreate(boolean useGmtConversion, Calendar gmtCalIfNeeded, Calendar cal, int year, int month, int day, int hour, int minute, int seconds, int secondsPart) (package private) static final TimestampfastTimestampCreate(TimeZone tz, int year, int month, int day, int hour, int minute, int seconds, int secondsPart) static StringformatNanos(int nanos, boolean serverSupportsFracSecs, int fsp) Return a string representation of a fractional seconds part.static StringgetCanonicalTimezone(String timezoneStr, ExceptionInterceptor exceptionInterceptor) Returns the 'official' Java timezone name for the given timezonestatic longstatic final TimeZonegetDefaultTimeZone(boolean useCache) static SimpleDateFormatgetSimpleDateFormat(SimpleDateFormat cachedSimpleDateFormat, String pattern, Calendar cal, TimeZone tz) static booleanstatic CalendarsetProlepticIfNeeded(Calendar origCalendar, Calendar refCalendar) Return the proleptic version of origCalendar if refCalendar is proleptic.static TimestamptruncateFractionalSeconds(Timestamp timestamp)
-
Field Details
-
GMT_TIMEZONE
-
systemNanoTimeMethod
-
-
Constructor Details
-
TimeUtil
public TimeUtil()
-
-
Method Details
-
nanoTimeAvailable
public static boolean nanoTimeAvailable() -
getDefaultTimeZone
-
getCurrentTimeNanosOrMillis
public static long getCurrentTimeNanosOrMillis() -
changeTimezone
public static Time changeTimezone(MySQLConnection conn, Calendar sessionCalendar, Calendar targetCalendar, Time t, TimeZone fromTz, TimeZone toTz, boolean rollForward) Change the given times from one timezone to another- Parameters:
conn- the current connection to the MySQL servert- the times to changefromTz- the timezone to change fromtoTz- the timezone to change to- Returns:
- the times changed to the timezone 'toTz'
-
changeTimezone
public static Timestamp changeTimezone(MySQLConnection conn, Calendar sessionCalendar, Calendar targetCalendar, Timestamp tstamp, TimeZone fromTz, TimeZone toTz, boolean rollForward) Change the given timestamp from one timezone to another- Parameters:
conn- the current connection to the MySQL servertstamp- the timestamp to changefromTz- the timezone to change fromtoTz- the timezone to change to- Returns:
- the timestamp changed to the timezone 'toTz'
-
fastDateCreate
-
fastDateCreate
-
fastTimeCreate
static final Time fastTimeCreate(Calendar cal, int hour, int minute, int second, ExceptionInterceptor exceptionInterceptor) throws SQLException - Throws:
SQLException
-
fastTimeCreate
static final Time fastTimeCreate(int hour, int minute, int second, Calendar targetCalendar, ExceptionInterceptor exceptionInterceptor) throws SQLException - Throws:
SQLException
-
fastTimestampCreate
-
fastTimestampCreate
-
getCanonicalTimezone
public static String getCanonicalTimezone(String timezoneStr, ExceptionInterceptor exceptionInterceptor) throws SQLException Returns the 'official' Java timezone name for the given timezone- Parameters:
timezoneStr- the 'common' timezone name- Returns:
- the Java timezone name for the given timezone
- Throws:
SQLExceptionIllegalArgumentException
-
adjustTimestampNanosPrecision
public static Timestamp adjustTimestampNanosPrecision(Timestamp ts, int fsp, boolean serverRoundFracSecs) throws SQLException Return a new Timestamp object which value is adjusted according to known DATE, DATETIME or TIMESTAMP field precision.- Parameters:
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.- Returns:
- A new Timestamp object cloned from original ones and then rounded or truncated according to required fsp value
- Throws:
SQLException- if fsp value is out of range
-
formatNanos
public static String formatNanos(int nanos, boolean serverSupportsFracSecs, int fsp) throws SQLException 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- fractional seconds valueserverSupportsFracSecs- flag indicating does server support fractional secondsfsp- required fractional part length- Returns:
- fractional seconds part as a string
- Throws:
SQLException- if nanos or fsp value is out of range
-
truncateFractionalSeconds
-
getSimpleDateFormat
public static SimpleDateFormat getSimpleDateFormat(SimpleDateFormat cachedSimpleDateFormat, String pattern, Calendar cal, TimeZone tz) -
setProlepticIfNeeded
Return the proleptic version of origCalendar if refCalendar is proleptic. Applied only to GregorianCalendar parameters.- Parameters:
origCalendar- original CalendarrefCalendar- reference Calendar- Returns:
- the original Calendar if no adjustments are needed or the new proleptic GregorianCalendar with preserved Timezone of origCalendar and other fields unset.
-