Skip to content

Commit 8e5b840

Browse files
authored
fix: set timezone 'Asia/Shanghai' bug (#261)
1 parent 3ecc754 commit 8e5b840

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

src/main/java/com/taosdata/jdbc/rs/ConnectionParam.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,8 @@ public static ConnectionParam getParamWs(Properties perperties) throws SQLExcept
344344
try {
345345
ZoneId zoneId = ZoneId.of(connectionParam.getTz());
346346
ZoneId defaultZoneId = ZoneId.systemDefault();
347-
if (!StringUtils.isEmpty(connectionParam.getTz()) && defaultZoneId.equals(zoneId)){
348-
// for performance, if the time zone is the same as the system default time zone, we ignore it
349-
connectionParam.setTz("");
350-
} else {
347+
if (!defaultZoneId.equals(zoneId)){
348+
// Only set the time zone if it differs from the system default
351349
connectionParam.setZoneId(zoneId);
352350
}
353351
} catch (DateTimeException e) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.taosdata.jdbc.ws;
2+
3+
import com.taosdata.jdbc.TSDBDriver;
4+
import com.taosdata.jdbc.annotation.TestTarget;
5+
import com.taosdata.jdbc.utils.DateTimeUtils;
6+
import com.taosdata.jdbc.utils.SpecifyAddress;
7+
import com.taosdata.jdbc.utils.TestUtils;
8+
import org.junit.After;
9+
import org.junit.Assert;
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
import org.junit.runner.RunWith;
13+
import org.junit.runners.Parameterized;
14+
15+
import java.sql.Date;
16+
import java.sql.*;
17+
import java.time.*;
18+
import java.time.temporal.ChronoUnit;
19+
import java.util.*;
20+
21+
@TestTarget(alias = "websocket timezon test", author = "sheyj", version = "3.7.0")
22+
public class WSTimeZoneTest2 {
23+
24+
private static final String host = "127.0.0.1";
25+
private static final int port = 6041;
26+
27+
28+
29+
@Test
30+
public void UTC8Test() throws SQLException {
31+
String url = SpecifyAddress.getInstance().getRestWithoutUrl();
32+
if (url == null) {
33+
url = "jdbc:TAOS-WS://" + host + ":" + port + "/?user=root&password=taosdata";
34+
} else {
35+
url += "?user=root&password=taosdata";
36+
}
37+
Properties properties = new Properties();
38+
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "Asia/Shanghai");
39+
try ( Connection connection = DriverManager.getConnection(url, properties)) {
40+
WSConnection wsConnection = (WSConnection) connection;
41+
Assert.assertEquals("Asia/Shanghai", wsConnection.getParam().getTz());
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)