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

◆ min_value

const date_time xtd::date_time::min_value
static

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

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
Remarks
The value of this constant is equivalent to 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar.
xtd::date_time::min_value defines the date and time that is assigned to an uninitialized xtd::date_time variable. The following example illustrates this.
#include <xtd/console>
#include <xtd/date_time>
#include <xtd/startup>
using namespace xtd;
class program {
public:
static auto main() {
// Define an uninitialized date.
auto date1 = date_time {};
console::write("{:u}", date1);
if (date1.equals(date_time::min_value))
console::write_line(" (Equals date_time.min_value)");
}
};
startup_(program::main);
// This code produces the following output :
//
// 01/01/0001 00:00:00 (Equals date_time.min_value)