xtd 0.2.0
Loading...
Searching...
No Matches

◆ 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
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:1333
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
int32 hours() const noexcept
Gets the hours component of the time interval represented by the current xtd::time_span structure.
Represents a time interval.
Definition time_span.h:29