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

◆ 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: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
static time_span from_days(double value)
Returns a xtd::time_span that represents a specified number of days, where the specification is accur...
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.
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
double total_days() const noexcept
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.h:36