xtd 1.0.0
Loading...
Searching...
No Matches
xtd::time_span Class Reference
Inheritance diagram for xtd::time_span:
xtd::object xtd::iequatable< time_span > xtd::icomparable< time_span > xtd::iformatable xtd::interface xtd::extensions::equality_operators< time_span, iequatable< time_span > > xtd::interface xtd::extensions::comparison_operators< time_span, icomparable< time_span > > xtd::interface

Definition

Represents a time interval.

Namespace
xtd
Library
xtd.core
Examples
The following example instantiates a The following example instantiates a xtd::time_span object that represents the difference between two dates. It then displays the xtd::time_span object's properties. object that represents the difference between two dates. It then displays the xtd::time_span object's properties.
#include <xtd/xtd>
namespace uri_example {
class program {
public:
// The main entry point for the application.
static auto main() {
// Define two dates.
auto date1 = date_time {2010, 1, 1, 8, 0, 15};
auto date2 = date_time {2010, 8, 18, 13, 30, 30};
// Calculate the interval between the two dates.
time_span interval = date2 - date1;
console::write_line("{0} - {1} = {2}", date2, date1, interval.to_string());
// Display individual properties of the resulting TimeSpan object.
console::write_line(" {0,-35} {1,20}", "Value of Days Component:", interval.days());
console::write_line(" {0,-35} {1,20}", "Total Number of Days:", interval.total_days());
console::write_line(" {0,-35} {1,20}", "Value of Hours Component:", interval.hours());
console::write_line(" {0,-35} {1,20}", "Total Number of Hours:", interval.total_hours());
console::write_line(" {0,-35} {1,20}", "Value of Minutes Component:", interval.minutes());
console::write_line(" {0,-35} {1,20}", "Total Number of Minutes:", interval.total_minutes());
console::write_line(" {0,-35} {1,20:N0}", "Value of Seconds Component:", interval.seconds());
console::write_line(" {0,-35} {1,20:N0}", "Total Number of Seconds:", interval.total_seconds());
console::write_line(" {0,-35} {1,20:N0}", "Value of Milliseconds Component:", interval.milliseconds());
console::write_line(" {0,-35} {1,20:N0}", "Total Number of Milliseconds:", interval.total_milliseconds());
console::write_line(" {0,-35} {1,20:N0}", "Ticks:", interval.ticks());
}
};
}
startup_(uri_example::program::main);
// This code produces the following output :
//
// 8/18/2010 1:30:30 PM - 1/1/2010 8:00:15 AM = 229.05:30:15
// Value of Days Component: 229
// Total Number of Days: 229.229340277778
// Value of Hours Component: 5
// Total Number of Hours: 5501.50416666667
// Value of Minutes Component: 30
// Total Number of Minutes: 330090.25
// Value of Seconds Component: 15
// Total Number of Seconds: 19,805,415
// Value of Milliseconds Component: 0
// Total Number of Milliseconds: 19,805,415,000
// Ticks: 198,054,150,000,000
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp:83
#define startup_(...)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:284

Public Fields

static const time_span max_value
 Represents the maximum xtd::time_span value. This field is read-only.
static const time_span min_value
 Represents the minimum xtd::time_span value. This field is read-only.
static constexpr xtd::int64 nanoseconds_per_tick
 Represents the number of nanoseconds per tick. This field is constant.
static constexpr xtd::int64 ticks_per_microsecond
 Represents the number of ticks in 1 microsecond. This field is constant.
static constexpr xtd::int64 ticks_per_millisecond
 Represents the number of ticks in 1 millisecond. This field is constant.
static constexpr xtd::int64 ticks_per_second
 Represents the number of ticks in 1 second.
static constexpr xtd::int64 ticks_per_minute
 Represents the number of ticks in 1 minute. This field is constant.
static constexpr xtd::int64 ticks_per_hour
 Represents the number of ticks in 1 hour. This field is constant.
static constexpr xtd::int64 ticks_per_day
 Represents the number of ticks in 1 day. This field is constant.
static const time_span zero
 Represents the zero xtd::time_span value. This field is read-only.

Public Constructors

 time_span (xtd::int64 ticksticks)
 Initializes a new instance of the xtd::time_span structure to the specified number of ticks.
 time_span (xtd::ticks ticksticks)
 Initializes a new instance of the xtd::time_span structure to the specified number of ticks.
template<typename duration_t, typename period_t = std::ratio<1>>
 time_span (const std::chrono::duration< duration_t, period_t > &value)
 Initializes a new instance of the xtd::time_span structure to the specified number of ticks.
 time_span (xtd::int32 hours, xtd::int32 minutes, xtd::int32 seconds)
 Initializes a new instance of the xtd::time_span structure to a specified number of hours, minutes, and seconds.
 time_span (xtd::int32 days, xtd::int32 hours, xtd::int32 minutes, xtd::int32 seconds)
 Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, and seconds.
 time_span (xtd::int32 days, xtd::int32 hours, xtd::int32 minutes, xtd::int32 seconds, xtd::int32 milliseconds)
 Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, seconds, and millisonds.
 time_span (xtd::int32 days, xtd::int32 hours, xtd::int32 minutes, xtd::int32 seconds, xtd::int32 milliseconds, xtd::int32 microseconds)
 Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, seconds, millisonds, and microseconds.
 time_span (xtd::int32 days, xtd::int32 hours, xtd::int32 minutes, xtd::int32 seconds, xtd::int32 milliseconds, xtd::int32 microseconds, xtd::int32 nanoseconds)
 Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, seconds, millisonds, and microseconds.

Public Properties

auto days () const noexcept -> xtd::int32
 Gets the days component of the time interval represented by the current xtd::time_span structure.
auto hours () const noexcept -> xtd::int32
 Gets the hours component of the time interval represented by the current xtd::time_span structure.
auto microseconds () const noexcept -> xtd::int32
 Gets the microseconds component of the time interval represented by the current xtd::time_span structure.
auto milliseconds () const noexcept -> xtd::int32
 Gets the milliseconds component of the time interval represented by the current xtd::time_span structure.
auto minutes () const noexcept -> xtd::int32
 Gets the minutes component of the time interval represented by the current xtd::time_span structure.
auto nanoseconds () const noexcept -> xtd::int32
 Gets the nanoseconds component of the time interval represented by the current xtd::time_span structure.
