Skip to content

Commit

Permalink
dbeaver#36487 Use old timezone for Kolkata during connection (dbeaver…
Browse files Browse the repository at this point in the history
…#36578)

* dbeaver#36487 Use old timezone for Kolkata during connection

* dbeaver#36073 Fix constants

* dbeaver#36073 Refactor code

* dbeaver#36073 Refactor code after review

* dbeaver#36073 Refactor code after review

---------

Co-authored-by: kseniaguzeeva <112612526+kseniaguzeeva@users.noreply.github.com>
  • Loading branch information
IvanGorshechnikov and kseniaguzeeva authored Dec 30, 2024
1 parent f839c98 commit 31790fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ public class PostgreConstants {
public static final String COLLATION_DEFAULT = "default";
public static final String DEFAULT_ARRAY_DELIMITER = " ";
public static final String PG_PASS_HOSTNAME = "overriddenUsername";
public static final String LEGACY_UA_TIMEZONE = "Europe/Kiev";
public static final String NEW_UA_TIMEZONE = "Europe/Kyiv";
public static final Map<String, String> REPLACING_TIMEZONE = Map.of(
"Europe/Kyiv", "Europe/Kiev",
"Asia/Calcutta", "Asia/Kolkata"
);

static {
DATA_TYPE_ALIASES.put("boolean", TYPE_BOOL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,15 @@ protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @Nullab
if (instance != null) {
log.debug("Initiate connection to " + getServerType().getServerTypeName() + " database [" + instance.getName() + "@" + conConfig.getHostName() + "] for " + purpose);
}
boolean timezoneOverridden = false;
String currentTimezoneId = ZoneId.systemDefault().getId();
String legacyTimezoneOverridden = PostgreConstants.REPLACING_TIMEZONE.get(currentTimezoneId);

try {
// Old versions of postgres and some linux distributions, on which docker images are made, may not contain
// new timezone, which will lead to the error while connecting, there is no way to know before connecting
// so to be sure we will use the old name
if (PostgreConstants.NEW_UA_TIMEZONE.equals(TimeZone.getDefault().getID())) {
TimezoneRegistry.setDefaultZone(ZoneId.of(PostgreConstants.LEGACY_UA_TIMEZONE), false);
timezoneOverridden = true;
if (legacyTimezoneOverridden != null) {
TimezoneRegistry.setDefaultZone(ZoneId.of(legacyTimezoneOverridden), false);
}

if (isReadDatabaseList(conConfig) || !CommonUtils.isEmpty(conConfig.getBootstrap().getDefaultCatalogName())) {
Expand Down Expand Up @@ -580,8 +580,8 @@ protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @Nullab

throw e;
} finally {
if (timezoneOverridden && PostgreConstants.LEGACY_UA_TIMEZONE.equals(TimeZone.getDefault().getID())) {
TimezoneRegistry.setDefaultZone(ZoneId.of(PostgreConstants.NEW_UA_TIMEZONE), false);
if (legacyTimezoneOverridden != null) {
TimezoneRegistry.setDefaultZone(ZoneId.of(currentTimezoneId), false);
}
}

Expand Down

0 comments on commit 31790fa

Please sign in to comment.