Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
com.google.protobuf.util.TimeUtil Class Reference

Static Public Member Functions

static Duration add (Duration d1, Duration d2)
 
static Timestamp add (Timestamp start, Duration length)
 
static Duration createDurationFromMicros (long microseconds)
 
static Duration createDurationFromMillis (long milliseconds)
 
static Duration createDurationFromNanos (long nanoseconds)
 
static Timestamp createTimestampFromMicros (long microseconds)
 
static Timestamp createTimestampFromMillis (long milliseconds)
 
static Timestamp createTimestampFromNanos (long nanoseconds)
 
static Duration distance (Timestamp from, Timestamp to)
 
static long divide (Duration d1, Duration d2)
 
static Duration divide (Duration duration, double value)
 
static Duration divide (Duration duration, long times)
 
static Timestamp getCurrentTime ()
 
static Timestamp getEpoch ()
 
static Duration multiply (Duration duration, double times)
 
static Duration multiply (Duration duration, long times)
 
static Duration parseDuration (String value) throws ParseException
 
static Timestamp parseTimestamp (String value) throws ParseException
 
static Duration remainder (Duration d1, Duration d2)
 
static Duration subtract (Duration d1, Duration d2)
 
static Timestamp subtract (Timestamp start, Duration length)
 
static long toMicros (Duration duration)
 
static long toMicros (Timestamp timestamp)
 
static long toMillis (Duration duration)
 
static long toMillis (Timestamp timestamp)
 
static long toNanos (Duration duration)
 
static long toNanos (Timestamp timestamp)
 
static String toString (Duration duration)
 
static String toString (Timestamp timestamp)
 

Static Public Attributes

static final long DURATION_SECONDS_MAX = 315576000000L
 
static final long DURATION_SECONDS_MIN = -315576000000L
 
static final long TIMESTAMP_SECONDS_MAX = 253402300799L
 
static final long TIMESTAMP_SECONDS_MIN = -62135596800L
 

Private Member Functions

 TimeUtil ()
 

Static Private Member Functions

static Duration createDurationFromBigInteger (BigInteger value)
 
static Duration normalizedDuration (long seconds, int nanos)
 
static BigInteger toBigInteger (Duration duration)
 
static BigInteger toBigInteger (long value)
 

Static Private Attributes

static final long NANOS_PER_SECOND = 1000000000
 
static final BigInteger NANOS_PER_SECOND_BIG_INTEGER
 

Detailed Description

Utilities to help create/manipulate Timestamp/Duration

Deprecated:
Use Durations and Timestamps instead.

Definition at line 45 of file TimeUtil.java.

Constructor & Destructor Documentation

◆ TimeUtil()

com.google.protobuf.util.TimeUtil.TimeUtil ( )
inlineprivate

Definition at line 56 of file TimeUtil.java.

Member Function Documentation

◆ add() [1/2]

static Duration com.google.protobuf.util.TimeUtil.add ( Duration  d1,
Duration  d2 
)
inlinestatic

Add two durations.

Deprecated:
Use Durations#add instead.

Definition at line 311 of file TimeUtil.java.

◆ add() [2/2]

static Timestamp com.google.protobuf.util.TimeUtil.add ( Timestamp  start,
Duration  length 
)
inlinestatic

Add a duration to a timestamp.

Deprecated:
Use Timestamps#add instead.

Definition at line 291 of file TimeUtil.java.

◆ createDurationFromBigInteger()

static Duration com.google.protobuf.util.TimeUtil.createDurationFromBigInteger ( BigInteger  value)
inlinestaticprivate

Definition at line 377 of file TimeUtil.java.

◆ createDurationFromMicros()

static Duration com.google.protobuf.util.TimeUtil.createDurationFromMicros ( long  microseconds)
inlinestatic

Create a Duration from the number of microseconds.

Deprecated:
Use Durations#fromMicros instead.

Definition at line 185 of file TimeUtil.java.

◆ createDurationFromMillis()

static Duration com.google.protobuf.util.TimeUtil.createDurationFromMillis ( long  milliseconds)
inlinestatic

Create a Duration from the number of milliseconds.

Deprecated:
Use Durations#fromMillis instead.

Definition at line 139 of file TimeUtil.java.

◆ createDurationFromNanos()

static Duration com.google.protobuf.util.TimeUtil.createDurationFromNanos ( long  nanoseconds)
inlinestatic

Create a Duration from the number of nanoseconds.

Deprecated:
Use Durations#fromNanos instead.

Definition at line 231 of file TimeUtil.java.

◆ createTimestampFromMicros()

static Timestamp com.google.protobuf.util.TimeUtil.createTimestampFromMicros ( long  microseconds)
inlinestatic

Create a Timestamp from the number of microseconds elapsed from the epoch.

Deprecated:
Use Timestamps#fromMicros instead.

Definition at line 175 of file TimeUtil.java.

◆ createTimestampFromMillis()

static Timestamp com.google.protobuf.util.TimeUtil.createTimestampFromMillis ( long  milliseconds)
inlinestatic

