NebulaGraph Java Client 5.0.0
Loading...
Searching...
No Matches
NZonedDateTime.java
1package com.vesoft.nebula.driver.graph.data;
2
3import com.vesoft.nebula.driver.graph.utils.ZoneOffsetUtil;
4import com.vesoft.nebula.proto.common.ZonedDatetime;
5import java.time.LocalDateTime;
6import java.time.ZoneOffset;
7import java.util.Objects;
8
9public class NZonedDateTime {
10 private final LocalDateTime localDateTime;
11 private final ZoneOffset zoneOffset;
12
13 public NZonedDateTime(LocalDateTime localDateTime, ZoneOffset zoneOffset) {
14 this.localDateTime = localDateTime;
15 this.zoneOffset = zoneOffset;
16 }
17
21 public int getYear() {
22 return localDateTime.getYear();
23 }
24
28 public int getMonth() {
29 return localDateTime.getMonth().getValue();
30 }
31
35 public int getDay() {
36 return localDateTime.getDayOfMonth();
37 }
38
42 public int getHour() {
43 return localDateTime.getHour();
44 }
45
49 public int getMinute() {
50 return localDateTime.getMinute();
51 }
52
56 public int getSecond() {
57 return localDateTime.getSecond();
58 }
59
63 public int getMicrosec() {
64 return localDateTime.getNano() / 1000;
65 }
66
70 public int getOffset() {
71 return zoneOffset.getTotalSeconds();
72 }
73
74 @Override
75 public String toString() {
76 return String.format("%d-%02d-%02dT%02d:%02d:%02d.%06d%s",
77 getYear(), getMonth(), getDay(),
79 getMicrosec(), ZoneOffsetUtil.buildOffset(getOffset()));
80 }
81
82 @Override
83 public boolean equals(Object o) {
84 if (this == o) {
85 return true;
86 }
87 if (o == null || getClass() != o.getClass()) {
88 return false;
89 }
90 NZonedDateTime that = (NZonedDateTime) o;
91 return getYear() == that.getYear()
92 && getMonth() == that.getMonth()
93 && getDay() == that.getDay()
94 && getHour() == that.getHour()
95 && getMinute() == that.getMinute()
96 && getSecond() == that.getSecond()
97 && getMicrosec() == that.getMicrosec()
98 && getOffset() == that.getOffset();
99 }
100
101 @Override
102 public int hashCode() {
103 return Objects.hash(localDateTime, getOffset());
104 }
105}