6 #include "../conversion/types.h"
60 constexpr DateTime(
uint64 ticks);
61 static DateTime fromDate(
int year = 1,
int month = 1,
int day = 1);
62 static DateTime fromTime(
int hour = 0,
int minute = 0,
int second = 0,
double millisecond = 0.0);
63 static DateTime fromDateAndTime(
int year = 1,
int month = 1,
int day = 1,
int hour = 0,
int minute = 0,
int second = 0,
double millisecond = 0.0);
64 static DateTime fromString(
const std::string &str);
66 constexpr
uint64 totalTicks()
const;
70 int dayOfYear()
const;
72 constexpr
int hour()
const;
73 constexpr
int minute()
const;
74 constexpr
int second()
const;
75 constexpr
int millisecond()
const;
76 constexpr
bool isNull()
const;
77 constexpr
TimeSpan timeOfDay()
const;
78 bool isLeapYear()
const;
79 constexpr
bool isSameDay(
const DateTime &other)
const;
82 static const char *printDayOfWeek(
DayOfWeek dayOfWeek,
bool abbreviation =
false);
84 static DateTime now();
85 constexpr
static bool isLeapYear(
int year);
86 static int daysInMonth(
int year,
int month);
88 constexpr
bool operator ==(
const DateTime &other)
const;
89 constexpr
bool operator !=(
const DateTime &other)
const;
90 constexpr
bool operator <(
const DateTime &other)
const;
91 constexpr
bool operator >(
const DateTime &other)
const;
92 constexpr
bool operator <=(
const DateTime &other)
const;
93 constexpr
bool operator >=(
const DateTime &other)
const;
94 constexpr DateTime operator +(
const TimeSpan &timeSpan)
const;
95 constexpr DateTime operator -(
const TimeSpan &timeSpan)
const;
96 constexpr
TimeSpan operator +(
const DateTime &other)
const;
97 constexpr
TimeSpan operator -(
const DateTime &other)
const;
98 DateTime &operator +=(
const TimeSpan &timeSpan);
99 DateTime &operator -=(
const TimeSpan &timeSpan);
102 static uint64 dateToTicks(
int year,
int month,
int day);
103 static uint64 timeToTicks(
int hour,
int minute,
int second,
double millisecond);
104 int getDatePart(
DatePart part)
const;
107 static const int m_daysPerYear;
108 static const int m_daysPer4Years;
109 static const int m_daysPer100Years;
110 static const int m_daysPer400Years;
111 static const int m_daysTo1601;
112 static const int m_daysTo1899;
113 static const int m_daysTo10000;
114 static const int m_daysToMonth365[13];
115 static const int m_daysToMonth366[13];
116 static const int m_daysInMonth365[12];
117 static const int m_daysInMonth366[12];
139 return DateTime(dateToTicks(year, month, day));
147 return DateTime(timeToTicks(hour, minute, second, millisecond));
155 uint64 ticks = dateToTicks(year, month, day);
157 return DateTime(ticks + timeToTicks(hour, minute, second, millisecond));
208 return static_cast<DayOfWeek>((m_ticks / TimeSpan::m_ticksPerDay) % 7l);
216 return m_ticks / TimeSpan::m_ticksPerHour % 24ul;
224 return m_ticks / TimeSpan::m_ticksPerMinute % 60ul;
232 return m_ticks / TimeSpan::m_ticksPerSecond % 60ul;
240 return m_ticks / TimeSpan::m_ticksPerMillisecond % 1000ul;
257 return TimeSpan(m_ticks % TimeSpan::m_ticksPerDay);
273 return (year % 4 != 0)
285 return (month >= 1 && month <= 12)
287 ? m_daysInMonth366[month - 1]
288 : m_daysInMonth365[month - 1])
297 return (m_ticks / TimeSpan::m_ticksPerDay) == (other.m_ticks / TimeSpan::m_ticksPerDay);
305 return m_ticks == other.m_ticks;
313 return m_ticks != other.m_ticks;
321 return m_ticks < other.m_ticks;
329 return m_ticks > other.m_ticks;
337 return m_ticks <= other.m_ticks;
345 return m_ticks >= other.m_ticks;
354 return DateTime(m_ticks + timeSpan.m_ticks);
363 return DateTime(m_ticks - timeSpan.m_ticks);
372 return TimeSpan(m_ticks + other.m_ticks);
381 return TimeSpan(m_ticks - other.m_ticks);
389 m_ticks += timeSpan.m_ticks;
398 m_ticks -= timeSpan.m_ticks;
constexpr int millisecond() const
Gets the millisecond component of the date represented by this instance.
DateTime & operator-=(const TimeSpan &timeSpan)
Substracts a TimeSpan from the current instance.
constexpr bool operator<(const DateTime &other) const
Indicates whether a specified DateTime is less than another specified DateTime.
static int daysInMonth(int year, int month)
Returns the number of days in the specified month and year.
Represents an instant in time, typically expressed as a date and time of day.
Contains classes providing a means for handling date and time information.
constexpr int hour() const
Gets the hour component of the date represented by this instance.
constexpr TimeSpan timeOfDay() const
Gets the time of day as TimeSpan for this instance.
Represents a time interval.
constexpr bool isNull() const
Returns ture if the date represented by the current DateTime class is null.
static DateTime fromDateAndTime(int year=1, int month=1, int day=1, int hour=0, int minute=0, int second=0, double millisecond=0.0)
Constructs a DateTime to the specified year, month, day, hour, minute, second and millisecond...
static DateTime fromDate(int year=1, int month=1, int day=1)
Constructs a DateTime to the specified year, month, and day.
#define LIB_EXPORT
This macro marks a symbol for shared library export.
std::uint64_t uint64
unsigned 64-bit integer
int year() const
Gets the year component of the date represented by this instance.
constexpr DateTime operator-(const TimeSpan &timeSpan) const
Substracts a TimeSpan.
constexpr bool operator==(const DateTime &other) const
Indicates whether two DateTime instances are equal.
DateTime & operator+=(const TimeSpan &timeSpan)
Adds a TimeSpan to the current instance.
constexpr bool isSameDay(const DateTime &other) const
Returns and indication whether two DateTime instances represent the same day.
constexpr uint64 totalTicks() const
Gets the number of ticks that represent the value of the current DateTime class.
constexpr int second() const
Gets the second component of the date represented by this instance.
constexpr bool operator!=(const DateTime &other) const
Indicates whether two DateTime instances are not equal.
DatePart
Specifies the date part.
constexpr DateTime()
Constructs a DateTime.
constexpr int minute() const
Gets the minute component of the date represented by this instance.
static DateTime fromTime(int hour=0, int minute=0, int second=0, double millisecond=0.0)
Constructs a DateTime to the specified hour, minute, second and millisecond.
int dayOfYear() const
Gets the day of the year represented by this instance.
DateTimeOutputFormat
Specifies the output format.
constexpr bool operator>(const DateTime &other) const
Indicates whether a specified DateTime is greater than another specified DateTime.
constexpr DateTime operator+(const TimeSpan &timeSpan) const
Adds a TimeSpan.
constexpr bool operator>=(const DateTime &other) const
Indicates whether a specified DateTime is greater or equal than another specified DateTime...
constexpr DayOfWeek dayOfWeek() const
Gets the day of the week represented by this instance.
DayOfWeek
Specifies the day of the week.
constexpr bool operator<=(const DateTime &other) const
Indicates whether a specified DateTime is less or equal than another specified DateTime.
int month() const
Gets the month component of the date represented by this instance.
bool isLeapYear() const
Returns an indication whether the year of the dae represented by this instance is a leap year...
int day() const
Gets the day component of the date represented by this instance.