Create a Timestamp from the number of milliseconds elapsed from the epoch.

Deprecated:
Use Timestamps#fromMillis instead.

Definition at line 129 of file TimeUtil.java.

◆ createTimestampFromNanos()

static Timestamp com.google.protobuf.util.TimeUtil.createTimestampFromNanos ( long  nanoseconds)
inlinestatic

Create a Timestamp from the number of nanoseconds elapsed from the epoch.

Deprecated:
Use Timestamps#fromNanos instead.

Definition at line 221 of file TimeUtil.java.

◆ distance()

static Duration com.google.protobuf.util.TimeUtil.distance ( Timestamp  from,
Timestamp  to 
)
inlinestatic

Calculate the difference between two timestamps.

Deprecated:
Use Timestamps#between instead.

Definition at line 281 of file TimeUtil.java.

◆ divide() [1/3]

static long com.google.protobuf.util.TimeUtil.divide ( Duration  d1,
Duration  d2 
)
inlinestatic

Definition at line 355 of file TimeUtil.java.

◆ divide() [2/3]

static Duration com.google.protobuf.util.TimeUtil.divide ( Duration  duration,
double  value 
)
inlinestatic

Definition at line 340 of file TimeUtil.java.

◆ divide() [3/3]

static Duration com.google.protobuf.util.TimeUtil.divide ( Duration  duration,
long  times 
)
inlinestatic

Definition at line 350 of file TimeUtil.java.

◆ getCurrentTime()

static Timestamp com.google.protobuf.util.TimeUtil.getCurrentTime ( )
inlinestatic

Get the current time.

Deprecated:
Use
Timestamps.fromMillis(System.currentTimeMillis())

instead.

Definition at line 261 of file TimeUtil.java.

◆ getEpoch()

static Timestamp com.google.protobuf.util.TimeUtil.getEpoch ( )
inlinestatic

Get the epoch.

Deprecated:
Use
Timestamps.fromMillis(0)

instead.

Definition at line 271 of file TimeUtil.java.

◆ multiply() [1/2]

static Duration com.google.protobuf.util.TimeUtil.multiply ( Duration  duration,
double  times 
)
inlinestatic

Definition at line 329 of file TimeUtil.java.

◆ multiply() [2/2]

static Duration com.google.protobuf.util.TimeUtil.multiply ( Duration  duration,
long  times 
)
inlinestatic

Definition at line 345 of file TimeUtil.java.

◆ normalizedDuration()

static Duration com.google.protobuf.util.TimeUtil.normalizedDuration ( long  seconds,
int  nanos 
)
inlinestaticprivate

Definition at line 383 of file TimeUtil.java.

◆ parseDuration()

static Duration com.google.protobuf.util.TimeUtil.parseDuration ( String  value) throws ParseException
inlinestatic

Parse from a string to produce a duration.

Returns
A Duration parsed from the string.
Exceptions
ParseExceptionif parsing fails.
Deprecated:
Use Durations#parse instead.

Definition at line 119 of file TimeUtil.java.

◆ parseTimestamp()

static Timestamp com.google.protobuf.util.TimeUtil.parseTimestamp ( String  value) throws ParseException
inlinestatic

Parse from RFC 3339 date string to Timestamp. This method accepts all outputs of toString(Timestamp) and it also accepts any fractional digits (or none) and any offset as long as they fit into nano-seconds precision.

Example of accepted format: "1972-01-01T10:00:20.021-05:00"

Returns
A Timestamp parsed from the string.
Exceptions
ParseExceptionif parsing fails.
Deprecated:
Use Timestamps#parse instead.

Definition at line 90 of file TimeUtil.java.

◆ remainder()

static Duration com.google.protobuf.util.TimeUtil.remainder ( Duration  d1,
Duration  d2 
)
inlinestatic

Definition at line 360 of file TimeUtil.java.

◆ subtract() [1/2]

static Duration com.google.protobuf.util.TimeUtil.subtract ( Duration  d1,
Duration  d2 
)
inlinestatic

Subtract a duration from another.

Deprecated:
Use Durations#subtract instead.

Definition at line 321 of file TimeUtil.java.

◆ subtract() [2/2]

static Timestamp com.google.protobuf.util.TimeUtil.subtract ( Timestamp  start,
Duration  length 
)
inlinestatic

Subtract a duration from a timestamp.

Deprecated:
Use Timestamps#subtract instead.

Definition at line 301 of file TimeUtil.java.

◆ toBigInteger() [1/2]

static BigInteger com.google.protobuf.util.TimeUtil.toBigInteger ( Duration  duration)
inlinestaticprivate

Definition at line 367 of file TimeUtil.java.

◆ toBigInteger() [2/2]

static BigInteger com.google.protobuf.util.TimeUtil.toBigInteger ( long  value)
inlinestaticprivate

Definition at line 373 of file TimeUtil.java.

◆ toMicros() [1/2]

static long com.google.protobuf.util.TimeUtil.toMicros ( Duration  duration)
inlinestatic

Convert a Duration to the number of microseconds.The result will be rounded towards 0 to the nearest microseconds. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.

