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

◆ max_value

const date_time xtd::date_time::max_value
static

Represents the largest possible value of xtd::date_time. This field is read-only.

Remarks
The value of this constant is equivalent to 23:59:59.9999999 UTC, December 31, 9999 in the Gregorian calendar, exactly one 100-nanosecond tick before 00:00:00 UTC, January 1, 10000.
Examples
The following example instantiates a xtd::date_time object by passing its constructor an xtd::ticks value that represents a number of ticks. Before invoking the constructor, the example ensures that this value is greater than or equal to date_time::min_value.ticks() and less than or equal to date_time::max_value.ticks(). If not, it throws an xtd::argument_out_of_range_exception.
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/int64_object>
#include <xtd/startup>
using namespace xtd;
class program {
public:
static auto main() {
// Attempt to assign an out-of-range value to a date_time constructor.
auto number_of_ticks = int64_object::max_value;
auto valid_date = date_time {};
// Validate the value.
if (number_of_ticks >= date_time::min_value.ticks() && number_of_ticks <= date_time::max_value.ticks()) {
valid_date = date_time(number_of_ticks);
console::write_line("{0} is valid.", valid_date.ticks());
} else if (number_of_ticks < date_time::min_value.ticks())
console::write_line("{0} is less than {1} ticks.", number_of_ticks, date_time::min_value.ticks());
else
console::write_line("{0} is greater than {1} ticks.", number_of_ticks, date_time::max_value.ticks());
}
};
startup_(program::main);
// This code produces the following output :
//
// 9223372036854775807 is greater than 3155378975999999999 ticks.
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
std::chrono::duration< int64, tick > ticks
Represents a tick duration.
Definition ticks.h:21
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10