[#absl-Duration]
= xref:absl.adoc[absl]::Duration
:relfileprefix: ../
:mrdocs:

The `absl&colon;&colon;Duration` class represents a signed, fixed&hyphen;length amount of time&period; A `Duration` is generated using a unit&hyphen;specific factory function, or is the result of subtracting one `absl&colon;&colon;Time` from another&period; Durations behave like unit&hyphen;safe integers and they support all the natural integer&hyphen;like arithmetic operations&period; Arithmetic overflows and saturates at &plus;&sol;&hyphen; infinity&period; `Duration` is trivially destructible and should be passed by value rather than const reference&period;

== Synopsis

Declared in `&lt;absl&sol;time&sol;time&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class Duration;
----

== Description

Factory functions `Nanoseconds()`, `Microseconds()`, `Milliseconds()`, `Seconds()`, `Minutes()`, `Hours()` and `InfiniteDuration()` allow for creation of constexpr `Duration` values

Examples&colon;

constexpr absl&colon;&colon;Duration ten&lowbar;ns &equals; absl&colon;&colon;Nanoseconds(10)&semi; constexpr absl&colon;&colon;Duration min &equals; absl&colon;&colon;Minutes(1)&semi; constexpr absl&colon;&colon;Duration hour &equals; absl&colon;&colon;Hours(1)&semi; absl&colon;&colon;Duration dur &equals; 60 &ast; min&semi; &sol;&sol; dur &equals;&equals; hour absl&colon;&colon;Duration half&lowbar;sec &equals; absl&colon;&colon;Milliseconds(500)&semi; absl&colon;&colon;Duration quarter&lowbar;sec &equals; 0&period;25 &ast; absl&colon;&colon;Seconds(1)&semi;

`Duration` values can be easily converted to an integral number of units using the division operator&period;

Example&colon;

constexpr absl&colon;&colon;Duration dur &equals; absl&colon;&colon;Milliseconds(1500)&semi; int64&lowbar;t ns &equals; dur &sol; absl&colon;&colon;Nanoseconds(1)&semi; &sol;&sol; ns &equals;&equals; 1500000000 int64&lowbar;t ms &equals; dur &sol; absl&colon;&colon;Milliseconds(1)&semi; &sol;&sol; ms &equals;&equals; 1500 int64&lowbar;t sec &equals; dur &sol; absl&colon;&colon;Seconds(1)&semi; &sol;&sol; sec &equals;&equals; 1 (subseconds truncated) int64&lowbar;t min &equals; dur &sol; absl&colon;&colon;Minutes(1)&semi; &sol;&sol; min &equals;&equals; 0

See the `IDivDuration()` and `FDivDuration()` functions below for details on how to access the fractional parts of the quotient&period;

Alternatively, conversions can be performed using helpers such as `ToInt64Microseconds()` and `ToDoubleSeconds()`&period;

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/Duration/2constructor-03.adoc[`Duration`]         [.small]#[constructor]#
| Constructors
| xref:absl/Duration/operator_assign.adoc[`operator&equals;`] 
| Assigns a copy of another duration&period;
| xref:absl/Duration/operator_mod_eq.adoc[`operator%&equals;`] 
| Sets this duration to its remainder modulo another duration&period;
| xref:absl/Duration/operator_star_eq-0a9.adoc[`operator&ast;&equals;`] 
| Multiplication assignment operators
| xref:absl/Duration/operator_plus_eq.adoc[`operator&plus;&equals;`] 
| Adds a duration to this one&period;
| xref:absl/Duration/operator_minus_eq.adoc[`operator&hyphen;&equals;`] 
| Subtracts a duration from this one&period;
| xref:absl/Duration/operator_slash_eq-01.adoc[`operator&sol;&equals;`] 
| Division assignment operators
|===


== Friends

[cols="1,4"]
|===
| Name| Description
| `xref:absl/AbslHashValue-0e.adoc[absl::AbslHashValue]`
| Combines this duration into a hash state&period;
|===

== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:absl/AbsDuration.adoc[`AbsDuration`]
| Returns the absolute value of a duration&period;
| xref:absl/AbslUnparseFlag-08.adoc[`AbslUnparseFlag`]
| Unparses a Duration value into a command&hyphen;line string representation using the format specified by `absl&colon;&colon;ParseDuration()`&period;
| xref:absl/Ceil.adoc[`Ceil`]
| Returns the ceiling of a duration using the passed duration unit to its smallest value not less than the duration&period;
| xref:absl/DurationFromTimespec.adoc[`DurationFromTimespec`]
| Converts a `timespec` to an `absl&colon;&colon;Duration`&period;
| xref:absl/DurationFromTimeval.adoc[`DurationFromTimeval`]
| Converts a `timeval` to an `absl&colon;&colon;Duration`&period;
| xref:absl/FDivDuration.adoc[`FDivDuration`]
| Divides a `Duration` numerator into a fractional number of units of a `Duration` denominator&period;
| xref:absl/Floor.adoc[`Floor`]
| Floors a duration using the passed duration unit to its largest value not greater than the duration&period;
| xref:absl/FormatDuration.adoc[`FormatDuration`]
| Returns a string representing the duration in the form &quot;72h3m0&period;5s&quot;&period; Returns &quot;inf&quot; or &quot;&hyphen;inf&quot; for &plus;&sol;&hyphen; `InfiniteDuration()`&period;
| xref:absl/FromChrono-00.adoc[`FromChrono`]
| Converts a std&colon;&colon;chrono&colon;&colon;microseconds value to an absl&colon;&colon;Duration&period;
| xref:absl/FromChrono-03.adoc[`FromChrono`]
| Converts a std&colon;&colon;chrono&colon;&colon;hours value to an absl&colon;&colon;Duration&period;
| xref:absl/FromChrono-05.adoc[`FromChrono`]
| Converts a std&colon;&colon;chrono&colon;&colon;nanoseconds value to an absl&colon;&colon;Duration&period;
| xref:absl/FromChrono-0a.adoc[`FromChrono`]
| Converts a std&colon;&colon;chrono&colon;&colon;milliseconds value to an absl&colon;&colon;Duration&period;
| xref:absl/FromChrono-0d3.adoc[`FromChrono`]
| Converts a std&colon;&colon;chrono&colon;&colon;seconds value to an absl&colon;&colon;Duration&period;
| xref:absl/FromChrono-0f.adoc[`FromChrono`]
| Converts a std&colon;&colon;chrono&colon;&colon;minutes value to an absl&colon;&colon;Duration&period;
| xref:absl/Hours-08.adoc[`Hours`]
| Constructs a `Duration` from a floating&hyphen;point number of hours&period;
| xref:absl/Hours-0b.adoc[`Hours`]
| Constructs a `Duration` from an integral number of hours&period;
| xref:absl/IDivDuration.adoc[`IDivDuration`]
| Divides a numerator `Duration` by a denominator `Duration`, returning the quotient and remainder&period; The remainder always has the same sign as the numerator&period; The returned quotient and remainder respect the identity&colon;
| xref:absl/InfiniteDuration.adoc[`InfiniteDuration`]
| Returns an infinite `Duration`&period; To get a `Duration` representing negative infinity, use `&hyphen;InfiniteDuration()`&period;
| xref:absl/Microseconds-05.adoc[`Microseconds`]
| Constructs a `Duration` from a floating&hyphen;point number of microseconds&period;
| xref:absl/Microseconds-0e.adoc[`Microseconds`]
| Constructs a `Duration` from an integral number of microseconds&period;
| xref:absl/Milliseconds-01f.adoc[`Milliseconds`]
| Constructs a `Duration` from a floating&hyphen;point number of milliseconds&period;
| xref:absl/Milliseconds-04.adoc[`Milliseconds`]
| Constructs a `Duration` from an integral number of milliseconds&period;
| xref:absl/Minutes-07.adoc[`Minutes`]
| Constructs a `Duration` from a floating&hyphen;point number of minutes&period;
| xref:absl/Minutes-08.adoc[`Minutes`]
| Constructs a `Duration` from an integral number of minutes&period;
| xref:absl/Nanoseconds-05.adoc[`Nanoseconds`]
| Constructs a `Duration` from a floating&hyphen;point number of nanoseconds&period;
| xref:absl/Nanoseconds-0a.adoc[`Nanoseconds`]
| Constructs a `Duration` from an integral number of nanoseconds&period;
| xref:absl/Seconds-02.adoc[`Seconds`]
| Constructs a `Duration` from a floating&hyphen;point number of seconds&period;
| xref:absl/Seconds-0b.adoc[`Seconds`]
| Constructs a `Duration` from an integral number of seconds&period;
| xref:absl/SleepFor.adoc[`SleepFor`]
| Sleeps for the specified duration, expressed as an `absl&colon;&colon;Duration`&period;
| xref:absl/ToChronoHours.adoc[`ToChronoHours`]
| Converts an absl&colon;&colon;Duration to a std&colon;&colon;chrono&colon;&colon;hours value&period;
| xref:absl/ToChronoMicroseconds.adoc[`ToChronoMicroseconds`]
| Converts an absl&colon;&colon;Duration to a std&colon;&colon;chrono&colon;&colon;microseconds value&period;
| xref:absl/ToChronoMilliseconds.adoc[`ToChronoMilliseconds`]
| Converts an absl&colon;&colon;Duration to a std&colon;&colon;chrono&colon;&colon;milliseconds value&period;
| xref:absl/ToChronoMinutes.adoc[`ToChronoMinutes`]
| Converts an absl&colon;&colon;Duration to a std&colon;&colon;chrono&colon;&colon;minutes value&period;
| xref:absl/ToChronoNanoseconds.adoc[`ToChronoNanoseconds`]
| Converts an absl&colon;&colon;Duration to a std&colon;&colon;chrono&colon;&colon;nanoseconds value&period;
| xref:absl/ToChronoSeconds.adoc[`ToChronoSeconds`]
| Converts an absl&colon;&colon;Duration to a std&colon;&colon;chrono&colon;&colon;seconds value&period;
| xref:absl/ToDoubleHours.adoc[`ToDoubleHours`]
| Converts a Duration to a floating&hyphen;point count of hours&period;
| xref:absl/ToDoubleMicroseconds.adoc[`ToDoubleMicroseconds`]
| Converts a Duration to a floating&hyphen;point count of microseconds&period;
| xref:absl/ToDoubleMilliseconds.adoc[`ToDoubleMilliseconds`]
| Converts a Duration to a floating&hyphen;point count of milliseconds&period;
| xref:absl/ToDoubleMinutes.adoc[`ToDoubleMinutes`]
| Converts a Duration to a floating&hyphen;point count of minutes&period;
| xref:absl/ToDoubleNanoseconds.adoc[`ToDoubleNanoseconds`]
| Converts a Duration to a floating&hyphen;point count of nanoseconds&period;
| xref:absl/ToDoubleSeconds.adoc[`ToDoubleSeconds`]
| Converts a Duration to a floating&hyphen;point count of seconds&period;
| xref:absl/ToInt64Hours.adoc[`ToInt64Hours`]
| Converts a Duration to an integral count of hours&period;
| xref:absl/ToInt64Microseconds.adoc[`ToInt64Microseconds`]
| Converts a Duration to an integral count of microseconds&period;
| xref:absl/ToInt64Milliseconds.adoc[`ToInt64Milliseconds`]
| Converts a Duration to an integral count of milliseconds&period;
| xref:absl/ToInt64Minutes.adoc[`ToInt64Minutes`]
| Converts a Duration to an integral count of minutes&period;
| xref:absl/ToInt64Nanoseconds.adoc[`ToInt64Nanoseconds`]
| Converts a Duration to an integral count of nanoseconds&period;
| xref:absl/ToInt64Seconds.adoc[`ToInt64Seconds`]
| Converts a Duration to an integral count of seconds&period;
| xref:absl/ToTimespec-06.adoc[`ToTimespec`]
| Converts an `absl&colon;&colon;Duration` to a `timespec`&period;
| xref:absl/ToTimeval-01.adoc[`ToTimeval`]
| Converts an `absl&colon;&colon;Duration` to a `timeval`&period;
| xref:absl/Trunc.adoc[`Trunc`]
| Truncates a duration (toward zero) to a multiple of a non&hyphen;zero unit&period;
| xref:absl/UnparseFlag-06.adoc[`UnparseFlag`]
| Deprecated&period; Use `AbslUnparseFlag()` instead&period;
| xref:absl/ZeroDuration.adoc[`ZeroDuration`]
| Returns a zero&hyphen;length duration&period; This function behaves just like the default constructor, but the name helps make the semantics clear at call sites&period;
| xref:absl/operator_not_eq-0e7.adoc[`operator!&equals;`]
| Returns whether two durations are unequal&period;
| xref:absl/operator_mod-02.adoc[`operator%`]
| Returns the remainder of one duration divided by another&period;
| xref:absl/operator_star-02.adoc[`operator&ast;`]
| Returns the product of a scalar and a duration&period;
| xref:absl/operator_star-07.adoc[`operator&ast;`]
| Returns the product of a duration and a scalar&period;
| xref:absl/operator_plus-04.adoc[`operator&plus;`]
| Returns the time obtained by advancing a time by a duration&period;
| xref:absl/operator_plus-0c.adoc[`operator&plus;`]
| Returns the sum of two durations&period;
| xref:absl/operator_minus-01a.adoc[`operator&hyphen;`]
| Returns the difference of two durations&period;
| xref:absl/operator_minus-09.adoc[`operator&hyphen;`]
| Returns the negation of a duration&period;
| xref:absl/operator_minus-0b.adoc[`operator&hyphen;`]
| Returns the duration between two times&period;
| xref:absl/operator_slash-05.adoc[`operator&sol;`]
| Returns the integer quotient of one duration divided by another&period;
| xref:absl/operator_slash-07.adoc[`operator&sol;`]
| Returns the quotient of a duration divided by a scalar&period;
| xref:absl/operator_lt-06f.adoc[`operator&lt;`]
| Returns whether one duration is less than another&period;
| xref:absl/operator_le-075.adoc[`operator&lt;&equals;`]
| Returns whether one duration is less than or equal to another&period;
| xref:absl/operator_3way-03e.adoc[`operator&lt;&equals;&gt;`]
| Three&hyphen;way&hyphen;compares two durations&period;
| xref:absl/operator_eq-023.adoc[`operator&equals;&equals;`]
| Returns whether two durations are equal&period;
| xref:absl/operator_gt-06d.adoc[`operator&gt;`]
| Returns whether one duration is greater than another&period;
| xref:absl/operator_ge-0b.adoc[`operator&gt;&equals;`]
| Returns whether one duration is greater than or equal to another&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