Deprecated:
Use Durations#toMicros instead.

Definition at line 211 of file TimeUtil.java.

◆ toMicros() [2/2]

static long com.google.protobuf.util.TimeUtil.toMicros ( Timestamp  timestamp)
inlinestatic

Convert a Timestamp to the number of microseconds elapsed from the epoch.

The result will be rounded down to the nearest microsecond. E.g., if the timestamp represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond.

Deprecated:
Use Timestamps#toMicros instead.

Definition at line 199 of file TimeUtil.java.

◆ toMillis() [1/2]

static long com.google.protobuf.util.TimeUtil.toMillis ( Duration  duration)
inlinestatic

Convert a Duration to the number of milliseconds.The result will be rounded towards 0 to the nearest millisecond. E.g., if the duration represents -1 nanosecond, it will be rounded to 0.

Deprecated:
Use Durations#toMillis instead.

Definition at line 165 of file TimeUtil.java.

◆ toMillis() [2/2]

static long com.google.protobuf.util.TimeUtil.toMillis ( Timestamp  timestamp)
inlinestatic

Convert a Timestamp to the number of milliseconds elapsed from the epoch.

The result will be rounded down to the nearest millisecond. E.g., if the timestamp represents "1969-12-31T23:59:59.999999999Z", it will be rounded to -1 millisecond.

Deprecated:
Use Timestamps#toMillis instead.

Definition at line 153 of file TimeUtil.java.

◆ toNanos() [1/2]

static long com.google.protobuf.util.TimeUtil.toNanos ( Duration  duration)
inlinestatic

Convert a Duration to the number of nanoseconds.

Deprecated:
Use Durations#toNanos instead.

Definition at line 251 of file TimeUtil.java.

◆ toNanos() [2/2]

static long com.google.protobuf.util.TimeUtil.toNanos ( Timestamp  timestamp)
inlinestatic

Convert a Timestamp to the number of nanoseconds elapsed from the epoch.

Deprecated:
Use Timestamps#toNanos instead.

Definition at line 241 of file TimeUtil.java.

◆ toString() [1/2]

static String com.google.protobuf.util.TimeUtil.toString ( Duration  duration)
inlinestatic

Convert Duration to string format. The string format will contains 3, 6, or 9 fractional digits depending on the precision required to represent the exact Duration value. For example: "1s", "1.010s", "1.000000100s", "-3.100s" The range that can be represented by Duration is from -315,576,000,000 to +315,576,000,000 inclusive (in seconds).

Returns
The string representation of the given duration.
Exceptions
IllegalArgumentExceptionif the given duration is not in the valid range.
Deprecated:
Use Durations#toString instead.

Definition at line 107 of file TimeUtil.java.

◆ toString() [2/2]

static String com.google.protobuf.util.TimeUtil.toString ( Timestamp  timestamp)
inlinestatic

Convert Timestamp to RFC 3339 date string format. The output will always be Z-normalized and uses 3, 6 or 9 fractional digits as required to represent the exact value. Note that Timestamp can only represent time from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. See https://www.ietf.org/rfc/rfc3339.txt

Example of generated format: "1972-01-01T10:00:20.021Z"

Returns
The string representation of the given timestamp.
Exceptions
IllegalArgumentExceptionif the given timestamp is not in the valid range.
Deprecated:
Use Timestamps#toString instead.

Definition at line 73 of file TimeUtil.java.

Member Data Documentation

◆ DURATION_SECONDS_MAX

final long com.google.protobuf.util.TimeUtil.DURATION_SECONDS_MAX = 315576000000L
static

Definition at line 52 of file TimeUtil.java.

◆ DURATION_SECONDS_MIN

final long com.google.protobuf.util.TimeUtil.DURATION_SECONDS_MIN = -315576000000L
static

Definition at line 51 of file TimeUtil.java.

◆ NANOS_PER_SECOND

final long com.google.protobuf.util.TimeUtil.NANOS_PER_SECOND = 1000000000
staticprivate

Definition at line 54 of file TimeUtil.java.

◆ NANOS_PER_SECOND_BIG_INTEGER

final BigInteger com.google.protobuf.util.TimeUtil.NANOS_PER_SECOND_BIG_INTEGER
staticprivate
Initial value:
=
new BigInteger(String.valueOf(NANOS_PER_SECOND))

Definition at line 364 of file TimeUtil.java.

◆ TIMESTAMP_SECONDS_MAX

final long com.google.protobuf.util.TimeUtil.TIMESTAMP_SECONDS_MAX = 253402300799L
static

Definition at line 50 of file TimeUtil.java.

◆ TIMESTAMP_SECONDS_MIN

final long com.google.protobuf.util.TimeUtil.TIMESTAMP_SECONDS_MIN = -62135596800L
static

Definition at line 47 of file TimeUtil.java.


The documentation for this class was generated from the following file:
com.google.protobuf.util.TimeUtil.NANOS_PER_SECOND
static final long NANOS_PER_SECOND
Definition: TimeUtil.java:54


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:09