@@ -72,6 +72,21 @@ private DateTimeOffset(java.sql.Timestamp timestamp, int minutesOffset) {
72
72
assert 0 == this .utcMillis % 1000L : "utcMillis: " + this .utcMillis ;
73
73
}
74
74
75
+ /**
76
+ * Constructs a DateTimeOffset from an existing java.time.OffsetDateTime
77
+ *
78
+ * @param offsetDateTime A java.time.OffsetDateTime value
79
+ * @apiNote DateTimeOffset represents values to 100ns precision. If the java.time.OffsetDateTime instance represents
80
+ * a value that is more precise, values in excess of the 100ns precision are rounded to the nearest
81
+ * multiple of 100ns.
82
+ */
83
+ private DateTimeOffset (java .time .OffsetDateTime offsetDateTime ) {
84
+ int hundredNanos = ((offsetDateTime .getNano () + 50 ) / 100 );
85
+ this .utcMillis = offsetDateTime .toEpochSecond () * 1000 ;
86
+ this .nanos = 100 * (hundredNanos % HUNDRED_NANOS_PER_SECOND );
87
+ this .minutesOffset = offsetDateTime .getOffset ().getTotalSeconds () / 60 ;
88
+ }
89
+
75
90
/**
76
91
* Converts a java.sql.Timestamp value with an integer offset to the equivalent DateTimeOffset value
77
92
*
@@ -105,6 +120,19 @@ public static DateTimeOffset valueOf(java.sql.Timestamp timestamp, Calendar cale
105
120
(calendar .get (Calendar .ZONE_OFFSET ) + calendar .get (Calendar .DST_OFFSET )) / (60 * 1000 ));
106
121
}
107
122
123
+ /**
124
+ * Directly converts a {@link java.time.OffsetDateTime} value to an equivalent {@link DateTimeOffset} value
125
+ *
126
+ * @param offsetDateTime A java.time.OffsetDateTime value
127
+ * @return The DateTimeOffset value of the input java.time.OffsetDateTime
128
+ * @apiNote DateTimeOffset represents values to 100ns precision. If the java.time.OffsetDateTime instance represents
129
+ * a value that is more precise, values in excess of the 100ns precision are rounded to the nearest
130
+ * multiple of 100ns.
131
+ */
132
+ public static DateTimeOffset valueOf (java .time .OffsetDateTime offsetDateTime ) {
133
+ return new DateTimeOffset (offsetDateTime );
134
+ }
135
+
108
136
/** formatted value */
109
137
private String formattedValue = null ;
110
138
0 commit comments