-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce
java.time
methods and variables (#2780)
This PR introduces `java.time` alternatives to existing `org.threeten.bp.*` methods, as well as switching internal variables (if any) to `java.time` The main constraint is to keep the changes backwards compatible, so for each existing threeten method "`method1(org.threeten.bp.Duration)`" we will add an alternative with a _Duration_ (or _Timestamp_ when applicable) suffix: "`method1Duration(java.time.Duration)`". For most cases, the implementation will be held in the `java.time` method and the old threeten method will just delegate the call to it. However, for the case of abstract classes, the implementation will be kept in the threeten method to avoid breaking changes (i.e. users that already overloaded the method in their user code).
- Loading branch information
1 parent
7703ab2
commit 8dd66d5
Showing
40 changed files
with
473 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...uerystorage/src/main/java/com/google/cloud/bigquery/storage/util/TimeConversionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.bigquery.storage.util; | ||
|
||
import com.google.api.core.InternalApi; | ||
|
||
/** | ||
* Convenience methods for conversions between {@link java.time} and {@link org.threeten.bp} | ||
* objects. This will be kept until <a | ||
* href="https://github.com/googleapis/sdk-platform-java/issues/3412">this issue</a> is solved. | ||
*/ | ||
@InternalApi("https://github.com/googleapis/sdk-platform-java/issues/3412") | ||
public class TimeConversionUtils { | ||
public static java.time.LocalDateTime toJavaTimeLocalDateTime( | ||
org.threeten.bp.LocalDateTime result) { | ||
return java.time.LocalDateTime.of( | ||
result.getYear(), | ||
java.time.Month.of(result.getMonth().getValue()), | ||
result.getDayOfMonth(), | ||
result.getHour(), | ||
result.getMinute(), | ||
result.getSecond(), | ||
result.getNano()); | ||
} | ||
|
||
public static org.threeten.bp.LocalDateTime toThreetenLocalDateTime( | ||
java.time.LocalDateTime result) { | ||
return org.threeten.bp.LocalDateTime.of( | ||
result.getYear(), | ||
org.threeten.bp.Month.of(result.getMonth().getValue()), | ||
result.getDayOfMonth(), | ||
result.getHour(), | ||
result.getMinute(), | ||
result.getSecond(), | ||
result.getNano()); | ||
} | ||
|
||
public static java.time.LocalTime toJavaTimeLocalTime(org.threeten.bp.LocalTime result) { | ||
return java.time.LocalTime.of( | ||
result.getHour(), result.getMinute(), result.getSecond(), result.getNano()); | ||
} | ||
|
||
public static org.threeten.bp.LocalTime toThreetenLocalTime(java.time.LocalTime result) { | ||
return org.threeten.bp.LocalTime.of( | ||
result.getHour(), result.getMinute(), result.getSecond(), result.getNano()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.