auto seconds () const noexcept -> xtd::int32
 Gets the seconds component of the time interval represented by the current xtd::time_span structure.
auto ticks () const noexcept -> xtd::int64
 Gets the number of ticks that represent the value of the current xtd::time_span structure.
auto ticks_duration () const noexcept -> xtd::ticks
 Gets the number of ticks that represent the value of the current xtd::time_span structure.
auto total_days () const noexcept -> double
 Gets the value of the current xtd::time_span structure expressed in whole and fractional days.
auto total_days_duration () const noexcept -> std::chrono::days
 Gets the value of the current xtd::time_span structure expressed in whole and fractional days.
auto total_hours () const noexcept -> double
 Gets the value of the current xtd::time_span structure expressed in whole and fractional hours.
auto total_hours_duration () const noexcept -> std::chrono::hours
 Gets the value of the current xtd::time_span structure expressed in whole and fractional hours.
auto total_microseconds () const noexcept -> double
 Gets the value of the current xtd::time_span structure expressed in whole and fractional microseconds.
auto total_microseconds_duration () const noexcept -> std::chrono::microseconds
 Gets the value of the current xtd::time_span structure expressed in whole and fractional microseconds.
auto total_milliseconds () const noexcept -> double
 Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds.
auto total_milliseconds_duration () const noexcept -> std::chrono::milliseconds
 Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds.
auto total_minutes () const noexcept -> double
 Gets the value of the current xtd::time_span structure expressed in whole and fractional minutes.
auto total_minutes_duration () const noexcept -> std::chrono::minutes
 Gets the value of the current xtd::time_span structure expressed in whole and fractional minutes.
auto total_nanoseconds () const noexcept -> double
 Gets the value of the current xtd::time_span structure expressed in whole and fractional nanoseconds.
auto total_nanoseconds_duration () const noexcept -> std::chrono::nanoseconds
 Gets the value of the current xtd::time_span structure expressed in whole and fractional nanoseconds.
auto total_seconds () const noexcept -> double
 Gets the value of the current xtd::time_span structure expressed in whole and fractional seconds.
auto total_seconds_duration () const noexcept -> std::chrono::seconds
 Gets the value of the current xtd::time_span structure expressed in whole and fractional seconds.

Public Methods

auto add (const time_span &ts) const noexcept -> time_span
 Returns a new xtd::time_span object whose value is the sum of the specified xtd::time_span object and this instance.
auto compare_to (const time_span &value) const noexcept -> xtd::int32 override
 Compares the current instance with another object of the same type.
auto divide (const time_span &ts) const -> double
 Returns a double value that's the result of dividing this instance by ts.
auto divide (double divisor) const -> time_span
 Returns a new xtd::time_span object whose value is the result of dividing this instance by the specified divisor.
auto duration () const noexcept -> time_span
 Returns a new xtd::time_span object whose value is the absolute value of the current xtd::time_span object.
auto equals (const object &value) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
auto equals (const time_span &value) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
auto get_hash_code () const noexcept -> xtd::usize override
 Serves as a hash function for a particular type.
auto multiply (const time_span &ts) const noexcept -> double
 Returns a new xtd::time_spam object which value is the result of multiplication of this instance and the specified factor.
auto multiply (double factor) const noexcept -> time_span
 Returns a new xtd::time_spam object which value is the result of multiplication of this instance and the specified factor.
auto negate () const -> time_span
 Returns a new xtd::time_spam object whose value is the negated value of this instance.
auto subtract (const time_span &ts) const noexcept -> time_span
 Returns a new xtd::time_span object whose value is the difference between the specified xtd::time_span object and this instance.
auto to_string () const noexcept -> xtd::string override
 Returns a xtd::string that represents the current object.
auto to_string (const xtd::string &format) const -> xtd::string
 Converts the value of the current xtd::time_span object to its equivalent string representation by using the specified format.
auto to_string (const xtd::string &format, const xtd::globalization::culture_info &culture) const -> xtd::string override
 Converts the value of the current xtd::time_span object to its equivalent string representation by using the specified format, and locale.
static auto parse (const string &value) -> time_span
 Converts the string representation of a time interval to its xtd::time_span equivalent.

Public Static Methods

static auto equals (time_span t1, time_span t2) -> bool
 Returns a value that indicates whether two specified instances of xtd::time_span are equal.
static auto from_days (double value) -> time_span
 Returns a xtd::time_span that represents a specified number of days, where the specification is accurate to the nearest millisecond.
static auto from_days (std::chrono::days value) -> time_span
 Returns a xtd::time_span that represents a specified number of days, where the specification is accurate to the nearest millisecond.
static auto from_hours (double value) -> time_span
 Returns a xtd::time_span that represents a specified number of hours, where the specification is accurate to the nearest millisecond.
static auto from_hours (std::chrono::hours value) -> time_span
 Returns a xtd::time_span that represents a specified number of hours, where the specification is accurate to the nearest millisecond.
static auto from_microseconds (double value) -> time_span
 Returns a xtd::time_span that represents a specified number of microseconds.
static auto from_microseconds (std::chrono::microseconds value) -> time_span
 Returns a xtd::time_span that represents a specified number of microseconds.
static auto from_milliseconds (double value) -> time_span
 Returns a xtd::time_span that represents a specified number of milliseconds.
static auto from_milliseconds (std::chrono::milliseconds value) -> time_span
 Returns a xtd::time_span that represents a specified number of milliseconds.
static auto from_minutes (double value) -> time_span
 Returns a xtd::time_span that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.
static auto from_minutes (std::chrono::minutes value) -> time_span
 Returns a xtd::time_span that represents a specified number of minutes.
static auto from_nanoseconds (double value) -> time_span
 Returns a xtd::time_span that represents a specified number of nanoseconds.
static auto from_nanoseconds (std::chrono::nanoseconds value) -> time_span
 Returns a xtd::time_span that represents a specified number of nanoseconds.
static auto from_seconds (double value) -> time_span
 Returns a xtd::time_spam that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.
static auto from_seconds (std::chrono::seconds value) -> time_span
 Returns a xtd::time_span that represents a specified number of seconds.
static auto from_ticks (int64 value) -> time_span
 Returns a xtd::time_spam that represents a specified time, where the specification is in units of ticks.
