1
1
package io .cloudquery .scalar ;
2
2
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 ;
4
9
import org .apache .arrow .vector .types .TimeUnit ;
5
10
import org .apache .arrow .vector .types .pojo .ArrowType ;
6
11
7
12
public class Timestamp extends Scalar <Long > {
8
13
public static final ZoneId zoneID = ZoneOffset .UTC ;
9
14
10
15
// 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 ());
12
18
13
19
public Timestamp () {
14
20
super ();
@@ -26,34 +32,36 @@ public ArrowType dataType() {
26
32
@ Override
27
33
public void setValue (Object value ) throws ValidationException {
28
34
if (value instanceof ZonedDateTime timestamp ) {
29
- this .value = timestamp .withZoneSameInstant (zoneID ).toEpochSecond ();
35
+ this .value = timestamp .withZoneSameInstant (zoneID ).toEpochSecond () * 1000 ;
30
36
return ;
31
37
}
32
38
33
39
if (value instanceof LocalDate date ) {
34
- this .value = date .atStartOfDay (zoneID ).toEpochSecond ();
40
+ this .value = date .atStartOfDay (zoneID ).toEpochSecond () * 1000 ;
35
41
return ;
36
42
}
37
43
38
44
if (value instanceof LocalDateTime date ) {
39
- this .value = date .atZone (zoneID ).toEpochSecond ();
45
+ this .value = date .atZone (zoneID ).toEpochSecond () * 1000 ;
40
46
return ;
41
47
}
42
48
43
49
if (value instanceof Integer integer ) {
44
50
this .value =
45
- ZonedDateTime .ofInstant (Instant .ofEpochMilli (integer ), ZoneOffset .UTC ).toEpochSecond ();
51
+ ZonedDateTime .ofInstant (Instant .ofEpochMilli (integer ), ZoneOffset .UTC ).toEpochSecond ()
52
+ * 1000 ;
46
53
return ;
47
54
}
48
55
49
56
if (value instanceof Long longValue ) {
50
57
this .value =
51
- ZonedDateTime .ofInstant (Instant .ofEpochMilli (longValue ), ZoneOffset .UTC ).toEpochSecond ();
58
+ ZonedDateTime .ofInstant (Instant .ofEpochMilli (longValue ), ZoneOffset .UTC ).toEpochSecond ()
59
+ * 1000 ;
52
60
return ;
53
61
}
54
62
55
63
if (value instanceof CharSequence sequence ) {
56
- this .value = ZonedDateTime .parse (sequence ).toEpochSecond ();
64
+ this .value = ZonedDateTime .parse (sequence ).toInstant (). toEpochMilli ();
57
65
return ;
58
66
}
59
67
@@ -64,7 +72,7 @@ public void setValue(Object value) throws ValidationException {
64
72
@ Override
65
73
public java .lang .String toString () {
66
74
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 ();
68
76
}
69
77
70
78
return NULL_VALUE_STRING ;
0 commit comments