Package dev.cel.common.internal
Class DateTimeHelpers
- java.lang.Object
-
- dev.cel.common.internal.DateTimeHelpers
-
@Internal public final class DateTimeHelpers extends java.lang.ObjectCollection of utility methods for CEL datetime handlings.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringUTC
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.time.Durationadd(java.time.Duration d1, java.time.Duration d2)Adds two durationsstatic java.time.Instantadd(java.time.Instant ts, java.time.Duration dur)Adds a duration to an instant.static voidcheckValid(java.time.Instant instant)Throws anIllegalArgumentExceptionif the givenTimestampis not valid.static java.time.LocalDateTimenewLocalDateTime(com.google.protobuf.Timestamp ts, java.lang.String tz)Constructs a newLocalDateTimeinstancestatic java.time.LocalDateTimenewLocalDateTime(java.time.Instant instant, java.lang.String tz)Constructs a newLocalDateTimeinstance from a Java Instant.static java.time.Instantparse(java.lang.String text)Parse from RFC 3339 date string toInstant.static java.time.Durationsubtract(java.time.Duration d1, java.time.Duration d2)Subtract a duration from another.static java.time.Instantsubtract(java.time.Instant ts, java.time.Duration dur)Subtracts a duration to an instant.static java.lang.StringtoString(java.time.Duration duration)Formats aDurationinto a minimal seconds-based representation.
-
-
-
Field Detail
-
UTC
public static final java.lang.String UTC
- See Also:
- Constant Field Values
-
-
Method Detail
-
newLocalDateTime
public static java.time.LocalDateTime newLocalDateTime(com.google.protobuf.Timestamp ts, java.lang.String tz)Constructs a newLocalDateTimeinstance- Parameters:
ts- Timestamp protobuf objecttz- Timezone based on the CEL specification. This is either the canonical name from tz database or a standard offset represented in (+/-)HH:MM. Few valid examples are:- UTC
- America/Los_Angeles
- -09:30 or -9:30 (Leading zeroes can be omitted though not allowed by spec)
- Returns:
- If an Invalid timezone is supplied.
-
newLocalDateTime
public static java.time.LocalDateTime newLocalDateTime(java.time.Instant instant, java.lang.String tz)Constructs a newLocalDateTimeinstance from a Java Instant.- Parameters:
instant- Instant objecttz- Timezone based on the CEL specification. This is either the canonical name from tz database or a standard offset represented in (+/-)HH:MM. Few valid examples are:- UTC
- America/Los_Angeles
- -09:30 or -9:30 (Leading zeroes can be omitted though not allowed by spec)
- Returns:
- A new
LocalDateTimeinstance.
-
parse
public static java.time.Instant parse(java.lang.String text)
Parse from RFC 3339 date string toInstant.Example of accepted format: "1972-01-01T10:00:20.021-05:00"
-
add
public static java.time.Instant add(java.time.Instant ts, java.time.Duration dur)Adds a duration to an instant.
-
add
public static java.time.Duration add(java.time.Duration d1, java.time.Duration d2)Adds two durations
-
subtract
public static java.time.Instant subtract(java.time.Instant ts, java.time.Duration dur)Subtracts a duration to an instant.
-
subtract
public static java.time.Duration subtract(java.time.Duration d1, java.time.Duration d2)Subtract a duration from another.
-
toString
public static java.lang.String toString(java.time.Duration duration)
Formats aDurationinto a minimal seconds-based representation.Note: follows
ProtoTimeUtils#toString(Duration)implementation
-
checkValid
public static void checkValid(java.time.Instant instant)
Throws anIllegalArgumentExceptionif the givenTimestampis not valid.
-
-