1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.tikv.common;
19
20 import java.sql.Timestamp;
21 import org.joda.time.DateTime;
22
23
24 public class ExtendedDateTime {
25
26 private final DateTime dateTime;
27 private final int microsOfMillis;
28
29
30
31
32
33
34
35
36 public ExtendedDateTime(DateTime dateTime, int microsOfMillis) {
37 this.dateTime = dateTime;
38 this.microsOfMillis = microsOfMillis;
39 }
40
41 public ExtendedDateTime(DateTime dateTime) {
42 this.dateTime = dateTime;
43 this.microsOfMillis = 0;
44 }
45
46 public DateTime getDateTime() {
47 return dateTime;
48 }
49
50 public int getMicrosOfSeconds() {
51 return dateTime.getMillisOfSecond() * 1000 + microsOfMillis;
52 }
53
54 public int getMicrosOfMillis() {
55 return microsOfMillis;
56 }
57
58 public Timestamp toTimeStamp() {
59 Timestamp timestamp = new Timestamp(dateTime.getMillis() / 1000 * 1000);
60 timestamp.setNanos(dateTime.getMillisOfSecond() * 1000000 + microsOfMillis * 1000);
61 return timestamp;
62 }
63
64 public long toEpochMicro() {
65 return toTimeStamp().getTime() * 1000 + getMicrosOfMillis();
66 }
67 }