xtd 0.2.0
Loading...
Searching...
No Matches
xtd::time_span Struct Reference
Inheritance diagram for xtd::time_span:
xtd::object xtd::iequatable< time_span > xtd::icomparable< time_span > xtd::iformatable xtd::interface xtd::equality_operators< type_t, equatable_t > xtd::interface xtd::comparison_operators< type_t, comparable_t > 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/console>
#include <xtd/startup>
#include <xtd/date_time>
#include <xtd/time_span>
using namespace 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 :
//
// Wed Aug 18 13:30:30 2010 - Fri Jan 1 08:00:15 2010 = 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.h:85
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Represents a time interval.
Definition time_span.h:29
double total_milliseconds() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional milliseconds...
int32 milliseconds() const noexcept
Gets the milliseconds component of the time interval represented by the current xtd::time_span struct...
double total_seconds() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional seconds.
double total_days() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional days.
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
int32 days() const noexcept
Gets the days component of the time interval represented by the current xtd::time_span structure.
int32 seconds() const noexcept
Gets the seconds component of the time interval represented by the current xtd::time_span structure.
int32 minutes() const noexcept
Gets the minutes component of the time interval represented by the current xtd::time_span structure.
int64 ticks() const noexcept
Gets the number of ticks that represent the value of the current xtd::time_span structure.
double total_hours() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional hours.
double total_minutes() const noexcept
Gets the value of the current xtd::time_span structure expressed in whole and fractional minutes.
int32 hours() const noexcept
Gets the hours component of the time interval represented by the current xtd::time_span structure.
Examples
date_time_ticks2.cpp, graph_control.cpp, time_span.cpp, and time_span_from_hours.cpp.

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 int64 nanoseconds_per_tick
 Represents the number of nanoseconds per tick. This field is constant.
 
static constexpr int64 ticks_per_microsecond
 Represents the number of ticks in 1 microsecond. This field is constant.
 
static constexpr int64 ticks_per_millisecond
 Represents the number of ticks in 1 millisecond. This field is constant.
 
static constexpr int64 ticks_per_second
 Represents the number of ticks in 1 second.
 
static constexpr int64 ticks_per_minute
 Represents the number of ticks in 1 minute. This field is constant.
 
static constexpr int64 ticks_per_hour
 Represents the number of ticks in 1 hour. This field is constant.
 
