1515 */
1616package com .google .cloud .bigquery .storage .v1 ;
1717
18+ import static com .google .cloud .bigquery .storage .util .TimeConversionUtils .toJavaTimeLocalDateTime ;
19+ import static com .google .cloud .bigquery .storage .util .TimeConversionUtils .toJavaTimeLocalTime ;
20+ import static com .google .cloud .bigquery .storage .util .TimeConversionUtils .toThreetenLocalDateTime ;
21+ import static com .google .cloud .bigquery .storage .util .TimeConversionUtils .toThreetenLocalTime ;
1822import static com .google .common .base .Preconditions .checkArgument ;
1923
20- import org .threeten .bp .DateTimeException ;
21- import org .threeten .bp .LocalDateTime ;
22- import org .threeten .bp .LocalTime ;
23- import org .threeten .bp .temporal .ChronoUnit ;
24+ import com .google .api .core .ObsoleteApi ;
25+ import java .time .DateTimeException ;
26+ import java .time .temporal .ChronoUnit ;
2427
2528/**
2629 * Ported from ZetaSQL CivilTimeEncoder Original code can be found at:
@@ -89,7 +92,7 @@ public final class CivilTimeEncoder {
8992 * @see #decodePacked32TimeSeconds(int)
9093 */
9194 @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
92- private static int encodePacked32TimeSeconds (LocalTime time ) {
95+ private static int encodePacked32TimeSeconds (java . time . LocalTime time ) {
9396 checkValidTimeSeconds (time );
9497 int bitFieldTimeSeconds = 0x0 ;
9598 bitFieldTimeSeconds |= time .getHour () << HOUR_SHIFT ;
@@ -112,19 +115,29 @@ private static int encodePacked32TimeSeconds(LocalTime time) {
112115 * @see #encodePacked32TimeSeconds(LocalTime)
113116 */
114117 @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
115- private static LocalTime decodePacked32TimeSeconds (int bitFieldTimeSeconds ) {
118+ private static java . time . LocalTime decodePacked32TimeSeconds (int bitFieldTimeSeconds ) {
116119 checkValidBitField (bitFieldTimeSeconds , TIME_SECONDS_MASK );
117120 int hourOfDay = getFieldFromBitField (bitFieldTimeSeconds , HOUR_MASK , HOUR_SHIFT );
118121 int minuteOfHour = getFieldFromBitField (bitFieldTimeSeconds , MINUTE_MASK , MINUTE_SHIFT );
119122 int secondOfMinute = getFieldFromBitField (bitFieldTimeSeconds , SECOND_MASK , SECOND_SHIFT );
120123 // LocalTime validates the input parameters.
121124 try {
122- return LocalTime .of (hourOfDay , minuteOfHour , secondOfMinute );
125+ return java . time . LocalTime .of (hourOfDay , minuteOfHour , secondOfMinute );
123126 } catch (DateTimeException e ) {
124127 throw new IllegalArgumentException (e .getMessage (), e );
125128 }
126129 }
127130
131+ /**
132+ * This method is obsolete. Use {@link #encodePacked64TimeMicrosLocalTime(java.time.LocalTime)}
133+ * instead.
134+ */
135+ @ ObsoleteApi ("Use encodePacked64TimeMicrosLocalTime(java.time.LocalTime) instead" )
136+ @ SuppressWarnings ("GoodTime" )
137+ public static long encodePacked64TimeMicros (org .threeten .bp .LocalTime time ) {
138+ return encodePacked64TimeMicrosLocalTime (toJavaTimeLocalTime (time ));
139+ }
140+
128141 /**
129142 * Encodes {@code time} as a 8-byte integer with microseconds precision.
130143 *
@@ -140,11 +153,18 @@ private static LocalTime decodePacked32TimeSeconds(int bitFieldTimeSeconds) {
140153 * @see #encodePacked64TimeMicros(LocalTime)
141154 */
142155 @ SuppressWarnings ("GoodTime" )
143- public static long encodePacked64TimeMicros ( LocalTime time ) {
156+ public static long encodePacked64TimeMicrosLocalTime ( java . time . LocalTime time ) {
144157 checkValidTimeMicros (time );
145158 return (((long ) encodePacked32TimeSeconds (time )) << MICRO_LENGTH ) | (time .getNano () / 1_000L );
146159 }
147160
161+ /** This method is obsolete. Use {@link #decodePacked64TimeMicrosLocalTime(long)} instead. */
162+ @ ObsoleteApi ("Use decodePacked64TimeMicrosLocalTime(long) instead" )
163+ @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
164+ public static org .threeten .bp .LocalTime decodePacked64TimeMicros (long bitFieldTimeMicros ) {
165+ return toThreetenLocalTime (decodePacked64TimeMicrosLocalTime (bitFieldTimeMicros ));
166+ }
167+
148168 /**
149169 * Decodes {@code bitFieldTimeMicros} as a {@link LocalTime} with microseconds precision.
150170 *
@@ -159,13 +179,13 @@ public static long encodePacked64TimeMicros(LocalTime time) {
159179 * @see #encodePacked64TimeMicros(LocalTime)
160180 */
161181 @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
162- public static LocalTime decodePacked64TimeMicros (long bitFieldTimeMicros ) {
182+ public static java . time . LocalTime decodePacked64TimeMicrosLocalTime (long bitFieldTimeMicros ) {
163183 checkValidBitField (bitFieldTimeMicros , TIME_MICROS_MASK );
164184 int bitFieldTimeSeconds = (int ) (bitFieldTimeMicros >> MICRO_LENGTH );
165- LocalTime timeSeconds = decodePacked32TimeSeconds (bitFieldTimeSeconds );
185+ java . time . LocalTime timeSeconds = decodePacked32TimeSeconds (bitFieldTimeSeconds );
166186 int microOfSecond = getFieldFromBitField (bitFieldTimeMicros , MICRO_MASK , MICRO_SHIFT );
167187 checkValidMicroOfSecond (microOfSecond );
168- LocalTime time = timeSeconds .withNano (microOfSecond * 1000 );
188+ java . time . LocalTime time = timeSeconds .withNano (microOfSecond * 1000 );
169189 checkValidTimeMicros (time );
170190 return time ;
171191 }
@@ -184,7 +204,7 @@ public static LocalTime decodePacked64TimeMicros(long bitFieldTimeMicros) {
184204 * @see #decodePacked64DatetimeSeconds(long)
185205 */
186206 @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
187- private static long encodePacked64DatetimeSeconds (LocalDateTime dateTime ) {
207+ private static long encodePacked64DatetimeSeconds (java . time . LocalDateTime dateTime ) {
188208 checkValidDateTimeSeconds (dateTime );
189209 long bitFieldDatetimeSeconds = 0x0L ;
190210 bitFieldDatetimeSeconds |= (long ) dateTime .getYear () << YEAR_SHIFT ;
@@ -208,16 +228,17 @@ private static long encodePacked64DatetimeSeconds(LocalDateTime dateTime) {
208228 * @see #encodePacked64DatetimeSeconds(LocalDateTime)
209229 */
210230 @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
211- private static LocalDateTime decodePacked64DatetimeSeconds (long bitFieldDatetimeSeconds ) {
231+ private static java .time .LocalDateTime decodePacked64DatetimeSeconds (
232+ long bitFieldDatetimeSeconds ) {
212233 checkValidBitField (bitFieldDatetimeSeconds , DATETIME_SECONDS_MASK );
213234 int bitFieldTimeSeconds = (int ) (bitFieldDatetimeSeconds & TIME_SECONDS_MASK );
214- LocalTime timeSeconds = decodePacked32TimeSeconds (bitFieldTimeSeconds );
235+ java . time . LocalTime timeSeconds = decodePacked32TimeSeconds (bitFieldTimeSeconds );
215236 int year = getFieldFromBitField (bitFieldDatetimeSeconds , YEAR_MASK , YEAR_SHIFT );
216237 int monthOfYear = getFieldFromBitField (bitFieldDatetimeSeconds , MONTH_MASK , MONTH_SHIFT );
217238 int dayOfMonth = getFieldFromBitField (bitFieldDatetimeSeconds , DAY_MASK , DAY_SHIFT );
218239 try {
219- LocalDateTime dateTime =
220- LocalDateTime .of (
240+ java . time . LocalDateTime dateTime =
241+ java . time . LocalDateTime .of (
221242 year ,
222243 monthOfYear ,
223244 dayOfMonth ,
@@ -231,6 +252,16 @@ private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetime
231252 }
232253 }
233254
255+ /**
256+ * This method is obsolete. Use {@link
257+ * #encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime)} instead.
258+ */
259+ @ ObsoleteApi ("Use encodePacked64DatetimeMicrosLocalDateTime(java.time.LocalDateTime) instead" )
260+ @ SuppressWarnings ({"GoodTime-ApiWithNumericTimeUnit" , "JavaLocalDateTimeGetNano" })
261+ public static long encodePacked64DatetimeMicros (org .threeten .bp .LocalDateTime dateTime ) {
262+ return encodePacked64DatetimeMicrosLocalDateTime (toJavaTimeLocalDateTime (dateTime ));
263+ }
264+
234265 /**
235266 * Encodes {@code dateTime} as a 8-byte integer with microseconds precision.
236267 *
@@ -245,12 +276,23 @@ private static LocalDateTime decodePacked64DatetimeSeconds(long bitFieldDatetime
245276 * @see #decodePacked64DatetimeMicros(long)
246277 */
247278 @ SuppressWarnings ({"GoodTime-ApiWithNumericTimeUnit" , "JavaLocalDateTimeGetNano" })
248- public static long encodePacked64DatetimeMicros ( LocalDateTime dateTime ) {
279+ public static long encodePacked64DatetimeMicrosLocalDateTime ( java . time . LocalDateTime dateTime ) {
249280 checkValidDateTimeMicros (dateTime );
250281 return (encodePacked64DatetimeSeconds (dateTime ) << MICRO_LENGTH )
251282 | (dateTime .getNano () / 1_000L );
252283 }
253284
285+ /**
286+ * This method is obsolete. Use {@link #decodePacked64DatetimeMicrosLocalDateTime(long)} instead.
287+ */
288+ @ ObsoleteApi ("Use decodePacked64DatetimeMicrosLocalDateTime(long) instead" )
289+ @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
290+ public static org .threeten .bp .LocalDateTime decodePacked64DatetimeMicros (
291+ long bitFieldDatetimeMicros ) {
292+ return toThreetenLocalDateTime (
293+ decodePacked64DatetimeMicrosLocalDateTime (bitFieldDatetimeMicros ));
294+ }
295+
254296 /**
255297 * Decodes {@code bitFieldDatetimeMicros} as a {@link LocalDateTime} with microseconds precision.
256298 *
@@ -265,13 +307,15 @@ public static long encodePacked64DatetimeMicros(LocalDateTime dateTime) {
265307 * @see #encodePacked64DatetimeMicros(LocalDateTime)
266308 */
267309 @ SuppressWarnings ("GoodTime-ApiWithNumericTimeUnit" )
268- public static LocalDateTime decodePacked64DatetimeMicros (long bitFieldDatetimeMicros ) {
310+ public static java .time .LocalDateTime decodePacked64DatetimeMicrosLocalDateTime (
311+ long bitFieldDatetimeMicros ) {
269312 checkValidBitField (bitFieldDatetimeMicros , DATETIME_MICROS_MASK );
270313 long bitFieldDatetimeSeconds = bitFieldDatetimeMicros >> MICRO_LENGTH ;
271- LocalDateTime dateTimeSeconds = decodePacked64DatetimeSeconds (bitFieldDatetimeSeconds );
314+ java .time .LocalDateTime dateTimeSeconds =
315+ decodePacked64DatetimeSeconds (bitFieldDatetimeSeconds );
272316 int microOfSecond = getFieldFromBitField (bitFieldDatetimeMicros , MICRO_MASK , MICRO_SHIFT );
273317 checkValidMicroOfSecond (microOfSecond );
274- LocalDateTime dateTime = dateTimeSeconds .withNano (microOfSecond * 1_000 );
318+ java . time . LocalDateTime dateTime = dateTimeSeconds .withNano (microOfSecond * 1_000 );
275319 checkValidDateTimeMicros (dateTime );
276320 return dateTime ;
277321 }
@@ -280,25 +324,25 @@ private static int getFieldFromBitField(long bitField, long mask, int shift) {
280324 return (int ) ((bitField & mask ) >> shift );
281325 }
282326
283- private static void checkValidTimeSeconds (LocalTime time ) {
327+ private static void checkValidTimeSeconds (java . time . LocalTime time ) {
284328 checkArgument (time .getHour () >= 0 && time .getHour () <= 23 );
285329 checkArgument (time .getMinute () >= 0 && time .getMinute () <= 59 );
286330 checkArgument (time .getSecond () >= 0 && time .getSecond () <= 59 );
287331 }
288332
289- private static void checkValidDateTimeSeconds (LocalDateTime dateTime ) {
333+ private static void checkValidDateTimeSeconds (java . time . LocalDateTime dateTime ) {
290334 checkArgument (dateTime .getYear () >= 1 && dateTime .getYear () <= 9999 );
291335 checkArgument (dateTime .getMonthValue () >= 1 && dateTime .getMonthValue () <= 12 );
292336 checkArgument (dateTime .getDayOfMonth () >= 1 && dateTime .getDayOfMonth () <= 31 );
293337 checkValidTimeSeconds (dateTime .toLocalTime ());
294338 }
295339
296- private static void checkValidTimeMicros (LocalTime time ) {
340+ private static void checkValidTimeMicros (java . time . LocalTime time ) {
297341 checkValidTimeSeconds (time );
298342 checkArgument (time .equals (time .truncatedTo (ChronoUnit .MICROS )));
299343 }
300344
301- private static void checkValidDateTimeMicros (LocalDateTime dateTime ) {
345+ private static void checkValidDateTimeMicros (java . time . LocalDateTime dateTime ) {
302346 checkValidDateTimeSeconds (dateTime );
303347 checkArgument (dateTime .equals (dateTime .truncatedTo (ChronoUnit .MICROS )));
304348 }
0 commit comments