final case class Duration(seconds: Long = 0L, nanos: Int = 0, unknownFields: scalapb.UnknownFieldSet = _root_.scalapb.UnknownFieldSet.empty) extends scalapb.GeneratedMessage with Updatable[Duration] with DurationMethods with Product with Serializable
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 (duration.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".
- seconds
Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. Note: these bounds are computed from: 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
- nanos
Signed fractions of a second at nanosecond resolution of the span of time. Durations less than one second are represented with a 0
seconds
field and a positive or negativenanos
field. For durations of one second or more, a non-zero value for thenanos
field must be of the same sign as theseconds
field. Must be from -999,999,999 to +999,999,999 inclusive.
- Annotations
- @SerialVersionUID()
- Alphabetic
- By Inheritance
- Duration
- DurationMethods
- Updatable
- GeneratedMessage
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Duration(seconds: Long = 0L, nanos: Int = 0, unknownFields: scalapb.UnknownFieldSet = _root_.scalapb.UnknownFieldSet.empty)
- seconds
Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. Note: these bounds are computed from: 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
- nanos
Signed fractions of a second at nanosecond resolution of the span of time. Durations less than one second are represented with a 0
seconds
field and a positive or negativenanos
field. For durations of one second or more, a non-zero value for thenanos
field must be of the same sign as theseconds
field. Must be from -999,999,999 to +999,999,999 inclusive.
Value Members
- final def !=(arg0: scala.Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: scala.Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- final def asJavaDuration: java.time.Duration
- Definition Classes
- DurationMethods
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def companion: Duration.type
- Definition Classes
- Duration → GeneratedMessage
- def discardUnknownFields: Duration
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def getField(__field: FieldDescriptor): PValue
- Definition Classes
- Duration → GeneratedMessage
- def getFieldByNumber(__fieldNumber: Int): scala.Any
- Definition Classes
- Duration → GeneratedMessage
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- val nanos: Int
- Definition Classes
- Duration → DurationMethods
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- val seconds: Long
- Definition Classes
- Duration → DurationMethods
- def serializedSize: Int
- Definition Classes
- Duration → GeneratedMessage
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- final def toByteArray: Array[Byte]
Serializes the message and returns a byte array containing its raw bytes
Serializes the message and returns a byte array containing its raw bytes
- Definition Classes
- GeneratedMessage
- final def toByteString: ByteString
Serializes the message and returns a ByteString containing its raw bytes
Serializes the message and returns a ByteString containing its raw bytes
- Definition Classes
- GeneratedMessage
- final def toPMessage: PMessage
- Definition Classes
- GeneratedMessage
- def toProtoString: String
Returns a human-readable ASCII format representation of this message.
Returns a human-readable ASCII format representation of this message.
The original message can be decoded from this format by using fromAscii on the companion object.
- returns
human-readable representation of this message.
- Definition Classes
- Duration → GeneratedMessage
- val unknownFields: scalapb.UnknownFieldSet
- def update(ms: (Lens[Duration, Duration]) => Mutation[Duration]*): Duration
- Definition Classes
- Updatable
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withNanos(__v: Int): Duration
- def withSeconds(__v: Long): Duration
- def withUnknownFields(__v: scalapb.UnknownFieldSet): Duration
- final def writeDelimitedTo(output: OutputStream): Unit
- Definition Classes
- GeneratedMessage
- def writeTo(_output__: CodedOutputStream): Unit
Serializes the message into the given coded output stream
Serializes the message into the given coded output stream
- Definition Classes
- Duration → GeneratedMessage
- final def writeTo(output: OutputStream): Unit
Serializes the message into the given output stream
Serializes the message into the given output stream
- Definition Classes
- GeneratedMessage