file
Duration.hThis module provides methods for dealing with durations of time.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Classes
- struct CnxDuration
CnxDuration
represents a duration in a particular unit of time ACnxDuration
occurs in a particular unit of time (e.g. seconds, nanoseconds, or years), and can represent a positive or negative amount of that unit
Typedefs
- using CnxDuration = struct CnxDuration
CnxDuration
represents a duration in a particular unit of time ACnxDuration
occurs in a particular unit of time (e.g. seconds, nanoseconds, or years), and can represent a positive or negative amount of that unit
Functions
- CnxDuration cnx_duration_new(i64 count, CnxRatio period)
- Creates a new
CnxDuration
with the given count and period. - CnxDuration cnx_duration_cast(CnxDuration to_cast, CnxRatio new_period)
- Converts the given
CnxDuration
to one with a different period Converts the givenCnxDuration
to aCnxDuration
with a different period, truncating any fractional portion caused by the conversion. - CnxDuration cnx_duration_floor(CnxDuration to_floor, CnxRatio new_period)
- Converts the given
CnxDuration
to one with a different period Converts the givenCnxDuration
to aCnxDuration
with a different period, flooring any fractional portion caused by the conversion. - CnxDuration cnx_duration_ceil(CnxDuration to_ceil, CnxRatio new_period)
- Converts the given
CnxDuration
to one with a different period Converts the givenCnxDuration
to aCnxDuration
with a different period, taking the ceiling of any fractional portion caused by the conversion. - CnxDuration cnx_duration_round(CnxDuration to_round, CnxRatio new_period)
- Converts the given
CnxDuration
to one with a different period Converts the givenCnxDuration
to aCnxDuration
with a different period, rounding any fractional portion caused by the conversion. - CnxDuration cnx_duration_abs(CnxDuration duration)
- Takes the absolute value of the given `CnxDuration.
- CnxDuration cnx_duration_add(CnxDuration lhs, CnxDuration rhs)
- Casts
rhs
to the same period aslhs
, then adds the two. - CnxDuration cnx_duration_add_scalar(CnxDuration lhs, i64 rhs)
- Adds
rhs
tolhs
as if it were aCnxDuration
of the same period. - CnxDuration cnx_duration_subtract(CnxDuration lhs, CnxDuration rhs)
- Casts
rhs
to the same period aslhs
, then subtractsrhs
fromlhs
- CnxDuration cnx_duration_subtract_scalar(CnxDuration lhs, i64 rhs)
- Subtracts
rhs
fromlhs
as if it were aCnxDuration
of the same period. - CnxDuration cnx_duration_multiply(CnxDuration lhs, i64 rhs)
- Multiplies
lhs
by the scalar valuerhs
- CnxDuration cnx_duration_divide(CnxDuration lhs, i64 rhs)
- Divides
lhs
by the scalar valuerhs
- bool cnx_duration_equal(CnxDuration lhs, CnxDuration rhs)
- Determines if the two
CnxDuration
s are equal. - bool cnx_duration_not_equal(CnxDuration lhs, CnxDuration rhs)
- Determines if the two
CnxDuration
s are NOT equal. - bool cnx_duration_less_than(CnxDuration lhs, CnxDuration rhs)
- Determines if
lhs
is strictly less thanrhs
. - bool cnx_duration_less_than_or_equal(CnxDuration lhs, CnxDuration rhs)
- Determines if
lhs
is less than or equal torhs
. - bool cnx_duration_greater_than(CnxDuration lhs, CnxDuration rhs)
- Determines if
lhs
is strictly greater thanrhs
. - bool cnx_duration_greater_than_or_equal(CnxDuration lhs, CnxDuration rhs)
- Determines if
lhs
is greater than or equal torhs
. - CnxCompare cnx_duration_compare(CnxDuration lhs, CnxDuration rhs)
- Performs a three-way comparison of
lhs
torhs
, determining howlhs
mathematically relates torhs
. - CnxFormatContext cnx_duration_is_specifier_valid(const CnxFormat*restrict self, CnxStringView specifier)
- Implementation of
CnxFormat.is_specifier_valid
forCnxDuration
- CnxString cnx_duration_format(const CnxFormat*restrict self, CnxFormatContext context)
- Implements the allocator-unaware part of the
CnxFormat
trait forCnxDuration
- CnxString cnx_duration_format_with_allocator(const CnxFormat*restrict self, CnxFormatContext context, CnxAllocator allocator)
- Implements the allocator-aware part of the
CnxFormat
trait forCnxDuration
-
static ImplTraitFor(CnxFormat,
CnxDuration,
cnx_
duration_ is_ specifier_ valid, cnx_ duration_ format, cnx_ duration_ format_ with_ allocator) - Implements the
CnxFormat
trait forCnxDuration
Variables
- static const CnxRatio cnx_duration_valid_periods
- Valid periods for
CnxDuration
and other time-related facilities.
Defines
- #define CNX_DURATION
- Declarations related to
CnxDuration
- #define cnx_nanoseconds_period
- Period representing nanoseconds for
CnxDuration
and other time-related facilities. - #define cnx_microseconds_period
- Period representing microseconds for
CnxDuration
and other time-related facilities. - #define cnx_milliseconds_period
- Period representing milliseconds for
CnxDuration
and other time-related facilities. - #define cnx_seconds_period
- Period representing seconds for
CnxDuration
and other time-related facilities. - #define cnx_minutes_period
- Period representing minutes for
CnxDuration
and other time-related facilities. - #define cnx_hours_period
- Period representing hours for
CnxDuration
and other time-related facilities. - #define cnx_days_period
- Period representing days for
CnxDuration
and other time-related facilities. - #define cnx_weeks_period
- Period representing weeks for
CnxDuration
and other time-related facilities. - #define cnx_months_period
- Period representing months for
CnxDuration
and other time-related facilities. - #define cnx_years_period
- Period representing years for
CnxDuration
and other time-related facilities. - #define cnx_nanoseconds(val)
- Returns a
CnxDuration
representing a number of nanoseconds. - #define cnx_microseconds(val)
- Returns a
CnxDuration
representing a number of microseconds. - #define cnx_milliseconds(val)
- Returns a
CnxDuration
representing a number of milliseconds. - #define cnx_seconds(val)
- Returns a
CnxDuration
representing a number of seconds. - #define cnx_minutes(val)
- Returns a
CnxDuration
representing a number of minutes. - #define cnx_hours(val)
- Returns a
CnxDuration
representing a number of hours. - #define cnx_days(val)
- Returns a
CnxDuration
representing a number of days. - #define cnx_weeks(val)
- Returns a
CnxDuration
representing a number of weeks. - #define cnx_months(val)
- Returns a
CnxDuration
representing a number of months. - #define cnx_years(val)
- Returns a
CnxDuration
representing a number of years.
Function documentation
CnxFormatContext cnx_duration_is_specifier_valid(const CnxFormat*restrict self, CnxStringView specifier)
Implementation of CnxFormat.is_specifier_valid
for CnxDuration
Parameters | |
---|---|
self | - The CnxDuration to format as a CnxFormat trait object |
specifier | - The CnxStringView viewing the format specifier to validate |
Returns | The CnxFormatContext indicating whether specifier was valid and storing the state holding the format settings and necessary info to format the CnxDuration |