static auto from_ticks (xtd::ticks value) -> time_span
 Returns a xtd::time_span that represents a specified number of ticks.
static auto try_parse (const string &value, time_span &result) -> bool
 Converts the string representation of a time interval to its xtd::time_span equivalent and returns a value that indicates whether the conversion succeeded.

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
virtual auto get_type () const noexcept -> type_object
 Gets the type of the current instance.
template<typename object_t>
auto memberwise_clone () const -> xtd::unique_ptr_object< object_t >
 Creates a shallow copy of the current object.
template<typename object_a_t, typename object_b_t>
static auto equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static auto reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are the same instance.

Constructor & Destructor Documentation

◆ time_span() [1/8]

xtd::time_span::time_span ( xtd::int64 ticks)
explicit

Initializes a new instance of the xtd::time_span structure to the specified number of ticks.

Parameters
tiksA time period expressed in 100-nanosecond units.
Remarks
A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.

◆ time_span() [2/8]

xtd::time_span::time_span ( xtd::ticks ticks)
explicit

Initializes a new instance of the xtd::time_span structure to the specified number of ticks.

Parameters
tiksA time period expressed in 100-nanosecond units.
Remarks
A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.

◆ time_span() [3/8]

template<typename duration_t, typename period_t = std::ratio<1>>
xtd::time_span::time_span ( const std::chrono::duration< duration_t, period_t > & value)
inline

Initializes a new instance of the xtd::time_span structure to the specified number of ticks.

Parameters
tiksA time period expressed in 100-nanosecond units.
Remarks
A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.
See std::chrono::duration for more information.

◆ time_span() [4/8]

xtd::time_span::time_span ( xtd::int32 hours,
xtd::int32 minutes,
xtd::int32 seconds )

Initializes a new instance of the xtd::time_span structure to a specified number of hours, minutes, and seconds.

Parameters
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
Exceptions
xtd::argument_out_of_range_exceptionThe parameters specify a xtd::time_span value less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
Remarks
The specified hours, minutes, and seconds are converted to ticks, and that value initializes this instance.

◆ time_span() [5/8]

xtd::time_span::time_span ( xtd::int32 days,
xtd::int32 hours,
xtd::int32 minutes,
xtd::int32 seconds )

Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, and seconds.

Parameters
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
Exceptions
xtd::argument_out_of_range_exceptionThe parameters specify a xtd::time_span value less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
Remarks
The specified days, hours, minutes, and seconds are converted to ticks, and that value initializes this instance.

◆ time_span() [6/8]

xtd::time_span::time_span ( xtd::int32 days,
xtd::int32 hours,
xtd::int32 minutes,
xtd::int32 seconds,
xtd::int32 milliseconds )

Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, seconds, and millisonds.

Parameters
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
millisecondsNumber of milliseconds.
Exceptions
xtd::argument_out_of_range_exceptionThe parameters specify a xtd::time_span value less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
Remarks
The specified days, hours, minutes, seconds, and millisonds are converted to ticks, and that value initializes this instance.

◆ time_span() [7/8]

xtd::time_span::time_span ( xtd::int32 days,
xtd::int32 hours,
xtd::int32 minutes,
xtd::int32 seconds,
xtd::int32 milliseconds,
xtd::int32 microseconds )

Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, seconds, millisonds, and microseconds.

Parameters
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
millisecondsNumber of milliseconds.
microsecondsNumber of microseconds.
Exceptions
xtd::argument_out_of_range_exceptionThe parameters specify a xtd::time_span value less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
Remarks
The specified days, hours, minutes, seconds, millisonds and microseconds are converted to ticks, and that value initializes this instance.

◆ time_span() [8/8]

xtd::time_span::time_span ( xtd::int32 days,
xtd::int32 hours,
xtd::int32 minutes,
xtd::int32 seconds,
xtd::int32 milliseconds,
xtd::int32 microseconds,
xtd::int32 nanoseconds )

Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, seconds, millisonds, and microseconds.

Parameters
daysNumber of days.
hoursNumber of hours.
minutesNumber of minutes.
secondsNumber of seconds.
millisecondsNumber of milliseconds.
microsecondsNumber of microseconds.
nanosecondsNumber of nanoseconds.
Exceptions
xtd::argument_out_of_range_exceptionThe parameters specify a xtd::time_span value less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
Remarks
The specified days, hours, minutes, seconds, millisonds and microseconds are converted to ticks, and that value initializes this instance.

Member Function Documentation

◆ days()

auto xtd::time_span::days ( ) const -> xtd::int32
nodiscardnoexcept

Gets the days component of the time interval represented by the current xtd::time_span structure.

Returns
The day component of this instance. The return value can be positive or negative.
Remarks
The xtd::time_span::days property represents whole days, whereas the xtd::time_span::total_days property represents whole and fractional days.

◆ hours()

auto xtd::time_span::hours ( ) const -> xtd::int32
nodiscardnoexcept

Gets the hours component of the time interval represented by the current xtd::time_span structure.

Returns
The hour component of the current xtd::time_span structure. The return value ranges from -23 through 23.
Remarks
The xtd::time_span::hours property represents whole hours, whereas the xtd::time_span::total_hours property represents whole and fractional hours.

◆ microseconds()

auto xtd::time_span::microseconds ( ) const -> xtd::int32
nodiscardnoexcept

Gets the microseconds component of the time interval represented by the current xtd::time_span structure.

Returns
The hour component of the current xtd::time_span structure. The return value ranges from -999 through 999.
Remarks
The xtd::time_span::microseconds property represents whole microseconds, whereas the xtd::time_span::total_microseconds property represents whole and fractional microseconds.

◆ milliseconds()

auto xtd::time_span::milliseconds ( ) const -> xtd::int32
nodiscardnoexcept

Gets the milliseconds component of the time interval represented by the current xtd::time_span structure.

Returns
The millisecond component of the current xtd::time_span structure. The return value ranges from -999 through 999.
Remarks
The xtd::time_span::milliseconds property represents whole milliseconds, whereas the xtd::time_span::total_milliseconds property represents whole and fractional milliseconds.

◆ minutes()

auto xtd::time_span::minutes ( ) const -> xtd::int32
nodiscardnoexcept

Gets the minutes component of the time interval represented by the current xtd::time_span structure.

