Top Description Inners Fields Constructors Methods
com.google.protobuf

public final Class Duration

extends GeneratedMessageV3
implements DurationOrBuilder
Class Inheritance
All Implemented Interfaces
com.google.protobuf.DurationOrBuilder, com.google.protobuf.MessageOrBuilder, com.google.protobuf.MessageLiteOrBuilder

A Duration represents a signed, fixed-length span of time represented
as a count of seconds and fractions of seconds at nanosecond
resolution. It is independent of any calendar and concepts like "day"
or "month". It is related to Timestamp in that the difference between
two Timestamp values is a Duration and it can be added or subtracted
from a Timestamp. Range is approximately +-10,000 years.
# Examples
Example 1: Compute Duration from two Timestamps in pseudo code.
    Timestamp start = ...;
    Timestamp end = ...;
    Duration duration = ...;
    duration.seconds = end.seconds - start.seconds;
    duration.nanos = end.nanos - start.nanos;
    if (duration.seconds < 0 && duration.nanos > 0) {
      duration.seconds += 1;
      duration.nanos -= 1000000000;
    } else if (durations.seconds > 0 && duration.nanos < 0) {
      duration.seconds -= 1;
      duration.nanos += 1000000000;
    }
Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
    Timestamp start = ...;
    Duration duration = ...;
    Timestamp end = ...;
    end.seconds = start.seconds + duration.seconds;
    end.nanos = start.nanos + duration.nanos;
    if (end.nanos < 0) {
      end.seconds -= 1;
      end.nanos += 1000000000;
    } else if (end.nanos >= 1000000000) {
      end.seconds += 1;
      end.nanos -= 1000000000;
    }
Example 3: Compute Duration from datetime.timedelta in Python.
    td = datetime.timedelta(days=3, minutes=10)
    duration = Duration()
    duration.FromTimedelta(td)
# JSON Mapping
In JSON format, the Duration type is encoded as a string rather than an
object, where the string ends in the suffix "s" (indicating seconds) and
is preceded by the number of seconds, with nanoseconds expressed as
fractional seconds. For example, 3 seconds with 0 nanoseconds should be
encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
be expressed in JSON format as "3.000000001s", and 3 seconds and 1
microsecond should be expressed in JSON format as "3.000001s".
Protobuf type google.protobuf.Duration

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Duration.Builder

A Duration represents a signed, fixed-length span of time represented
as a count of seconds and fractions of seconds at nanosecond
resolution.

Field Summary

Modifier and TypeField and Description
private static final Duration
private byte
private int
public static final int
private static final Parser<Duration>
private long
public static final int
private static final long
Inherited from com.google.protobuf.GeneratedMessageV3:
alwaysUseFieldBuildersunknownFields

Constructor Summary

AccessConstructor and Description
private
private
private

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(final Object
object to be compared for equality with this message
obj
)

Overrides com.google.protobuf.AbstractMessage.equals.

Implements com.google.protobuf.Message.equals.

Compares the specified object with this message for equality.
public static Duration
public Duration
public static final Descriptors.Descriptor
public int
getNanos()

Implements com.google.protobuf.DurationOrBuilder.getNanos.

Signed fractions of a second at nanosecond resolution of the span
of time.
public Parser<Duration>
public long
getSeconds()

Implements com.google.protobuf.DurationOrBuilder.getSeconds.

Signed seconds of the span of time.
public int
getSerializedSize()

Overrides com.google.protobuf.GeneratedMessageV3.getSerializedSize.

Implements com.google.protobuf.MessageLite.getSerializedSize.

Get the number of bytes required to encode this message.
public final UnknownFieldSet
public int
hashCode()

Overrides com.google.protobuf.AbstractMessage.hashCode.

Implements com.google.protobuf.Message.hashCode.

Returns the hash code value for this message.
protected GeneratedMessageV3.FieldAccessorTable
internalGetFieldAccessorTable()

Implements abstract com.google.protobuf.GeneratedMessageV3.internalGetFieldAccessorTable.

Get the FieldAccessorTable for this type.
public final boolean
isInitialized()

Overrides com.google.protobuf.GeneratedMessageV3.isInitialized.

Implements com.google.protobuf.MessageLiteOrBuilder.isInitialized.

Returns true if all required fields in the message and all embedded messages are set, false otherwise.
public static Duration.Builder
public static Duration.Builder
newBuilder(Duration prototype)

public Duration.Builder
newBuilderForType()

Implements com.google.protobuf.Message.newBuilderForType, com.google.protobuf.MessageLite.newBuilderForType.

Constructs a new builder for a message of the same type as this message.
protected Duration.Builder
newBuilderForType(GeneratedMessageV3.BuilderParent parent)

Implements abstract com.google.protobuf.GeneratedMessageV3.newBuilderForType.

TODO(xiaofeng): remove this together with GeneratedMessageV3.BuilderParent.
public static Duration
public static Duration
public static Duration
public static Duration
parseFrom(ByteBuffer data, ExtensionRegistryLite extensionRegistry)

public static Duration
public static Duration
parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry)

public static Duration
parseFrom(byte[] data)

public static Duration
parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry)

public static Duration
public static Duration
parseFrom(InputStream input, ExtensionRegistryLite extensionRegistry)

public static Duration
public static Duration
public static Parser<Duration>
public Duration.Builder
toBuilder()

Implements com.google.protobuf.Message.toBuilder, com.google.protobuf.MessageLite.toBuilder.

Constructs a builder initialized with the current message.
public void
writeTo(CodedOutputStream output)

Overrides com.google.protobuf.GeneratedMessageV3.writeTo.

Implements com.google.protobuf.MessageLite.writeTo.

Serializes the message and writes it to output.
Inherited from com.google.protobuf.GeneratedMessageV3:
canUseUnsafecomputeStringSizecomputeStringSizeNoTagemptyBooleanListemptyDoubleListemptyFloatListemptyIntListemptyLongListenableAlwaysUseFieldBuildersForTestinggetAllFieldsgetAllFieldsRawgetDescriptorForTypegetFieldgetFieldRawgetOneofFieldDescriptorgetRepeatedFieldgetRepeatedFieldCounthasFieldhasOneofinternalGetMapFieldmakeExtensionsImmutablemutableCopymutableCopymutableCopymutableCopymutableCopynewBooleanListnewBuilderForTypenewDoubleListnewFloatListnewIntListnewLongListparseDelimitedWithIOExceptionparseDelimitedWithIOExceptionparseUnknownFieldparseUnknownFieldProto3parseWithIOExceptionparseWithIOExceptionparseWithIOExceptionparseWithIOExceptionserializeBooleanMapToserializeIntegerMapToserializeLongMapToserializeStringMapTowriteReplacewriteStringwriteStringNoTag