Skip to content

Commit

Permalink
(feat): Duration/Timestamp utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Dec 27, 2023
1 parent aee00da commit ca990cc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/dev/emortal/api/utils/ProtoDurationConverter.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.emortal.api.utils;

import com.google.protobuf.Duration;
import com.google.protobuf.Timestamp;
import org.jetbrains.annotations.NotNull;

import java.time.Instant;

public final class ProtoDurationConverter {
private static final long NANOS_PER_SECOND = 1_000_000_000;

Expand Down Expand Up @@ -31,6 +34,14 @@ public final class ProtoDurationConverter {
.build();
}

public static @NotNull java.time.Duration betweenFromProto(@NotNull Timestamp start, @NotNull Timestamp end) {
return java.time.Duration.between(ProtoTimestampConverter.fromProto(start), ProtoTimestampConverter.fromProto(end));
}

public static @NotNull Duration betweenToProto(@NotNull Instant start, @NotNull Instant end) {
return toProto(java.time.Duration.between(start, end));
}

private ProtoDurationConverter() {
}
}

0 comments on commit ca990cc

Please sign in to comment.