/** * Configures the client's timezone if required. * * @throws CJException * if the timezone the server is configured to use can't be * mapped to a Java timezone. */ publicvoidconfigureTimezone() { StringconfiguredTimeZoneOnServer=this.serverSession.getServerVariable("time_zone");
if ("SYSTEM".equalsIgnoreCase(configuredTimeZoneOnServer)) { configuredTimeZoneOnServer = this.serverSession.getServerVariable("system_time_zone"); }
if (configuredTimeZoneOnServer != null) { // user can override this with driver properties, so don't detect if that's the case if (canonicalTimezone == null || StringUtils.isEmptyOrWhitespaceOnly(canonicalTimezone)) { try { canonicalTimezone = TimeUtil.getCanonicalTimezone(configuredTimeZoneOnServer, getExceptionInterceptor()); } catch (IllegalArgumentException iae) { throw ExceptionFactory.createException(WrongArgumentException.class, iae.getMessage(), getExceptionInterceptor()); } } }
if (canonicalTimezone != null && canonicalTimezone.length() > 0) { this.serverSession.setServerTimeZone(TimeZone.getTimeZone(canonicalTimezone));
// // The Calendar class has the behavior of mapping unknown timezones to 'GMT' instead of throwing an exception, so we must check for this... // if (!canonicalTimezone.equalsIgnoreCase("GMT") && this.serverSession.getServerTimeZone().getID().equals("GMT")) { throw ExceptionFactory.createException(WrongArgumentException.class, Messages.getString("Connection.9", newObject[] { canonicalTimezone }), getExceptionInterceptor()); } }
/** * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime} * object, with the same year, month, day of month, hours, minutes, * seconds and nanos date-time value as the provided {@code LocalDateTime}. * <p> * The provided {@code LocalDateTime} is interpreted as the local * date-time in the local time zone. * * @param dateTime a {@code LocalDateTime} to convert * @return a {@code Timestamp} object * @exception NullPointerException if {@code dateTime} is null. * @since 1.8 */ @SuppressWarnings("deprecation") publicstatic Timestamp valueOf(LocalDateTime dateTime) { returnnewTimestamp(dateTime.getYear() - 1900, dateTime.getMonthValue() - 1, dateTime.getDayOfMonth(), dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond(), dateTime.getNano()); }