|
30 | 30 | import java.sql.Timestamp; |
31 | 31 | import java.time.LocalDate; |
32 | 32 | import java.time.LocalDateTime; |
| 33 | +import java.time.LocalTime; |
33 | 34 | import java.time.ZoneId; |
34 | 35 | import java.time.ZoneOffset; |
35 | 36 | import java.time.ZonedDateTime; |
@@ -61,12 +62,24 @@ abstract class TimestampCastOp extends CastOp { |
61 | 62 | return new Timestamp(DateTimeUtils.fromSecond(value)); |
62 | 63 | } |
63 | 64 |
|
64 | | - static @NonNull Timestamp timestampCast(@NonNull Time value) { |
| 65 | + static @NonNull Timestamp timestampCast(@NonNull Time value, ExprConfig config) { |
65 | 66 | int hours = value.toLocalTime().getHour(); |
66 | 67 | int minutes = value.toLocalTime().getMinute(); |
67 | 68 | int seconds = value.toLocalTime().getSecond(); |
| 69 | + |
68 | 70 | LocalDateTime localDatetime = LocalDate.now().atTime(hours,minutes,seconds); |
69 | | - return Timestamp.valueOf(localDatetime); |
| 71 | + TimeZone timeZone = (config != null ? config.getTimeZone() : TimeZone.getDefault()); |
| 72 | + ZonedDateTime zonedDateTime = localDatetime.atZone(timeZone.toZoneId()); |
| 73 | + |
| 74 | + java.time.ZoneOffset zoneOffset = zonedDateTime.getOffset(); |
| 75 | + ZonedDateTime targetZonedDateTime = zonedDateTime.withZoneSameInstant(ZoneId.of("UTC")); |
| 76 | + int zonedDayOfMonth = targetZonedDateTime.getDayOfMonth(); |
| 77 | + int localDayofMonth = localDatetime.getDayOfMonth(); |
| 78 | + if (zonedDayOfMonth != localDayofMonth) { |
| 79 | + targetZonedDateTime = targetZonedDateTime.plusDays(localDayofMonth - zonedDayOfMonth); |
| 80 | + } |
| 81 | + |
| 82 | + return new Timestamp(targetZonedDateTime.toLocalDateTime().toInstant(zoneOffset).toEpochMilli()); |
70 | 83 | } |
71 | 84 |
|
72 | 85 | static @Nullable Timestamp timestampCast(String value, @NonNull ExprConfig config) { |
|
0 commit comments