11package io .cloudquery .scalar ;
22
3- import java .time .*;
3+ import java .time .Instant ;
4+ import java .time .LocalDate ;
5+ import java .time .LocalDateTime ;
6+ import java .time .ZoneId ;
7+ import java .time .ZoneOffset ;
8+ import java .time .ZonedDateTime ;
49import org .apache .arrow .vector .types .TimeUnit ;
510import org .apache .arrow .vector .types .pojo .ArrowType ;
611
712public class Timestamp extends Scalar <Long > {
813 public static final ZoneId zoneID = ZoneOffset .UTC ;
914
1015 // TODO: add more units support later
11- private static final ArrowType dt = new ArrowType .Timestamp (TimeUnit .SECOND , zoneID .toString ());
16+ private static final ArrowType dt =
17+ new ArrowType .Timestamp (TimeUnit .MILLISECOND , zoneID .toString ());
1218
1319 public Timestamp () {
1420 super ();
@@ -26,34 +32,36 @@ public ArrowType dataType() {
2632 @ Override
2733 public void setValue (Object value ) throws ValidationException {
2834 if (value instanceof ZonedDateTime timestamp ) {
29- this .value = timestamp .withZoneSameInstant (zoneID ).toEpochSecond ();
35+ this .value = timestamp .withZoneSameInstant (zoneID ).toEpochSecond () * 1000 ;
3036 return ;
3137 }
3238
3339 if (value instanceof LocalDate date ) {
34- this .value = date .atStartOfDay (zoneID ).toEpochSecond ();
40+ this .value = date .atStartOfDay (zoneID ).toEpochSecond () * 1000 ;
3541 return ;
3642 }
3743
3844 if (value instanceof LocalDateTime date ) {
39- this .value = date .atZone (zoneID ).toEpochSecond ();
45+ this .value = date .atZone (zoneID ).toEpochSecond () * 1000 ;
4046 return ;
4147 }
4248
4349 if (value instanceof Integer integer ) {
4450 this .value =
45- ZonedDateTime .ofInstant (Instant .ofEpochMilli (integer ), ZoneOffset .UTC ).toEpochSecond ();
51+ ZonedDateTime .ofInstant (Instant .ofEpochMilli (integer ), ZoneOffset .UTC ).toEpochSecond ()
52+ * 1000 ;
4653 return ;
4754 }
4855
4956 if (value instanceof Long longValue ) {
5057 this .value =
51- ZonedDateTime .ofInstant (Instant .ofEpochMilli (longValue ), ZoneOffset .UTC ).toEpochSecond ();
58+ ZonedDateTime .ofInstant (Instant .ofEpochMilli (longValue ), ZoneOffset .UTC ).toEpochSecond ()
59+ * 1000 ;
5260 return ;
5361 }
5462
5563 if (value instanceof CharSequence sequence ) {
56- this .value = ZonedDateTime .parse (sequence ).toEpochSecond ();
64+ this .value = ZonedDateTime .parse (sequence ).toInstant (). toEpochMilli ();
5765 return ;
5866 }
5967
@@ -64,7 +72,7 @@ public void setValue(Object value) throws ValidationException {
6472 @ Override
6573 public java .lang .String toString () {
6674 if (this .value != null ) {
67- return ZonedDateTime .ofInstant (Instant .ofEpochSecond ((Long ) this .value ), zoneID ).toString ();
75+ return ZonedDateTime .ofInstant (Instant .ofEpochMilli ((Long ) this .value ), zoneID ).toString ();
6876 }
6977
7078 return NULL_VALUE_STRING ;
0 commit comments