Returns
The minute component of the current xtd::time_span structure. The return value ranges from -59 through 59.
Remarks
The xtd::time_span::minutes property represents whole minutes, whereas the xtd::time_span::total_minutes property represents whole and fractional minutes.

◆ nanoseconds()

auto xtd::time_span::nanoseconds ( ) const -> xtd::int32
nodiscardnoexcept

Gets the nanoseconds component of the time interval represented by the current xtd::time_span structure.

Returns
The nanosecond component of the current xtd::time_span structure. The return value ranges from -999 through 999.
Remarks
The xtd::time_span::nanoseconds property represents whole nanoseconds, whereas the xtd::time_span::total_nanoseconds property represents whole and fractional nanoseconds.

◆ seconds()

auto xtd::time_span::seconds ( ) const -> xtd::int32
nodiscardnoexcept

Gets the seconds component of the time interval represented by the current xtd::time_span structure.

Returns
The second component of the current xtd::time_span structure. The return value ranges from -59 through 59.
Remarks
The xtd::time_span::seconds property represents whole seconds, whereas the xtd::time_span::total_seconds property represents whole and fractional seconds.

◆ ticks()

auto xtd::time_span::ticks ( ) const -> xtd::int64
nodiscardnoexcept

Gets the number of ticks that represent the value of the current xtd::time_span structure.

Returns
The number of ticks contained in this instance.
Remarks
The smallest unit of time is the tick, which is equal to 100 nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond. The value of the xtd::time_span::ticks property can be negative or positive to represent a negative or positive time interval.

◆ ticks_duration()

auto xtd::time_span::ticks_duration ( ) const -> xtd::ticks
nodiscardnoexcept

Gets the number of ticks that represent the value of the current xtd::time_span structure.

Returns
The number of ticks contained in this instance.
Remarks
The smallest unit of time is the tick, which is equal to 100 nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond. The value of the xtd::time_span::ticks property can be negative or positive to represent a negative or positive time interval.

◆ total_days()

auto xtd::time_span::total_days ( ) const -> double
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional days.

Returns
The total number of days represented by this instance.
Remarks
The xtd::time_span::total_days property represents whole and fractional days, whereas the xtd::time_span::days property represents whole days.

◆ total_days_duration()

auto xtd::time_span::total_days_duration ( ) const -> std::chrono::days
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional days.

Returns
The total number of days represented by this instance.
Remarks
The xtd::time_span::total_days_duration property represents whole and fractional days, whereas the xtd::time_span::days property represents whole days.

◆ total_hours()

auto xtd::time_span::total_hours ( ) const -> double
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional hours.

Returns
The total number of hours represented by this instance.
Remarks
The xtd::time_span::total_hours property represents whole and fractional hours, whereas the xtd::time_span::hours property represents whole hours.

◆ total_hours_duration()

auto xtd::time_span::total_hours_duration ( ) const -> std::chrono::hours
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional hours.

Returns
The total number of hours represented by this instance.
Remarks
The xtd::time_span::total_hours_duration property represents whole and fractional hours, whereas the xtd::time_span::hours property represents whole hours.

◆ total_microseconds()

auto xtd::time_span::total_microseconds ( ) const -> double
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional microseconds.

Returns
The total number of microseconds represented by this instance.
Remarks
The xtd::time_span::total_microseconds property represents whole and fractional microseconds, whereas the xtd::time_span::microseconds property represents whole microseconds.

◆ total_microseconds_duration()

auto xtd::time_span::total_microseconds_duration ( ) const -> std::chrono::microseconds
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional microseconds.

Returns
The total number of microseconds represented by this instance.
Remarks
The xtd::time_span::total_microseconds_duration property represents whole and fractional microseconds, whereas the xtd::time_span::microseconds property represents whole microseconds.

◆ total_milliseconds()

auto xtd::time_span::total_milliseconds ( ) const -> double
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds.

Returns
The total number of milliseconds represented by this instance.
Remarks
The xtd::time_span::total_milliseconds property represents whole and fractional milliseconds, whereas the xtd::time_span::milliseconds property represents whole milliseconds.

◆ total_milliseconds_duration()

auto xtd::time_span::total_milliseconds_duration ( ) const -> std::chrono::milliseconds
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds.

Returns
The total number of milliseconds represented by this instance.
Remarks
The xtd::time_span::total_milliseconds_duration property represents whole and fractional milliseconds, whereas the xtd::time_span::milliseconds property represents whole milliseconds.

◆ total_minutes()

auto xtd::time_span::total_minutes ( ) const -> double
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional minutes.

Returns
The total number of minutes represented by this instance.
Remarks
The xtd::time_span::total_minutes property represents whole and fractional minutes, whereas the xtd::time_span::minutes property represents whole minutes.

◆ total_minutes_duration()

auto xtd::time_span::total_minutes_duration ( ) const -> std::chrono::minutes
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional minutes.

Returns
The total number of minutes represented by this instance.
Remarks
The xtd::time_span::total_minutes_duration property represents whole and fractional minutes, whereas the xtd::time_span::minutes property represents whole minutes.

◆ total_nanoseconds()

auto xtd::time_span::total_nanoseconds ( ) const -> double
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional nanoseconds.

Returns
The total number of nanoseconds represented by this instance.
Remarks
The xtd::time_span::total_nanoseconds property represents whole and fractional nanoseconds, whereas the xtd::time_span::nanoseconds property represents whole nanoseconds.

◆ total_nanoseconds_duration()

auto xtd::time_span::total_nanoseconds_duration ( ) const -> std::chrono::nanoseconds
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional nanoseconds.

Returns
The total number of nanoseconds represented by this instance.
Remarks
The xtd::time_span::total_nanoseconds_duration property represents whole and fractional nanoseconds, whereas the xtd::time_span::nanoseconds property represents whole nanoseconds.

◆ total_seconds()

auto xtd::time_span::total_seconds ( ) const -> double
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional seconds.

Returns
The total number of seconds represented by this instance.
Remarks
The xtd::time_span::total_seconds property represents whole and fractional seconds, whereas the xtd::time_span::seconds property represents whole seconds.

◆ total_seconds_duration()

auto xtd::time_span::total_seconds_duration ( ) const -> std::chrono::seconds
nodiscardnoexcept

Gets the value of the current xtd::time_span structure expressed in whole and fractional seconds.