static constexpr 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 (int64 ticks)
 Initializes a new instance of the xtd::time_span structure to the specified number of ticks.
 
 time_span (xtd::ticks ticks)
 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 (int32 hours, int32 minutes, int32 seconds)
 Initializes a new instance of the xtd::time_span structure to a specified number of hours, minutes, and seconds.
 
 time_span (int32 days, int32 hours, int32 minutes, int32 seconds)
 Initializes a new instance of the xtd::time_span structure to a specified number of days, hours, minutes, and seconds.
 
 time_span (int32 days, int32 hours, int32 minutes, int32 seconds, 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 (int32 days, int32 hours, int32 minutes, int32 seconds, int32 milliseconds, 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 (int32 days, int32 hours, int32 minutes, int32 seconds, int32 milliseconds, int32 microseconds, 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

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

Public Methods

time_span add (const time_span &ts) const noexcept
 Returns a new xtd::time_span object whose value is the sum of the specified xtd::time_span object and this instance.
 
int32 compare_to (const time_span &value) const noexcept override
 Compares the current instance with another object of the same type.
 
double divide (const time_span &ts) const
 Returns a double value that's the result of dividing this instance by ts.
 
time_span divide (double divisor) const
 Returns a new xtd::time_span object whose value is the result of dividing this instance by the specified divisor.
 
time_span duration () const noexcept
 Returns a new xtd::time_span object whose value is the absolute value of the current xtd::time_span object.
 
bool equals (const time_span &value) const noexcept override
 Indicates whether the current object is equal to another object of the same type.
 
double multiply (const time_span &ts) const noexcept
 Returns a new xtd::time_spam object which value is the result of multiplication of this instance and the specified factor.
 
time_span multiply (double factor) const noexcept
 Returns a new xtd::time_spam object which value is the result of multiplication of this instance and the specified factor.
 
time_span negate () const
 Returns a new xtd::time_spam object whose value is the negated value of this instance.
 
time_span subtract (const time_span &ts) const noexcept
 Returns a new xtd::time_span object whose value is the difference between the specified xtd::time_span object and this instance.
 
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 
string to_string (const string &format) const
 Converts the value of the current xtd::time_span object to its equivalent string representation by using the specified format.
 
string to_string (const string &format, const std::locale &loc) const override
 Converts the value of the current xtd::time_span object to its equivalent string representation by using the specified format, and locale.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
static time_span parse (const string &value)
 Converts the string representation of a time interval to its xtd::time_span equivalent.
 
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 

Public Static Methods

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

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::iequatable< time_span >
- Public Member Functions inherited from xtd::icomparable< time_span >
- Public Member Functions inherited from xtd::iformatable
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ time_span() [1/8]

xtd::time_span::time_span ( 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 ( int32  hours,
int32  minutes,
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 ( int32  days,
int32  hours,
int32  minutes,
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 ( int32  days,
int32  hours,
int32  minutes,
int32  seconds,
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 ( int32  days,
int32  hours,
int32  minutes,
int32  seconds,
int32  milliseconds,
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 ( int32  days,
int32  hours,
int32  minutes,
int32  seconds,
int32  milliseconds,
int32  microseconds,
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()

int32 xtd::time_span::days ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ hours()

int32 xtd::time_span::hours ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ microseconds()

int32 xtd::time_span::microseconds ( ) const
noexcept

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()

int32 xtd::time_span::milliseconds ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ minutes()

int32 xtd::time_span::minutes ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ nanoseconds()

int32 xtd::time_span::nanoseconds ( ) const
noexcept

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()

int32 xtd::time_span::seconds ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ ticks()

int64 xtd::time_span::ticks ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ ticks_duration()

xtd::ticks xtd::time_span::ticks_duration ( ) const
noexcept

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()

double xtd::time_span::total_days ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ total_days_duration()

std::chrono::days xtd::time_span::total_days_duration ( ) const
noexcept

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()

double xtd::time_span::total_hours ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ total_hours_duration()

std::chrono::hours xtd::time_span::total_hours_duration ( ) const
noexcept

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()

double xtd::time_span::total_microseconds ( ) const
noexcept

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()

std::chrono::microseconds xtd::time_span::total_microseconds_duration ( ) const
noexcept

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()

double xtd::time_span::total_milliseconds ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ total_milliseconds_duration()

std::chrono::milliseconds xtd::time_span::total_milliseconds_duration ( ) const
noexcept

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()

double xtd::time_span::total_minutes ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ total_minutes_duration()

std::chrono::minutes xtd::time_span::total_minutes_duration ( ) const
noexcept

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()

double xtd::time_span::total_nanoseconds ( ) const
noexcept

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()

std::chrono::nanoseconds xtd::time_span::total_nanoseconds_duration ( ) const
noexcept

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()

double xtd::time_span::total_seconds ( ) const
noexcept

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.
Examples
time_span.cpp.

◆ total_seconds_duration()

std::chrono::seconds xtd::time_span::total_seconds_duration ( ) const
noexcept

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()

time_span xtd::time_span::add ( const time_span ts) const
noexcept

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()

int32 xtd::time_span::compare_to ( const time_span obj) const
overridevirtualnoexcept

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]

double xtd::time_span::divide ( const time_span ts) const

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]

time_span xtd::time_span::divide ( double  divisor) const

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()

time_span xtd::time_span::duration ( ) const
noexcept

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/4]

bool xtd::time_span::equals ( const time_span ) const
overridevirtualnoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

Implements xtd::iequatable< time_span >.

◆ multiply() [1/2]

double xtd::time_span::multiply ( const time_span ts) const
noexcept

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]

time_span xtd::time_span::multiply ( double  factor) const
noexcept

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()

time_span xtd::time_span::negate ( ) const

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()

static time_span xtd::time_span::parse ( const string value)
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()

time_span xtd::time_span::subtract ( const time_span ts) const
noexcept

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]

xtd::string xtd::time_span::to_string ( ) const
overridevirtualnoexcept

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>
using namespace 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
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27

Reimplemented from xtd::object.

Examples
time_span.cpp, and time_span_from_hours.cpp.

◆ to_string() [2/3]

string xtd::time_span::to_string ( const string format) const

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]

string xtd::time_span::to_string ( const string format,
const std::locale &  loc 
) const
overridevirtual

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.
locAn std::locale object that contains locale information (see std::locale).
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() [2/4]

static bool xtd::time_span::equals ( time_span  t1,
time_span  t2 
)
static

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]

static time_span xtd::time_span::from_days ( double  value)
static

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/console>
#include <xtd/time_span>
#include <xtd/int64_object>
#include <xtd/string>
using namespace xtd;
void gen_time_span_from_days (double days) {
// Crée un objet TimeSpan et une chaîne TimeSpan à partir
// d'un nombre de jours.
auto interval = time_span::from_days(days);
auto time_interval = interval.to_string();
// Remplit la fin de la chaîne TimeSpan avec des espaces si elle
// ne contient pas de millisecondes.
size_t 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);
}
int main() {
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
This is a special value equal to the maximum value representable by the type xtd::size.
Definition basic_string.h:127
xtd::size index_of(const basic_string &value) const noexcept
Reports the index of the first occurrence of the specified basic_string in this basic_string.
Definition basic_string.h:1433
static time_span from_days(double value)
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
static const time_span max_value
Represents the maximum xtd::time_span value. This field is read-only.
Definition time_span.h:36

◆ from_days() [2/2]

static time_span xtd::time_span::from_days ( std::chrono::days  value)
static

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]

static time_span xtd::time_span::from_hours ( double  value)
static

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 time_span from_hours(double value)
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/console>
#include <xtd/time_span>
#include <xtd/int64_object>
#include <xtd/string>
using namespace xtd;
void gen_time_span_from_hours(double hours) {
// Crée un objet time_span et une chaîne string à partir
// d'un nombre d'heures.
string timeInterval = interval.to_string();
// Remplit la fin de la chaîne string avec des espaces si elle
// ne contient pas de millisecondes.
size_t pIndex = timeInterval.index_of(':');
pIndex = timeInterval.index_of( '.', pIndex );
if (pIndex < 0) timeInterval += " ";
console::write_line( "{0,21}{1,26}", hours, timeInterval );
}
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

◆ from_hours() [2/2]

static time_span xtd::time_span::from_hours ( std::chrono::hours  value)
static

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]

static time_span xtd::time_span::from_microseconds ( double  value)
static

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]

static time_span xtd::time_span::from_microseconds ( std::chrono::microseconds  value)
static

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]

static time_span xtd::time_span::from_milliseconds ( double  value)
static

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 time_span from_milliseconds(double value)
Returns a xtd::time_span that represents a specified number of milliseconds.

◆ from_milliseconds() [2/2]

static time_span xtd::time_span::from_milliseconds ( std::chrono::milliseconds  value)
static

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]

static time_span xtd::time_span::from_minutes ( double  value)
static

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 time_span from_minutes(double value)
Returns a xtd::time_span that represents a specified number of minutes, where the specification is ac...

◆ from_minutes() [2/2]

static time_span xtd::time_span::from_minutes ( std::chrono::minutes  value)
static

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]

static time_span xtd::time_span::from_nanoseconds ( double  value)
static

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]

static time_span xtd::time_span::from_nanoseconds ( std::chrono::nanoseconds  value)
static

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]

static time_span xtd::time_span::from_seconds ( double  value)
static

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 time_span from_seconds(double value)
Returns a xtd::time_spam that represents a specified number of seconds, where the specification is ac...

◆ from_seconds() [2/2]

static time_span xtd::time_span::from_seconds ( std::chrono::seconds  value)
static

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]

static time_span xtd::time_span::from_ticks ( int64  value)
static

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]

static time_span xtd::time_span::from_ticks ( xtd::ticks  value)
static

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()

static bool xtd::time_span::try_parse ( const string value,
time_span result 
)
static

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.

◆ equals() [3/4]

virtual bool xtd::object::equals ( const object obj) const
virtualnoexcept

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.
Examples
The following code example compares the current instance with another object.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true

Reimplemented from xtd::object.

◆ equals() [4/4]

template<typename object_a_t , typename object_b_t >
static bool xtd::object::equals ( const object_a_t &  object_a,
const object_b_t &  object_b 
)
inlinestaticnoexcept

Determines whether the specified object instances are considered equal.

Parameters
object_aThe first object to compare.
object_bThe second object to compare.
Returns
true if object_a is the same instance as object_b or if both are null references or if object_a(object_b) returns true. otherwise, false.
Examples
The following code example compares different objects.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
string s1 = "Tom";
string s2 = "Carol";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Carol";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
}
// This code produces the following output :
//
// object::equals("Tom", "Carol") => false
// object::equals("Tom", "Tom") => true
// object::equals("", "Tom") => false
// object::equals("Carol", "") => false
// object::equals("", "") => true
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.

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

constexpr 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

constexpr 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

constexpr 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

constexpr 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

constexpr 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

constexpr 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

constexpr 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 struct was generated from the following file: