8 #ifndef INCL_evo_timestamp_h 9 #define INCL_evo_timestamp_h 23 inline int parse_num(
int& num,
const char*& inp,
const char* end) {
24 const int OVERFLOW_THRESHOLD =
Int::MAX / 10;
25 const char* start = inp;
28 if (*inp < '0' || *inp >
'9')
30 if (num >= OVERFLOW_THRESHOLD) {
34 num = (num * 10) + (*inp -
'0');
37 return (
int)(inp - start);
40 inline double parse_frac(
const char*& inp,
const char* end) {
44 if (*inp < '0' || *inp >
'9')
46 num = (num * 10) + (*inp -
'0');
87 static const int YEAR_MIN = 1000;
88 static const int YEAR_MAX = 9999;
89 static const int MONTH_MIN = 1;
90 static const int MONTH_MAX = 12;
91 static const int DAY_MIN = 1;
92 static const int DAY_MAX = 31;
93 static const ulong JDN_MIN = 2086302;
94 static const ulong JDN_MOD = 2400000;
102 { ::memset(
this, 0,
sizeof(
Date)); }
111 Date(
int year,
int month,
int day) : year(year), month(month), day(day) {
118 { ::memcpy(
this, &src,
sizeof(
Date)); }
125 { ::memcpy(
this, &src,
sizeof(
Date));
return *
this; }
132 {
return (year == oth.
year && month == oth.
month && day == oth.
day); }
139 {
return (year != oth.
year || month != oth.
month || day != oth.
day); }
146 {
return (year < oth.
year || (year == oth.
year && (month < oth.
month || (month == oth.
month && day < oth.
day)))); }
153 {
return (year < oth.
year || (year == oth.
year && (month < oth.
month || (month == oth.
month && day <= oth.
day)))); }
160 {
return (year > oth.
year || (year == oth.
year && (month > oth.
month || (month == oth.
month && day > oth.
day)))); }
167 {
return (year > oth.
year || (year == oth.
year && (month > oth.
month || (month == oth.
month && day >= oth.
day)))); }
174 if (year == oth.
year) {
175 if (month == oth.
month) {
178 else if (day < oth.
day)
180 }
else if (month < oth.
month)
182 }
else if (year < oth.
year)
200 return calc_jdn(year, month, day);
207 return (year >= YEAR_MIN && year <= YEAR_MAX &&
208 month >= MONTH_MIN && month <= MONTH_MAX &&
209 day >= DAY_MIN && day <= days_per_month(month, year));
214 year = month = day = 0;
225 bool set(
int new_year,
int new_month,
int new_day) {
226 if ( new_year < YEAR_MIN || new_year > YEAR_MAX ||
227 new_month < MONTH_MIN || new_month > MONTH_MAX ||
228 new_day < DAY_MIN || new_day > days_per_month(new_month, new_year) )
250 const long f = jdn + 1401 + (((4 * jdn + 274277) / 146097) * 3) / 4 + -38;
251 const long e = 4 * f + 3;
252 const long g = (e % 1461) / 4;
253 const long h = 5 * g + 2;
254 day = (int)((h % 153) / 5 + 1);
255 month = (int)(((h / 153 + 2) % 12) + 1);
256 year = (int)((e / 1461) - 4716 + (12 + 2 - month) / 12);
262 int hour, minute, second, msecond;
268 int hour, minute, second, msecond;
282 const int maxday = days_per_month(month, year);
285 return (year >= YEAR_MIN && year <= YEAR_MAX);
297 year += (months / MONTH_MAX);
298 month += (months % MONTH_MAX);
299 if (month > MONTH_MAX) {
302 }
else if (month < MONTH_MIN) {
306 const int maxday = days_per_month(month, year);
309 return (year >= YEAR_MIN && year <= YEAR_MAX);
319 const ulong jdn = get_jdn();
323 return (year >= YEAR_MIN && year <= YEAR_MAX);
339 year = month = day = 0;
342 int digits = impl_time::parse_num(year, inp, end);
348 const int year_day = (year % 1000);
350 const int days_in_year = (is_leap_year(year) ? 366 : 365);
351 if (year_day <= 0 || year_day > days_in_year)
355 return add_days(year_day - 1);
364 month = (year % 100);
366 if (month < MONTH_MIN || month > MONTH_MAX || day > days_per_month(month, year))
378 if (*inp !=
'-' && *inp !=
'/' && *inp !=
'.' && *inp !=
' ')
384 digits = impl_time::parse_num(month, inp, end);
388 if (month < MONTH_MIN || month > MONTH_MAX)
393 const int year_day = month;
394 const int days_in_year = (is_leap_year(year) ? 366 : 365);
395 if (year_day <= 0 || year_day > days_in_year)
399 return add_days(year_day - 1);
411 digits = impl_time::parse_num(day, inp, end);
412 if (digits > 2 || day < DAY_MIN || day > days_per_month(month, year))
431 const char* p = str.
data();
432 return parse_std_impl(p, p + str.
size());
447 T&
format(T& out,
char delim=
'-')
const {
473 if (month > 0 && day > 0)
487 return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
496 static const int DAYS[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
497 assert( month >= MONTH_MIN && month <= MONTH_MAX );
498 if (month == 2 && leap_year)
500 return DAYS[month - 1];
509 return days_per_month(month, is_leap_year(year));
519 static const char* MONTHS[] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December" };
520 if (month < MONTH_MIN || month > MONTH_MAX)
522 return MONTHS[month - 1];
532 static const char* MONTHS[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
533 if (month < MONTH_MIN || month > MONTH_MAX)
535 return MONTHS[month - 1];
549 static ulong
calc_jdn(
int year,
int month,
int day) {
551 return (1461 * (year + 4800 + (month - 14) / 12)) / 4 +
552 (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 -
553 (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4 + day - 32075;
588 static const int HOUR_MIN = 0;
589 static const int HOUR_MAX = 23;
590 static const int MINUTE_MIN = 0;
591 static const int MINUTE_MAX = 59;
592 static const int SECOND_MIN = 0;
593 static const int SECOND_MAX = 60;
594 static const int MSECOND_MIN = 0;
595 static const int MSECOND_MAX = 999;
597 static const int HOURS_PER_DAY = 24;
598 static const int MIN_PER_HOUR = 60;
599 static const int MIN_PER_DAY = 1440;
600 static const int SEC_PER_MIN = 60;
601 static const int SEC_PER_HOUR = 3600;
602 static const int SEC_PER_DAY = 86400;
603 static const int MSEC_PER_SEC = 1000;
604 static const int MSEC_PER_MIN = 60000;
605 static const long MSEC_PER_HOUR = 3600000;
606 static const long MSEC_PER_DAY = 86400000;
615 { ::memset(
this, 0,
sizeof(
TimeOfDay)); }
623 TimeOfDay(
int hour,
int min=0,
int sec=0,
int msec=0) : hour(hour), minute(
min), second(sec), msecond(msec) {
630 { ::memcpy(
this, &src,
sizeof(
TimeOfDay)); }
637 { ::memcpy(
this, &src,
sizeof(
TimeOfDay));
return *
this; }
686 if (hour == oth.
hour) {
687 if (minute == oth.
minute) {
688 if (second == oth.
second) {
691 else if (msecond < oth.
msecond)
693 }
else if (second < oth.
second)
695 }
else if (minute < oth.
minute)
697 }
else if (hour < oth.
hour)
715 return ((
double)hour / HOURS_PER_DAY) +
716 ((double)minute / MIN_PER_DAY) +
717 ((double)second / SEC_PER_DAY);
726 return (hour / HOURS_PER_DAY);
740 int days = (hour / HOURS_PER_DAY);
741 result_hour = hour - (days * HOURS_PER_DAY);
742 if (result_hour < 0) {
744 result_hour += HOURS_PER_DAY;
753 bool validate(
bool allow_hour_overflow=
false)
const {
754 return (hour >= HOUR_MIN && (allow_hour_overflow || hour <= HOUR_MAX) &&
755 minute >= MINUTE_MIN && minute <= MINUTE_MAX &&
756 second >= SECOND_MIN && second <= SECOND_MAX &&
757 msecond >= MSECOND_MIN && msecond <= MSECOND_MAX);
762 { hour = minute = second = msecond = 0; }
773 bool set(
int new_hour,
int new_minute=0,
int new_second=0,
int new_msecond=0) {
774 if ( new_hour < HOUR_MIN || new_hour > HOUR_MAX ||
775 new_minute < MINUTE_MIN || new_minute > MINUTE_MAX ||
776 new_second < SECOND_MIN || new_second > SECOND_MAX ||
777 new_msecond < MSECOND_MIN || new_msecond > MSECOND_MAX )
782 msecond = new_msecond;
794 hour = (int)(tm * HOURS_PER_DAY);
795 tm -= (double)hour / HOURS_PER_DAY;
796 minute = (int)(tm * MIN_PER_DAY);
797 tm -= (double)minute / MIN_PER_DAY;
798 second = (int)(tm * SEC_PER_DAY);
804 int year, month, day;
810 int year, month, day;
822 int newhours = (minute / MIN_PER_HOUR);
824 minute -= (newhours * MIN_PER_HOUR);
827 minute += MIN_PER_HOUR;
841 long total_seconds = (minute * SEC_PER_MIN) + second + seconds;
842 int newhours = (total_seconds / SEC_PER_HOUR);
843 total_seconds -= (newhours * SEC_PER_HOUR);
846 minute = (total_seconds / SEC_PER_MIN);
847 total_seconds -= (minute * SEC_PER_MIN);
849 second = (int)total_seconds;
852 second += SEC_PER_MIN;
856 minute += MIN_PER_HOUR;
867 msecond += milliseconds;
868 int newseconds = (msecond / MSEC_PER_SEC);
869 msecond -= (newseconds * MSEC_PER_SEC);
872 msecond += MSEC_PER_SEC;
874 add_seconds(newseconds);
894 bool parse_std_impl(
const char*& inp,
const char* end,
bool allow_hour_overflow=
false) {
895 const double ROUND_MSEC = 0.001;
896 hour = minute = second = msecond = 0;
899 int digits = impl_time::parse_num(hour, inp, end);
907 if ( hour < HOUR_MIN || (hour > HOUR_MAX && !allow_hour_overflow) ||
908 minute < MINUTE_MIN || minute > MINUTE_MAX )
910 if (inp < end && (*inp ==
'.' || *inp ==
','))
918 if ( hour < HOUR_MIN || (hour > HOUR_MAX && !allow_hour_overflow) ||
919 minute < MINUTE_MIN || minute > MINUTE_MAX ||
920 second < SECOND_MIN || second > SECOND_MAX )
927 if (hour < HOUR_MIN || (hour > HOUR_MAX && !allow_hour_overflow))
932 if (*inp ==
'.' || *inp ==
',') {
934 double frac = impl_time::parse_frac(++inp, end);
935 frac *= MIN_PER_HOUR;
943 msecond = (int)((frac * MSEC_PER_SEC) + ROUND_MSEC);
951 digits = impl_time::parse_num(minute, inp, end);
959 if (minute < MINUTE_MIN || minute > MINUTE_MAX)
962 if (*inp ==
'.' || *inp ==
',') {
965 double frac = impl_time::parse_frac(++inp, end);
970 msecond = (int)((frac * MSEC_PER_SEC) + ROUND_MSEC);
978 digits = impl_time::parse_num(second, inp, end);
986 if (second < SECOND_MIN || second > SECOND_MAX)
990 if (*inp ==
'.' || *inp ==
',') {
992 msecond = (int)((impl_time::parse_frac(++inp, end) * MSEC_PER_SEC) + ROUND_MSEC);
1018 const char* p = str.
data();
1019 return parse_std_impl(p, p + str.
size(), allow_hour_overflow);
1030 T&
format(T& out,
char delim=
':',
char msdelim=0)
const {
1037 if (msecond > 0 && msdelim > 0)
1060 static const int OFFSET_MIN = -1439;
1061 static const int OFFSET_MAX = 1439;
1068 { minutes = OFFSET_NULL; }
1100 { minutes = src.
minutes;
return *
this; }
1107 {
return (minutes == oth.
minutes); }
1114 {
return (minutes != oth.
minutes); }
1121 {
return (minutes < oth.
minutes); }
1128 {
return (minutes <= oth.
minutes); }
1135 {
return (minutes > oth.
minutes); }
1142 {
return (minutes >= oth.
minutes); }
1149 {
return (minutes == oth.
minutes ? 0 : (minutes < oth.
minutes ? -1 : 1)); }
1155 {
return minutes == OFFSET_NULL; }
1161 {
return (minutes == OFFSET_NULL || (minutes >= OFFSET_MIN && minutes <= OFFSET_MAX)); }
1165 { minutes = OFFSET_NULL; }
1171 bool set(
int new_minutes) {
1172 if (new_minutes == OFFSET_NULL || (new_minutes >= OFFSET_MIN && new_minutes <= OFFSET_MAX)) {
1173 minutes = new_minutes;
1184 bool set(
int hours,
int hour_minutes) {
1224 minutes = OFFSET_NULL;
1241 if (*inp >=
'0' && *inp <=
'9')
1247 int digits = impl_time::parse_num(hours, ++inp, end);
1254 return (minutes >= OFFSET_MIN && minutes <= OFFSET_MAX);
1261 if (inp >= end || *inp !=
':') {
1268 int hour_minutes = 0;
1269 digits = impl_time::parse_num(hour_minutes, inp, end);
1291 const char* p = str.
data();
1292 return parse_std_impl(p, p + str.
size(), required);
1309 T&
format(T& out,
char delim=
':',
bool allow_z=
true)
const {
1310 if (minutes == OFFSET_NULL)
1312 if (allow_z && minutes == 0) {
1315 int hours = minutes / 60;
1316 int hour_minutes = minutes % 60;
1386 DateTime(
int year,
int month,
int day,
int hour=0,
int minute=0,
int second=0,
int msecond=0,
int tz_offset=OFFSET_NULL) :
1387 date(year, month, day), time(hour, minute, second, msecond), tz(tz_offset) {
1439 {
return (compare_op_helper(oth) == 0); }
1446 {
return (compare_op_helper(oth) != 0); }
1456 {
return (compare_op_helper(oth) < 0); }
1466 {
return (compare_op_helper(oth) <= 0); }
1476 {
return (compare_op_helper(oth) > 0); }
1486 {
return (compare_op_helper(oth) >= 0); }
1496 {
return compare_op_helper(oth); }
1539 bool set(
int year,
int month,
int day,
int hour=0,
int minute=0,
int second=0,
int msecond=0)
1540 {
return (date.
set(year, month, day) && time.
set(hour, minute, second, msecond)); }
1551 if (tm < JDN_MIN || !date.
set_jdn((ulong)tm))
1703 const char* p = str.
data();
1704 return parse_std_impl(p, p + str.
size());
1724 T&
format(T& out,
char dt_delim=
'T',
char d_delim=
'-',
char t_delim=
':',
char msec_delim=0,
char tz_delim=
':')
const {
1725 date.
format(out, d_delim);
1728 time.
format(out, t_delim, msec_delim);
1729 tz.
format(out, tz_delim);
1747 T&
format_std(T& out,
char dt_delim=
'T',
char msec_delim=0)
const 1748 {
return format(out, dt_delim,
'-',
':', msec_delim,
':'); }
1765 {
return format(out, dt_delim, 0, 0, msec_delim, 0); }
1768 int compare_op_helper(
const DateTime& oth)
const {
T & format_std(T &out, char dt_delim='T', char msec_delim=0) const
Format date and time to String or Stream using standard delimiters.
Definition: time.h:1747
double get_fraction() const
Get current time as a day fraction.
Definition: time.h:714
bool parse_std_impl(const char *&inp, const char *end)
Set date/time from parsing standard ISO 8601 based string.
Definition: time.h:1661
int msecond
Millisecond of second (0 - 999)
Definition: time.h:611
TimeZoneOffset & set_utc()
Set to UTC.
Definition: time.h:1196
bool add_milliseconds(int msec)
Add milliseconds to current date and time, subtract if negative.
Definition: time.h:1647
static const int MINUTE_MAX
Maximum minute value.
Definition: time.h:591
int minute
Minute of hour (0 - 59)
Definition: time.h:609
bool null() const
Get whether time zone offset is null (not set).
Definition: time.h:1154
bool operator==(const TimeZoneOffset &oth) const
Compare for equality with another time of day.
Definition: time.h:1106
bool operator==(const DateTime &oth) const
Compare for equality with another date and time.
Definition: time.h:1438
void set()
Set as null (no time zone).
Definition: time.h:1164
TimeZoneOffset(int minutes)
Constructor to initialize with a time zone offset in minutes.
Definition: time.h:1073
bool validate() const
Validate current date.
Definition: time.h:206
T & format_nodelim(T &out, char dt_delim='T', char msec_delim=0) const
Format date and time to String or Stream using standard delimiters.
Definition: time.h:1764
DateTime & operator=(const DateTime &src)
Assignment operator.
Definition: time.h:1427
T & format(T &out, char dt_delim='T', char d_delim='-', char t_delim=':', char msec_delim=0, char tz_delim=':') const
Format date and time to String or Stream using given delimiters.
Definition: time.h:1724
TimeZoneOffset(const TimeZoneOffset &src)
Copy constructor.
Definition: time.h:1092
bool operator>(const DateTime &oth) const
Compare whether greater than another date and time.
Definition: time.h:1475
bool operator>=(const Date &oth) const
Compare whether greater than or equal to another date.
Definition: time.h:166
double get_jdn_dt() const
Get Julian Day Number with time fraction.
Definition: time.h:1516
Evo system time implementation helpers.
bool add_days(int days)
Add days to current date, subtract if negative.
Definition: time.h:318
int compare(const DateTime &oth) const
Compare to another date and time.
Definition: time.h:1495
static const int MIN_PER_HOUR
Number of minutes per hour.
Definition: time.h:598
int compare(const TimeZoneOffset &oth) const
Compare to another time zone offset.
Definition: time.h:1148
DateTime()
Constructor.
Definition: time.h:1373
bool operator<(const Date &oth) const
Compare whether less than another date.
Definition: time.h:145
void set_local()
Set to current date in local time zone.
Definition: time.h:267
TimeZoneOffset & operator=(const TimeZoneOffset &src)
Assignment operator.
Definition: time.h:1099
bool operator<(const TimeOfDay &oth) const
Compare whether less than another time of day.
Definition: time.h:657
bool operator<(const TimeZoneOffset &oth) const
Compare whether less than another time of day.
Definition: time.h:1120
int hour
Hour of day (0 - 23)
Definition: time.h:608
bool set_jdn(ulong jdn)
Set date converted from Julian Day Number.
Definition: time.h:246
Date(int year, int month, int day)
Constructor to initialize with date.
Definition: time.h:111
int day
Day of month (1 - 31)
Definition: time.h:98
bool operator==(const TimeOfDay &oth) const
Compare for equality with another time of day.
Definition: time.h:643
static int days_per_month(int month, bool leap_year)
Helper to get number of days per given month.
Definition: time.h:495
DateTime & set_utc()
Set to current UTC date and time.
Definition: time.h:1560
static const T MIN
Minimum integer value.
Definition: type.h:995
static int days_per_month(int month, int year)
Helper to get number of days per given month in given year.
Definition: time.h:508
int year
4 digit year (1000 - 9999)
Definition: time.h:96
void set_utc()
Set to current UTC time of day.
Definition: time.h:803
T & format_yearday(T &out, char delim='-')
Format ordinal date to String or Stream.
Definition: time.h:469
bool parse(const SubString &str, bool allow_hour_overflow=false)
Set time of day from parsing standard time string.
Definition: time.h:1017
static const T MAX
Maximum interger value.
Definition: type.h:996
T & format(T &out, char delim=':', bool allow_z=true) const
Format timezone offset to String or Stream.
Definition: time.h:1309
bool add_years(int years)
Add years to current date, subtract if negative.
Definition: time.h:278
int compare(const Date &oth) const
Compare to another date.
Definition: time.h:173
ulong get_jdn() const
Get Julian Day Number for current date.
Definition: time.h:197
No base prefix (default)
Definition: str.h:2333
static const ulong JDN_MIN
Minimum Julian Day Number for Jan 1, 1000.
Definition: time.h:93
TimeZoneOffset tz
TimeZoneOffset fields.
Definition: time.h:1370
bool operator<=(const DateTime &oth) const
Compare whether less than or equal to another date and time.
Definition: time.h:1465
void add_seconds(int seconds)
Add seconds to current time, subtract if negative.
Definition: time.h:837
Size size() const
Get size.
void set_utc()
Set to current date in UTC.
Definition: time.h:261
bool add_minutes(int minutes)
Add minutes to current date and time, subtract if negative.
Definition: time.h:1629
Full calendar date and time of day with timezone offset.
Definition: time.h:1364
Structure holding a time zone offset from UTC.
Definition: time.h:1059
static bool is_leap_year(int year)
Helper to check whether given year is a leap year.
Definition: time.h:486
void set_local()
Set to current local time of day.
Definition: time.h:809
bool validate(T &val, T &min, T &max)
Definition: alg.h:79
Structure holding a time of day.
Definition: time.h:587
bool operator<(const DateTime &oth) const
Compare whether less than another date and time.
Definition: time.h:1455
bool add_months(int months)
Add months to current date, subtract if negative.
Definition: time.h:1602
TimeOfDay time
TimeOfDay fields.
Definition: time.h:1369
Base 10: decimal (default)
Definition: str.h:2323
FmtIntT< int > FmtInt
Explicitly format an integer.
Definition: str.h:3107
int get_days(int &result_hour) const
Get number of days and hours from current hour value.
Definition: time.h:739
bool operator<=(const Date &oth) const
Compare whether less than or equal to another date.
Definition: time.h:152
void set()
Set all fields to 0, which is a valid time (midnight).
Definition: time.h:761
TimeZoneOffset(int hours, int hour_minutes)
Constructor to initialize with a time zone offset from hours and minutes.
Definition: time.h:1082
bool parse(const SubString &str)
Set date from parsing standard date string (used internally).
Definition: time.h:430
T & format(T &out, char delim=':', char msdelim=0) const
Format time of day to String or Stream.
Definition: time.h:1030
bool validate(bool allow_hour_overflow=false) const
Validate current time of day.
Definition: time.h:753
bool validate() const
Validate current timezone offset.
Definition: time.h:1160
TimeOfDay(const TimeOfDay &src)
Copy constructor.
Definition: time.h:629
void add_minutes(int minutes)
Add minutes to current time, subtract if negative.
Definition: time.h:820
bool add_hours(int hours)
Add hours to current date and time, subtract if negative.
Definition: time.h:1620
bool validate() const
Validate current date, time, and timezone offset.
Definition: time.h:1501
bool parse_std_impl(const char *&inp, const char *end)
Set date from parsing standard date string (used internally).
Definition: time.h:338
void set_fraction(double tm, int msec=0)
Set time fields from day fraction.
Definition: time.h:793
Date & operator=(const Date &src)
Assignment operator.
Definition: time.h:124
bool operator==(const Date &oth) const
Compare for equality with another date.
Definition: time.h:131
bool operator>=(const TimeZoneOffset &oth) const
Compare whether greater than or equal to another time of day.
Definition: time.h:1141
bool operator!=(const Date &oth) const
Compare for inequality with another date.
Definition: time.h:138
int second
Second of minute (0 - 60), 60 is a special case for a leap second (rare)
Definition: time.h:610
DateTime(const Date &date, const TimeOfDay &time)
Date and TimeOfDay constructor.
Definition: time.h:1406
static const int HOURS_PER_DAY
Number of hours per day.
Definition: time.h:597
Date(const Date &src)
Copy constructor.
Definition: time.h:117
void add_milliseconds(int milliseconds)
Add milliseconds to current time, subtract if negative.
Definition: time.h:866
bool add_months(int months)
Add months to current date, subtract if negative.
Definition: time.h:294
bool set_jdn_dt(double tm, int msec=0)
Set new fields from Julian Day Number.
Definition: time.h:1550
Evo C++ Library namespace.
Definition: alg.h:11
DateTime & set_local_notz()
Set to current local date and time without time zone offset.
Definition: time.h:1581
bool operator!=(const TimeZoneOffset &oth) const
Compare for inequality with another time of day.
Definition: time.h:1113
int month
Month of year (1 - 12)
Definition: time.h:97
DateTime(const Date &date, const TimeOfDay &time, const TimeZoneOffset &tz)
Date and TimeOfDay constructor.
Definition: time.h:1414
Date()
Constructor.
Definition: time.h:101
DateTime(int year, int month, int day, int hour=0, int minute=0, int second=0, int msecond=0, int tz_offset=OFFSET_NULL)
Constructor.
Definition: time.h:1386
DateTime(const DateTime &src)
Copy constructor.
Definition: time.h:1393
static SubString month_name(int month)
Get name of given month.
Definition: time.h:518
bool operator>(const Date &oth) const
Compare whether greater than another date.
Definition: time.h:159
bool operator!=(const TimeOfDay &oth) const
Compare for inequality with another time of day.
Definition: time.h:650
bool add_years(int years)
Add years to current date, subtract if negative.
Definition: time.h:1593
bool operator>(const TimeZoneOffset &oth) const
Compare whether greater than another time of day.
Definition: time.h:1134
bool parse(const SubString &str)
Set date/time from parsing standard ISO 8601 based string.
Definition: time.h:1702
bool operator>(const TimeOfDay &oth) const
Compare whether greater than another time of day.
Definition: time.h:671
bool operator>=(const DateTime &oth) const
Compare whether greater than or equal to another date and time.
Definition: time.h:1485
static SubString month_name3(int month)
Get abbreviated name of given month.
Definition: time.h:531
bool operator!=(const DateTime &oth) const
Compare for inequality with another date and time.
Definition: time.h:1445
int get_days() const
Get number of days from current hour value.
Definition: time.h:725
bool operator<=(const TimeOfDay &oth) const
Compare whether less than or equal to another time of day.
Definition: time.h:664
static void get_wall_datetime_fields_utc(int &year, int &month, int &day, int &hour, int &minute, int &second, int &msecond)
Get fields for current real (wall clock) time for calendar date/time use (UTC).
Definition: systime.h:552
static const int OFFSET_NULL
Special value for null time zone (null is less than all other values), i.e. no assigned time zone...
Definition: time.h:1062
bool operator<=(const TimeZoneOffset &oth) const
Compare whether less than or equal to another time of day.
Definition: time.h:1127
bool parse_std_impl(const char *&inp, const char *end, bool allow_hour_overflow=false)
Set time of day from parsing standard time string (used internally).
Definition: time.h:894
static void get_wall_datetime_fields_local(int &year, int &month, int &day, int &hour, int &minute, int &second, int &msecond)
Get fields for current real (wall clock) time for calendar date/time use (Local Time).
Definition: systime.h:593
TimeOfDay & operator=(const TimeOfDay &src)
Assignment operator.
Definition: time.h:636
bool parse_std_impl(const char *&inp, const char *end, bool required=false)
Set timezone offset from parsing standard timezone offset string (used internally).
Definition: time.h:1223
static ulong calc_jdn(int year, int month, int day)
Calculate Julian Day Number from date fields.
Definition: time.h:549
DateTime & set_local()
Set to current local date and time with time zone offset.
Definition: time.h:1571
bool add_seconds(int seconds)
Add seconds to current date and time, subtract if negative.
Definition: time.h:1638
bool operator>=(const TimeOfDay &oth) const
Compare whether greater than or equal to another time of day.
Definition: time.h:678
TimeZoneOffset()
Constructor to set as null (no time zone).
Definition: time.h:1067
FmtIntT< ulong > FmtULong
Explicitly format an integer.
Definition: str.h:3117
TimeOfDay(int hour, int min=0, int sec=0, int msec=0)
Constructor to initialize with time of day.
Definition: time.h:623
DateTime(const TimeZoneOffset &tz)
Timezone offset constructor.
Definition: time.h:1420
int minutes
Time zone offset from UTC in minutes (-720 - 840), OFFSET_NULL for null, negative for the Western Hem...
Definition: time.h:1064
Reference and access existing string data.
Definition: substring.h:229
TimeZoneOffset & set_local()
Set to current time zone offset.
Definition: time.h:1204
DateTime(const Date &date)
Date constructor.
Definition: time.h:1399
TimeOfDay()
Constructor.
Definition: time.h:614
T & min(T &a, T &b)
Returns lowest of given values.
Definition: alg.h:26
void set()
Set all fields to 0, which is not a valid date.
Definition: time.h:213
Date date
Date fields.
Definition: time.h:1368
Structure holding a calendar date.
Definition: time.h:86
int compare(const TimeOfDay &oth) const
Compare to another time of day.
Definition: time.h:685
static int tz_get_offset()
Get current time zone (local time) offset from UTC in minutes.
Definition: systime.h:691
const char * data() const
Get data pointer.
T & format(T &out, char delim='-') const
Format date to String or Stream.
Definition: time.h:447
bool parse(const SubString &str, bool required=false)
Set timezone offset from parsing standard timezone offset string.
Definition: time.h:1290
bool add_days(int days)
Add days to current date, subtract if negative.
Definition: time.h:1611