Returns
The total number of seconds represented by this instance.
Remarks
The xtd::time_span::total_seconds_duration property represents whole and fractional seconds, whereas the xtd::time_span::seconds property represents whole seconds.

◆ add()

auto xtd::time_span::add ( const time_span & ts) const -> time_span
nodiscardnoexcept

Returns a new xtd::time_span object whose value is the sum of the specified xtd::time_span object and this instance.

Parameters
tsThe time interval to add.
Returns
A new object that represents the value of this instance plus the value of ts.
Remarks
The return value is a new xtd::time_span; the original xtd::time_span is not modified.

◆ compare_to()

auto xtd::time_span::compare_to ( const time_span & obj) const -> xtd::int32
nodiscardoverridevirtualnoexcept

Compares the current instance with another object of the same type.

Parameters
objAn object to compare with this instance.
Returns
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings:
Value Condition
Less than zero This instance is less than obj.
Zero This instance is equal to obj.
Greater than zero This instance is greater than obj.

Implements xtd::icomparable< time_span >.

◆ divide() [1/2]

auto xtd::time_span::divide ( const time_span & ts) const -> double
nodiscard

Returns a double value that's the result of dividing this instance by ts.

Parameters
tsThe value to be divided by.
Returns
A new value that represents result of dividing this instance by the value of ts.

◆ divide() [2/2]

auto xtd::time_span::divide ( double divisor) const -> time_span
nodiscard

Returns a new xtd::time_span object whose value is the result of dividing this instance by the specified divisor.

Parameters
divisorThe value to be divided by.
Returns
A new object that represents the value of this instance divided by the value of divisor.

◆ duration()

auto xtd::time_span::duration ( ) const -> time_span
nodiscardnoexcept

Returns a new xtd::time_span object whose value is the absolute value of the current xtd::time_span object.

Returns
A new object whose value is the absolute value of the current xtd::time_span object.

◆ equals() [1/3]

auto xtd::time_span::equals ( const object & value) const -> bool
nodiscardoverridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

Reimplemented from xtd::object.

◆ equals() [2/3]

auto xtd::time_span::equals ( const time_span & value) const -> bool
nodiscardoverridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
valueThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

Implements xtd::iequatable< time_span >.

◆ get_hash_code()

auto xtd::time_span::get_hash_code ( ) const -> xtd::usize
nodiscardoverridevirtualnoexcept

Serves as a hash function for a particular type.

Returns
A hash code for the current object.

Reimplemented from xtd::object.

◆ multiply() [1/2]

auto xtd::time_span::multiply ( const time_span & ts) const -> double
nodiscardnoexcept

Returns a new xtd::time_spam object which value is the result of multiplication of this instance and the specified factor.

Parameters
factorThe value to be multiplied by.
Returns
A double that represents the value of this instance multiplied by the value of factor.

◆ multiply() [2/2]

auto xtd::time_span::multiply ( double factor) const -> time_span
nodiscardnoexcept

Returns a new xtd::time_spam object which value is the result of multiplication of this instance and the specified factor.

Parameters
factorThe value to be multiplied by.
Returns
A new object that represents the value of this instance multiplied by the value of factor.

◆ negate()

auto xtd::time_span::negate ( ) const -> time_span
nodiscard

Returns a new xtd::time_spam object whose value is the negated value of this instance.

Returns
A new object with the same numeric value as this instance, but with the opposite sign.
Exceptions
xtd::overflow_exceptionThe negated value of this instance cannot be represented by a xtd::time_spam; that is, the value of this instance is xtd::time_spam::min_value.

◆ parse()

auto xtd::time_span::parse ( const string & value) -> time_span
static

Converts the string representation of a time interval to its xtd::time_span equivalent.

Parameters
valueA string that specifies the time interval to convert.
Returns
A time interval that corresponds to value.
Exceptions
xtd::format_exceptionvalue has an invalid format.
valuerepresents a number that is less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
-or-
At least one of the days, hours, minutes, or seconds components is outside its valid range.

◆ subtract()

auto xtd::time_span::subtract ( const time_span & ts) const -> time_span
nodiscardnoexcept

Returns a new xtd::time_span object whose value is the difference between the specified xtd::time_span object and this instance.

Parameters
tsThe time interval to be subtracted.
Returns
A new time interval whose value is the result of the value of this instance minus the value of ts.
Remarks
The return value is a new xtd::time_span; the original xtd::time_span is not modified.

◆ to_string() [1/3]

auto xtd::time_span::to_string ( ) const -> xtd::string
nodiscardoverridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.
#include <xtd/xtd>
namespace examples {
namespace object_test {
class object1 : public object {
};
}
}
auto main() -> int {
ptr<object> obj1 = new_ptr<examples::object_test::object1>();
console::write_line(obj1->to_string());
ptr<object> obj2 = new_ptr<date_time>(1971, 1, 5, 23, 5, 0);
console::write_line(obj2->to_string());
ptr<object> obj3 = new_ptr<boolean_object>();
console::write_line(obj3->to_string());
}
// This code produces the following output :
//
// examples::object_test::object1
// Tue Jan 5 23:05:00 1971
// false
object()=default
Create a new instance of the ultimate base class object.

Reimplemented from xtd::object.

◆ to_string() [2/3]

auto xtd::time_span::to_string ( const xtd::string & format) const -> xtd::string
nodiscard

Converts the value of the current xtd::time_span object to its equivalent string representation by using the specified format.

Parameters
formatA single format specifier that indicates how to format the value of this xtd::time_span.
Returns
The string representation of the current xtd::time_span value in the format specified by the format parameter.
Exceptions
xtd::format_exceptionThe format parameter is not recognized or is not supported.
Remarks
The format parameter can be any valid standard specifier for XTD::time_span values. If format is equal to xtd::string::empty_string (""), the return value of the current xtd::time_span object is formatted with the common format specifier ("c").
The formatting codes for xtd::time_span::to_string (const xtd::string&) are listed below:
Format Print
'c' write duration with optional ticks d.hh.mm.ss.ticks
'd' write absolute value of days d
'D' write absolute value of days dd
'f' write duration d.h.mm.ss.ticks
'F' write duration d.hh.mm.ss.ticks
'g' write duration with optional ticks d.h.mm.ss.ticks
'G' write duration with optional ticks d.hh.mm.ss.ticks
'h' write absolute value of hours h
'H' write absolute value of hours hh
'l' write absolute value of milliseconds
'L' write absolute value of milliseconds fixed at 3 digits
'm' write absolute value of minutes m
'M' write absolute value of minutes mm
'o' write optional minus sign
'o' write minus or plus sign
's' write absolute value of seconds s
'S' write absolute value of seconds ss
't' write absolute value of ticks
'T' write absolute value of ticks fixed at 7 digits

