Skip to content

Commit

Permalink
Remove deprecation warnings for Timestamp and Duration add/subtract/b…
Browse files Browse the repository at this point in the history
…etween that we do not yet have alternatives to.

Fixes #18925

PiperOrigin-RevId: 691117251
  • Loading branch information
deannagarcia committed Oct 31, 2024
1 parent 53cde64 commit f606c13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 57 deletions.
24 changes: 2 additions & 22 deletions java/util/src/main/java/com/google/protobuf/util/Durations.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,35 +422,15 @@ public static long toNanos(Duration duration) {

// Math operations

/**
* Add two durations.
*
* <!-- MOE:begin_intracomment_strip -->
* @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Duration}
* using {@link com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the
* arithmetic there, and convert back using {@link
* com.google.protobuf.util.JavaTimeConversions#toProtoDuration}.
* <!-- MOE:end_intracomment_strip -->
*/
@Deprecated // MOE:strip_line
/** Add two durations. */
public static Duration add(Duration d1, Duration d2) {
checkValid(d1);
checkValid(d2);
return normalizedDuration(
checkedAdd(d1.getSeconds(), d2.getSeconds()), checkedAdd(d1.getNanos(), d2.getNanos()));
}

/**
* Subtract a duration from another.
*
* <!-- MOE:begin_intracomment_strip -->
* @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Duration}
* using {@link com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the
* arithmetic there, and convert back using {@link
* com.google.protobuf.util.JavaTimeConversions#toProtoDuration}.
* <!-- MOE:end_intracomment_strip -->
*/
@Deprecated // MOE:strip_line
/** Subtract a duration from another. */
public static Duration subtract(Duration d1, Duration d2) {
checkValid(d1);
checkValid(d2);
Expand Down
38 changes: 3 additions & 35 deletions java/util/src/main/java/com/google/protobuf/util/Timestamps.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,7 @@ public static long toNanos(Timestamp timestamp) {
checkedMultiply(timestamp.getSeconds(), NANOS_PER_SECOND), timestamp.getNanos());
}

/**
* Calculate the difference between two timestamps.
*
* <!-- MOE:begin_intracomment_strip -->
* @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Instant}
* using {@link com.google.protobuf.util.JavaTimeConversions#toJavaInstant}, do the arithmetic
* there, and convert back using {@link
* com.google.protobuf.util.JavaTimeConversions#toProtoDuration}.
* <!-- MOE:end_intracomment_strip -->
*/
@Deprecated // MOE:strip_line
/** Calculate the difference between two timestamps. */
public static Duration between(Timestamp from, Timestamp to) {
checkValid(from);
checkValid(to);
Expand All @@ -456,18 +446,7 @@ public static Duration between(Timestamp from, Timestamp to) {
checkedSubtract(to.getNanos(), from.getNanos()));
}

/**
* Add a duration to a timestamp.
*
* <!-- MOE:begin_intracomment_strip -->
* @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Instant}
* and {@link java.time.Duration} using {@link
* com.google.protobuf.util.JavaTimeConversions#toJavaInstant} and {@link
* com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, and
* convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoTimestamp}.
* <!-- MOE:end_intracomment_strip -->
*/
@Deprecated // MOE:strip_line
/** Add a duration to a timestamp. */
public static Timestamp add(Timestamp start, Duration length) {
checkValid(start);
Durations.checkValid(length);
Expand All @@ -476,18 +455,7 @@ public static Timestamp add(Timestamp start, Duration length) {
checkedAdd(start.getNanos(), length.getNanos()));
}

/**
* Subtract a duration from a timestamp.
*
* <!-- MOE:begin_intracomment_strip -->
* @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Instant}
* and {@link java.time.Duration} using {@link
* com.google.protobuf.util.JavaTimeConversions#toJavaInstant} and {@link
* com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, and
* convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoTimestamp}.
* <!-- MOE:end_intracomment_strip -->
*/
@Deprecated // MOE:strip_line
/** Subtract a duration from a timestamp. */
public static Timestamp subtract(Timestamp start, Duration length) {
checkValid(start);
Durations.checkValid(length);
Expand Down

0 comments on commit f606c13

Please sign in to comment.