SaaS Runtime V1BETA1 API - Class Google::Protobuf::Duration (v0.1.0)
Reference documentation and code samples for the SaaS Runtime V1BETA1 API class Google::Protobuf::Duration.
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.
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".
Inherits
Object
Extended By
Google::Protobuf::MessageExts::ClassMethods
Includes
Google::Protobuf::MessageExts
Methods
#nanos
defnanos()->::Integer
Returns
(::Integer) — 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.
#nanos=
defnanos=(value)->::Integer
Parameter
value (::Integer) — 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.
Returns
(::Integer) — 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.
#seconds
defseconds()->::Integer
Returns
(::Integer) — 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
#seconds=
defseconds=(value)->::Integer
Parameter
value (::Integer) — 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
Returns
(::Integer) — 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
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[],[],null,["# SaaS Runtime V1BETA1 API - Class Google::Protobuf::Duration (v0.1.0)\n\nReference documentation and code samples for the SaaS Runtime V1BETA1 API class Google::Protobuf::Duration.\n\nA Duration represents a signed, fixed-length span of time represented\nas a count of seconds and fractions of seconds at nanosecond\nresolution. It is independent of any calendar and concepts like \"day\"\nor \"month\". It is related to Timestamp in that the difference between\ntwo Timestamp values is a Duration and it can be added or subtracted\nfrom a Timestamp. Range is approximately +-10,000 years.\n\nExamples\n--------\n\n\nExample 1: Compute Duration from two Timestamps in pseudo code. \n\n Timestamp start = ...;\n Timestamp end = ...;\n Duration duration = ...;\n\n duration.seconds = end.seconds - start.seconds;\n duration.nanos = end.nanos - start.nanos;\n\n if (duration.seconds \u003c 0 && duration.nanos \u003e 0) {\n duration.seconds += 1;\n duration.nanos -= 1000000000;\n } else if (duration.seconds \u003e 0 && duration.nanos \u003c 0) {\n duration.seconds -= 1;\n duration.nanos += 1000000000;\n }\n\nExample 2: Compute Timestamp from Timestamp + Duration in pseudo code. \n\n Timestamp start = ...;\n Duration duration = ...;\n Timestamp end = ...;\n\n end.seconds = start.seconds + duration.seconds;\n end.nanos = start.nanos + duration.nanos;\n\n if (end.nanos \u003c 0) {\n end.seconds -= 1;\n end.nanos += 1000000000;\n } else if (end.nanos \u003e= 1000000000) {\n end.seconds += 1;\n end.nanos -= 1000000000;\n }\n\nExample 3: Compute Duration from datetime.timedelta in Python. \n\n td = datetime.timedelta(days=3, minutes=10)\n duration = Duration()\n duration.FromTimedelta(td)\n\nJSON Mapping\n------------\n\n\u003cbr /\u003e\n\nIn JSON format, the Duration type is encoded as a string rather than an\nobject, where the string ends in the suffix \"s\" (indicating seconds) and\nis preceded by the number of seconds, with nanoseconds expressed as\nfractional seconds. For example, 3 seconds with 0 nanoseconds should be\nencoded in JSON format as \"3s\", while 3 seconds and 1 nanosecond should\nbe expressed in JSON format as \"3.000000001s\", and 3 seconds and 1\nmicrosecond should be expressed in JSON format as \"3.000001s\". \n\nInherits\n--------\n\n- Object \n\nExtended By\n-----------\n\n- Google::Protobuf::MessageExts::ClassMethods \n\nIncludes\n--------\n\n- Google::Protobuf::MessageExts\n\nMethods\n-------\n\n### #nanos\n\n def nanos() -\u003e ::Integer\n\n**Returns**\n\n- (::Integer) --- 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.\n\n### #nanos=\n\n def nanos=(value) -\u003e ::Integer\n\n**Parameter**\n\n- **value** (::Integer) --- 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. \n**Returns**\n\n- (::Integer) --- 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.\n\n### #seconds\n\n def seconds() -\u003e ::Integer\n\n**Returns**\n\n- (::Integer) --- 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\n\n### #seconds=\n\n def seconds=(value) -\u003e ::Integer\n\n**Parameter**\n\n- **value** (::Integer) --- 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 \n**Returns**\n\n- (::Integer) --- 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"]]