◆ to_string() [3/3]

auto xtd::time_span::to_string ( const xtd::string & format,
const xtd::globalization::culture_info & culture ) const -> xtd::string
nodiscardoverridevirtual

Converts the value of the current xtd::time_span object to its equivalent string representation by using the specified format, and locale.

Parameters
formatA single format specifier that indicates how to format the value of this xtd::time_span.
cultureAn xtd::globalization::culture_info object that contains culture information.
Returns
The string representation of the current xtd::time_span value in the format specified by the format parameter.
Exceptions
xtd::format_exceptionThe format parameter is not recognized or is not supported.
Remarks
The format parameter can be any valid standard specifier for XTD::time_span values. If format is equal to xtd::string::empty_string (""), the return value of the current xtd::time_span object is formatted with the common format specifier ("c").
The formatting codes for xtd::time_span::to_string (const xtd::string&) are listed below:
Format Print
'c' write duration with optional ticks d.hh.mm.ss.ticks
'd' write absolute value of days d
'D' write absolute value of days dd
'f' write duration d.h.mm.ss.ticks
'F' write duration d.hh.mm.ss.ticks
'g' write duration with optional ticks d.h.mm.ss.ticks
'G' write duration with optional ticks d.hh.mm.ss.ticks
'h' write absolute value of hours h
'H' write absolute value of hours hh
'l' write absolute value of milliseconds
'L' write absolute value of milliseconds fixed at 3 digits
'm' write absolute value of minutes m
'M' write absolute value of minutes mm
'o' write optional minus sign
'o' write minus or plus sign
's' write absolute value of seconds s
'S' write absolute value of seconds ss
't' write absolute value of ticks
'T' write absolute value of ticks fixed at 7 digits

Implements xtd::iformatable.

◆ equals() [3/3]

auto xtd::time_span::equals ( time_span t1,
time_span t2 ) -> bool
staticnodiscard

Returns a value that indicates whether two specified instances of xtd::time_span are equal.

Parameters
t1The first time interval to compare.
t2The second time interval to compare.
Returns
true if the values of t1 and t2 are equal; otherwise, false.

◆ from_days() [1/2]

auto xtd::time_span::from_days ( double value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of days, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of days, accurate to the nearest millisecond.
Returns
An object that represents value.
Exceptions
xtd::overflow_exceptionvalue is less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
-or-
value is xtd::double_object::positive_infinity.
-or-
value is xtd::double_object::negative_infinity.
xtd::argument_exceptionvalue is equal to xtd::double_object::NaN.
Examples
The following example creates several xtd::time_span objects using the xtd::time_span::from_days method.
#include <xtd/xtd>
auto gen_time_span_from_days (double days) -> void {
// Creates a time_span object and a time_span string from a number of days.
auto interval = time_span::from_days(days);
auto time_interval = interval.to_string();
// Fills the end of the time_span string with spaces if it does not contain milliseconds.
auto index = time_interval.index_of(':');
index = time_interval.index_of('.', index);
if (index == string::npos) time_interval += " ";
console::write_line("{0,21}{1,26}", days, time_interval);
}
auto main() -> int {
console::write_line("This example of time_span::from_days(double)\n"
"generates the following output.\n");
console::write_line("{0,21}{1,19}", "from_days", "time_span");
console::write_line("{0,21}{1,19}", "---------", "---------");
gen_time_span_from_days(0.000000006);
gen_time_span_from_days(0.000000017);
gen_time_span_from_days(0.000123456);
gen_time_span_from_days(1.234567898);
gen_time_span_from_days(12345.678987654);
gen_time_span_from_days(0.000011574);
gen_time_span_from_days(0.000694444);
gen_time_span_from_days(0.041666666);
gen_time_span_from_days(1);
gen_time_span_from_days(20.84745602);
}
// This example of time_span::from_days(double)
// generates the following output.
//
// from_days time_span
// --------- ---------
// 6E-09 00:00:00.0010000
// 1.7E-08 00:00:00.0010000
// 0.000123456 00:00:10.6670000
// 1.234567898 1.05:37:46.6660000
// 12345.678987654 12345.16:17:44.5330000
// 1.1574E-05 00:00:01
// 0.000694444 00:01:00
// 0.041666666 01:00:00
// 1 1.00:00:00
// 20.84745602 20.20:20:20.2000000
static constexpr size_type npos
Definition basic_string.hpp:121
static auto write_line() -> void
Writes the current line terminator to the standard output stream using the specified format informati...
auto days() const noexcept -> xtd::int32
Gets the days component of the time interval represented by the current xtd::time_span structure.
static auto from_days(double value) -> time_span
Returns a xtd::time_span that represents a specified number of days, where the specification is accur...
Remarks
The value parameter is converted to milliseconds, which is converted to ticks, and that number of ticks is used to initialize the new xd::time_span. Therefore, value will only be considered accurate to the nearest millisecond. Note that, because of the loss of precision of the Double data type, this conversion can cause an xtd::overflow_exception for values that are near to but still in the range of either xd::time_span::min_value or xd::time_span::max_value. For example, this causes an xtd:overflow_exception in the following attempt to instantiate a xd::time_span object.
// The following throws an overflow_exception at runtime
auto total_days() const noexcept -> double
Gets the value of the current xtd::time_span structure expressed in whole and fractional days.
static const time_span max_value
Represents the maximum xtd::time_span value. This field is read-only.
Definition time_span.hpp:36

◆ from_days() [2/2]

auto xtd::time_span::from_days ( std::chrono::days value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of days, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of days, accurate to the nearest millisecond.
Returns
An object that represents value.

◆ from_hours() [1/2]

auto xtd::time_span::from_hours ( double value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of hours, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of hours, accurate to the nearest millisecond.
Returns
An object that represents value.
Exceptions
xtd::overflow_exceptionvalue is less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
-or-
value is xtd::double_object::positive_infinity.
-or-
value is xtd::double_object::negative_infinity.
xtd::argument_exceptionvalue is equal to xtd::double_object::NaN.
Remarks
The value parameter is converted to milliseconds, which is converted to ticks, and that number of ticks is used to initialize the new xtd::time_span. Therefore, value will only be considered accurate to the nearest millisecond. Note that, because of the loss of precision of the double data type, this conversion can generate an xtd::overflow_exception for values that are near to but still in the range of either xtd::time_span::min_value or xtd::time_span::max_value. For example, this causes an xtd::overflow_exception in the following attempt to instantiate a xtd::time_span object.
// The following throws an overflow_exception at runtime
auto max_span = time_span::from_hours(time_span::max_value::total_hours());
static auto from_hours(double value) -> time_span
Returns a xtd::time_span that represents a specified number of hours, where the specification is accu...
Examples
The following example creates several xtd::time_span objects using the xtd::time_span::from_hours method.
#include <xtd/xtd>
void gen_time_span_from_hours(double hours) {
// Creates a `time_span` object and a string from a number of hours.
string time_interval = interval.to_string();
// Fills the end of the string with spaces if it does not contain any milliseconds.
auto index = time_interval.index_of(':');
index = time_interval.index_of( '.', index );
if (index < 0) time_interval += " ";
console::write_line( "{0,21}{1,26}", hours, time_interval );
}
int main( ) {
console::write_line("This example of time_span::from_hours(double)\n"
"generates the following output.\n" );
console::write_line( "{0,21}{1,19}",
"from_hours", "time_span" );
console::write_line( "{0,21}{1,19}",
"----------", "---------" );
gen_time_span_from_hours( 0.0000002 );
gen_time_span_from_hours( 0.0000003 );
gen_time_span_from_hours( 0.0012345 );
gen_time_span_from_hours( 12.3456789 );
gen_time_span_from_hours( 123456.7898765 );
gen_time_span_from_hours( 0.0002777 );
gen_time_span_from_hours( 0.0166666 );
gen_time_span_from_hours( 1 );
gen_time_span_from_hours( 24 );
gen_time_span_from_hours( 500.3389445 );
}
// This example of time_span::from_hours(double)
// generates the following output.
//
// from_hours time_span
// ---------- ---------
// 2E-07 00:00:00.0007200
// 3E-07 00:00:00.0010800
// 0.0012345 00:00:04.4442000
// 12.3456789 12:20:44.4440400
// 123456.7898765 5144.00:47:23.5554000
// 0.0002777 00:00:00.9997199
// 0.0166666 00:00:59.9997600
// 1 01:00:00
// 24 1.00:00:00
// 500.3389445 20.20:20:20.2002000
auto index_of(const basic_string &value) const noexcept -> xtd::usize
Reports the index of the first occurrence of the specified basic_string in this basic_string.
Definition basic_string.hpp:503
time_span(xtd::int64 ticks)
Initializes a new instance of the xtd::time_span structure to the specified number of ticks.
auto hours() const noexcept -> xtd::int32
Gets the hours component of the time interval represented by the current xtd::time_span structure.

◆ from_hours() [2/2]

auto xtd::time_span::from_hours ( std::chrono::hours value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of hours, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of hours, accurate to the nearest millisecond.
Returns
An object that represents value.

◆ from_microseconds() [1/2]

auto xtd::time_span::from_microseconds ( double value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of microseconds.

Parameters
valueA number of microseconds.
Returns
An object that represents value.
Exceptions
xtd::overflow_exceptionvalue is less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
-or-
value is xtd::double_object::positive_infinity.
-or-
value is xtd::double_object::negative_infinity.
xtd::argument_exceptionvalue is equal to xtd::double_object::NaN.

◆ from_microseconds() [2/2]

auto xtd::time_span::from_microseconds ( std::chrono::microseconds value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of microseconds.

Parameters
valueA number of microseconds.
Returns
An object that represents value.

◆ from_milliseconds() [1/2]

auto xtd::time_span::from_milliseconds ( double value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of milliseconds.

Parameters
valueA number of milliseconds.
Returns
An object that represents value.
Exceptions
xtd::overflow_exceptionvalue is less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
-or-
value is xtd::double_object::positive_infinity.
-or-
value is xtd::double_object::negative_infinity.
xtd::argument_exceptionvalue is equal to xtd::double_object::NaN.
Remarks
The value parameter is converted to ticks, and that number of ticks is used to initialize the new xtd::time_span. Therefore, value will only be considered accurate to the nearest millisecond. Note that, because of the loss of precision of the Double data type, this conversion can generate an xtd::overflow_exception for values that are near to but still in the range of either xtd::time_span::min_value or xtd::time_span::max_value. For example, this causes an xtd::overflow_exception in the following attempt to instantiate a xtd::time_span object.
// The following throws an overflow_exception at runtime
auto max_span = time_span::from_milliseconds(time_span::max_value::total_milliseconds);
static auto from_milliseconds(double value) -> time_span
Returns a xtd::time_span that represents a specified number of milliseconds.

◆ from_milliseconds() [2/2]

auto xtd::time_span::from_milliseconds ( std::chrono::milliseconds value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of milliseconds.

Parameters
valueA number of milliseconds.
Returns
An object that represents value.

◆ from_minutes() [1/2]

auto xtd::time_span::from_minutes ( double value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of minutes, accurate to the nearest millisecond.
Returns
An object that represents value.
Exceptions
xtd::overflow_exceptionvalue is less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
-or-
value is xtd::double_object::positive_infinity.
-or-
value is xtd::double_object::negative_infinity.
xtd::argument_exceptionvalue is equal to xtd::double_object::NaN.
Remarks
The value parameter is converted to milliseconds, which is converted to ticks, and that number of ticks is used to initialize the new xtd::time_span. Therefore, value will only be considered accurate to the nearest millisecond. Note that, because of the loss of precision of the Double data type, this conversion can generate an xtd::overflow_exception for values that are near to but still in the range of either xtd::time_span::min_value or xtd::time_span::max_value. For example, this causes an xtd::overflow_exception in the following attempt to instantiate a xtd::time_span object.
// The following throws an overflow_exception at runtime
auto max_span = time_span::from_minutes(time_span::max_value::total_miminutes);
static auto from_minutes(double value) -> time_span
Returns a xtd::time_span that represents a specified number of minutes, where the specification is ac...

◆ from_minutes() [2/2]

auto xtd::time_span::from_minutes ( std::chrono::minutes value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of minutes.

Parameters
valueA number of minutes.
Returns
An object that represents value.

◆ from_nanoseconds() [1/2]

auto xtd::time_span::from_nanoseconds ( double value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of nanoseconds.

Parameters
valueA number of nanoseconds.
Returns
An object that represents value.

◆ from_nanoseconds() [2/2]

auto xtd::time_span::from_nanoseconds ( std::chrono::nanoseconds value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of nanoseconds.

Parameters
valueA number of nanoseconds.
Returns
An object that represents value.

◆ from_seconds() [1/2]

auto xtd::time_span::from_seconds ( double value) -> time_span
staticnodiscard

Returns a xtd::time_spam that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.

Parameters
valueA number of minutes, accurate to the nearest second.
Returns
An object that represents value.
Exceptions
xtd::overflow_exceptionvalue is less than xtd::time_span::min_value or greater than xtd::time_span::max_value.
-or-
value is xtd::double_object::positive_infinity.
-or-
value is xtd::double_object::negative_infinity.
xtd::argument_exceptionvalue is equal to xtd::double_object::NaN.
Remarks
The value parameter is converted to milliseconds, which is converted to ticks, and that number of ticks is used to initialize the new xtd::time_span. Therefore, value will only be considered accurate to the nearest millisecond. Note that, because of the loss of precision of the Double data type, this conversion can generate an xtd::overflow_exception for values that are near to but still in the range of either xtd::time_span::min_value or xtd::time_span::max_value. For example, this causes an xtd::overflow_exception in the following attempt to instantiate a xtd::time_span object.
// The following throws an overflow_exception at runtime
auto max_span = time_span::from_seconds(time_span::max_value::total_seconds);
static auto from_seconds(double value) -> time_span
Returns a xtd::time_spam that represents a specified number of seconds, where the specification is ac...

◆ from_seconds() [2/2]

auto xtd::time_span::from_seconds ( std::chrono::seconds value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of seconds.

Parameters
valueA number of seconds.
Returns
An object that represents value.

◆ from_ticks() [1/2]

auto xtd::time_span::from_ticks ( int64 value) -> time_span
staticnodiscard

Returns a xtd::time_spam that represents a specified time, where the specification is in units of ticks.

Parameters
valueA number of ticks that represent a time.
Returns
An object that represents value.

◆ from_ticks() [2/2]

auto xtd::time_span::from_ticks ( xtd::ticks value) -> time_span
staticnodiscard

Returns a xtd::time_span that represents a specified number of ticks.

Parameters
valueA number of ticks.
Returns
An object that represents value.
Remarks
This is a convenience method with the same behavior as the xtd::time_spam.xtd::time_spam (int64) constructor. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond.

◆ try_parse()

auto xtd::time_span::try_parse ( const string & value,
time_span & result ) -> bool
staticnodiscard

Converts the string representation of a time interval to its xtd::time_span equivalent and returns a value that indicates whether the conversion succeeded.

Parameters
valueA string that specifies the time interval to convert.
resultWhen this method returns, contains an object that represents the time interval specified by value, or xtd::time_span::zero if the conversion failed.
Returns
true if s was converted successfully; otherwise, false. This operation returns false if the value parameter is empty (""), has an invalid format, represents a time interval that is less than xtd::time_span::min_value or greater than xtd::time_span::max_value, or has at least one days, hours, minutes, or seconds component outside its valid range.

Member Data Documentation

◆ max_value

const time_span xtd::time_span::max_value
static

Represents the maximum xtd::time_span value. This field is read-only.

Remarks
The value of this field is equivalent to xtd::int64_object::max_value ticks. The string representation of this value is positive 10675199.02:48:05.4775807, or slightly more than 10,675,199 days.

◆ min_value

const time_span xtd::time_span::min_value
static

Represents the minimum xtd::time_span value. This field is read-only.

Remarks
The value of this field is equivalent to xtd::int64_object::min_value ticks. The string representation of this value is negative 10675199.02:48:05.4775808, or slightly more than negative 10,675,199 days.

◆ nanoseconds_per_tick

xtd::int64 xtd::time_span::nanoseconds_per_tick
staticconstexpr

Represents the number of nanoseconds per tick. This field is constant.

Remarks
The value of this constant is 100.

◆ ticks_per_microsecond

xtd::int64 xtd::time_span::ticks_per_microsecond
staticconstexpr

Represents the number of ticks in 1 microsecond. This field is constant.

Remarks
The value of this constant is 10.

◆ ticks_per_millisecond

xtd::int64 xtd::time_span::ticks_per_millisecond
staticconstexpr

Represents the number of ticks in 1 millisecond. This field is constant.

Remarks
The value of this constant is 10 thousand; that is, 10,000.

◆ ticks_per_second

xtd::int64 xtd::time_span::ticks_per_second
staticconstexpr

Represents the number of ticks in 1 second.

Remarks
he value of this constant is 10 million; that is, 10'000'000.

◆ ticks_per_minute

xtd::int64 xtd::time_span::ticks_per_minute
staticconstexpr

Represents the number of ticks in 1 minute. This field is constant.

Remarks
The value of this constant is 600 million; that is, 600'000'000.

◆ ticks_per_hour

xtd::int64 xtd::time_span::ticks_per_hour
staticconstexpr

Represents the number of ticks in 1 hour. This field is constant.

Remarks
The value of this constant is 36 billion; that is, 36'000'000'000.

◆ ticks_per_day

xtd::int64 xtd::time_span::ticks_per_day
staticconstexpr

Represents the number of ticks in 1 day. This field is constant.

Remarks
The value of this constant is 864 billion; that is, 864'000'000'000.

◆ zero

const time_span xtd::time_span::zero
static

Represents the zero xtd::time_span value. This field is read-only.

Remarks
Because the value of the Zero field is a xtd::time_span object that represents a zero time value, you can compare it with other xtd::time_span objects to determine whether the latter represent positive, non-zero, or negative time intervals. You can also use this field to initialize a xtd::time_span object to a zero time value.

The documentation for this class was generated from the following file: