com.google.protobuf.duration

Duration

final case class Duration(seconds: Long = 0L, nanos: Int = 0) extends trueaccord.scalapb.GeneratedMessage with trueaccord.scalapb.Message[Duration] with Updatable[Duration] 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 (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".

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 negative nanos field. For durations of one second or more, a non-zero value for the nanos field must be of the same sign as the seconds field. Must be from -999,999,999 to +999,999,999 inclusive.

Annotations
@SerialVersionUID( 0L )
Linear Supertypes
Product, Equals, Updatable[Duration], trueaccord.scalapb.Message[Duration], trueaccord.scalapb.GeneratedMessage, Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Duration
  2. Product
  3. Equals
  4. Updatable
  5. Message
  6. GeneratedMessage
  7. Serializable
  8. Serializable
  9. AnyRef
  10. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Duration(seconds: Long = 0L, nanos: Int = 0)

    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 negative nanos field. For durations of one second or more, a non-zero value for the nanos field must be of the same sign as the seconds field. Must be from -999,999,999 to +999,999,999 inclusive.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def companion: Duration.type

    Definition Classes
    DurationGeneratedMessage
  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def getField(__field: FieldDescriptor): PValue

    Definition Classes
    DurationGeneratedMessage
  13. def getFieldByNumber(__fieldNumber: Int): Any

    Definition Classes
    DurationGeneratedMessage
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. def mergeFrom(_input__: CodedInputStream): Duration

    Definition Classes
    DurationMessage
  16. val nanos: Int

    Signed fractions of a second at nanosecond resolution of the span of time.

    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 negative nanos field. For durations of one second or more, a non-zero value for the nanos field must be of the same sign as the seconds field. Must be from -999,999,999 to +999,999,999 inclusive.

  17. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  18. final def notify(): Unit

    Definition Classes
    AnyRef
  19. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  20. val seconds: Long

    Signed seconds of the span of time.

    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

  21. final def serializedSize: Int

    Definition Classes
    DurationGeneratedMessage
  22. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  23. def toByteArray: Array[Byte]

    Definition Classes
    GeneratedMessage
  24. def toByteString: ByteString

    Definition Classes
    GeneratedMessage
  25. def toPMessage: PMessage

    Definition Classes
    GeneratedMessage
  26. def toString(): String

    Definition Classes
    Duration → AnyRef → Any
  27. def update(ms: (Lens[Duration, Duration]) ⇒ (Duration) ⇒ Duration*): Duration

    Definition Classes
    Updatable
  28. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. def withNanos(__v: Int): Duration

  32. def withSeconds(__v: Long): Duration

  33. def writeDelimitedTo(output: OutputStream): Unit

    Definition Classes
    GeneratedMessage
  34. def writeTo(_output__: CodedOutputStream): Unit

    Definition Classes
    DurationGeneratedMessage
  35. def writeTo(output: OutputStream): Unit

    Definition Classes
    GeneratedMessage

Deprecated Value Members

  1. def getAllFields: Map[FieldDescriptor, Any]

    Definition Classes
    GeneratedMessage
    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use toPMessage

  2. def getField(field: FieldDescriptor): Any

    Definition Classes
    GeneratedMessage
    Annotations
    @deprecated
    Deprecated

    (Since version 0.6.0) Use getField that accepts a ScalaPB descriptor and returns PValue

Inherited from Product

Inherited from Equals

Inherited from Updatable[Duration]

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped