#[non_exhaustive]pub struct Duration { /* private fields */ }Expand description
Well-known duration representation for Google APIs.
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.
§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”.
Implementations§
Source§impl Duration
impl Duration
Sourcepub const MAX_SECONDS: i64 = 315_576_000_000i64
pub const MAX_SECONDS: i64 = 315_576_000_000i64
The maximum value for the seconds component, approximately 10,000 years.
Sourcepub const MIN_SECONDS: i64 = -315_576_000_000i64
pub const MIN_SECONDS: i64 = -315_576_000_000i64
The minimum value for the seconds component, approximately -10,000 years.
Sourcepub fn new(seconds: i64, nanos: i32) -> Result<Self, DurationError>
pub fn new(seconds: i64, nanos: i32) -> Result<Self, DurationError>
Creates a Duration from the seconds and nanoseconds component.
This function validates the seconds and nanos components and returns
an error if either are out of range or their signs do not match.
Consider using clamp() to add nanoseconds to seconds
with carry.
§Arguments
seconds- the seconds in the interval.nanos- the nanoseconds added to the interval.
Sourcepub fn clamp(seconds: i64, nanos: i32) -> Self
pub fn clamp(seconds: i64, nanos: i32) -> Self
Create a normalized, clamped Duration.
Durations must be in the [-10_000, +10_000] year range, the nanoseconds field must be in the [-999_999_999, +999_999_999] range, and the seconds and nanosecond fields must have the same sign. This function creates a new Duration instance clamped to those ranges.
The function effectively adds the nanoseconds part (with carry) to the seconds part, with saturation.
§Arguments
seconds- the seconds in the interval.nanos- the nanoseconds added to the interval.