File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
runtime/src/main/java/io/dingodb/expr/runtime/op/cast Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 3030import java .sql .Timestamp ;
3131import java .time .LocalDate ;
3232import java .time .LocalDateTime ;
33+ import java .time .ZoneId ;
34+ import java .time .ZoneOffset ;
35+ import java .time .ZonedDateTime ;
36+ import java .util .TimeZone ;
3337
3438//@Operators
3539abstract class TimestampCastOp extends CastOp {
@@ -43,8 +47,14 @@ abstract class TimestampCastOp extends CastOp {
4347 return new Timestamp (DateTimeUtils .fromSecond (value ));
4448 }
4549
46- static @ NonNull Timestamp timestampCast (Date value ) {
47- return new Timestamp (value .getTime ());
50+ static @ NonNull Timestamp timestampCast (Date value , ExprConfig config ) {
51+ LocalDateTime ts = new Timestamp (value .getTime ()).toLocalDateTime ();
52+ TimeZone timeZone = (config != null ? config .getTimeZone () : TimeZone .getDefault ());
53+ ZonedDateTime zonedDateTime = ts .atZone (timeZone .toZoneId ());
54+
55+ java .time .ZoneOffset zoneOffset = zonedDateTime .getOffset ();
56+ ZonedDateTime targetZonedDateTime = zonedDateTime .withZoneSameInstant (ZoneId .of ("UTC" ));
57+ return new Timestamp (targetZonedDateTime .toLocalDateTime ().toInstant (zoneOffset ).toEpochMilli ());
4858 }
4959
5060 static @ NonNull Timestamp timestampCast (@ NonNull BigDecimal value ) {
Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ public static final class TimestampCastAny extends TimestampCastOp {
176176 @ Override
177177 protected Timestamp evalNonNullValue (@ NonNull Object value , ExprConfig config ) {
178178 if (value instanceof Date ) {
179- return timestampCast ((Date ) value );
179+ return timestampCast ((Date ) value , config );
180180 } else if (value instanceof Integer ) {
181181 return timestampCast ((Integer ) value );
182182 } else if (value instanceof Timestamp ) {
You can’t perform that action at this time.
0 commit comments