Class DateTimeHelpers


  • @Internal
    public final class DateTimeHelpers
    extends java.lang.Object
    Collection of utility methods for CEL datetime handlings.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String UTC  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.time.Duration add​(java.time.Duration d1, java.time.Duration d2)
      Adds two durations
      static java.time.Instant add​(java.time.Instant ts, java.time.Duration dur)
      Adds a duration to an instant.
      static void checkValid​(java.time.Instant instant)
      Throws an IllegalArgumentException if the given Timestamp is not valid.
      static java.time.LocalDateTime newLocalDateTime​(com.google.protobuf.Timestamp ts, java.lang.String tz)
      Constructs a new LocalDateTime instance
      static java.time.LocalDateTime newLocalDateTime​(java.time.Instant instant, java.lang.String tz)
      Constructs a new LocalDateTime instance from a Java Instant.
      static java.time.Instant parse​(java.lang.String text)
      Parse from RFC 3339 date string to Instant.
      static java.time.Duration subtract​(java.time.Duration d1, java.time.Duration d2)
      Subtract a duration from another.
      static java.time.Instant subtract​(java.time.Instant ts, java.time.Duration dur)
      Subtracts a duration to an instant.
      static java.lang.String toString​(java.time.Duration duration)
      Formats a Duration into a minimal seconds-based representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newLocalDateTime

        public static java.time.LocalDateTime newLocalDateTime​(com.google.protobuf.Timestamp ts,
                                                               java.lang.String tz)
        Constructs a new LocalDateTime instance
        Parameters:
        ts - Timestamp protobuf object
        tz - 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 new LocalDateTime instance from a Java Instant.
        Parameters:
        instant - Instant object
        tz - 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 LocalDateTime instance.
      • parse

        public static java.time.Instant parse​(java.lang.String text)
        Parse from RFC 3339 date string to Instant.

        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 a Duration into a minimal seconds-based representation.

        Note: follows ProtoTimeUtils#toString(Duration) implementation

      • checkValid

        public static void checkValid​(java.time.Instant instant)
        Throws an IllegalArgumentException if the given Timestamp is not valid.