40 #if defined(NCBI_OS_MSWIN)
42 #elif defined(NCBI_OS_UNIX)
43 # include <sys/time.h>
49 #if defined(__CYGWIN__) || defined(NCBI_COMPILER_MSVC)
50 # define TimeZone() _timezone
51 # define Daylight() _daylight
52 # define TZName() _tzname
54 # define TimeZone() timezone
55 # define Daylight() daylight
56 # define TZName() tzname
60 #if defined(NCBI_OS_DARWIN) || defined(NCBI_OS_BSD)
61 # define NCBI_TIMEZONE_IS_UNDEFINED 1
66 #if defined(NCBI_COMPILER_MSVC)
67 # define DSTBias() _dstbias
69 # define DSTBias() -3600
73 #define NCBI_USE_ERRCODE_X Corelib_Util
97 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
102 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
103 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
106 "January",
"February",
"March",
"April",
"May",
"June",
107 "July",
"August",
"September",
"October",
"November",
"December"
112 "Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
115 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
116 "Thursday",
"Friday",
"Saturday"
141 #define CHECK_RANGE_EXCEPTION(value, what, min, max) \
142 if ( value < min || value > max ) { \
143 NCBI_THROW(CTimeException, eArgument, \
145 NStr::Int8ToString((Int8)value) + "' is out of range"); \
148 #define CHECK_RANGE2(value, what, min, max, err_action) \
149 if ( value < min || value > max ) { \
150 if ( err_action == eErr_Throw ) { \
151 NCBI_THROW(CTimeException, eArgument, \
153 NStr::Int8ToString((Int8)value) + "' is out of range"); \
154 } else { return false; } \
157 #define CHECK_RANGE_YEAR(value) CHECK_RANGE_EXCEPTION(value, "Year", 1583, kMax_Int)
158 #define CHECK_RANGE_MONTH(value) CHECK_RANGE_EXCEPTION(value, "Month", 1, 12)
159 #define CHECK_RANGE_DAY(value) CHECK_RANGE_EXCEPTION(value, "Day", 1, 31)
160 #define CHECK_RANGE_HOUR(value) CHECK_RANGE_EXCEPTION(value, "Hour", 0, 23)
161 #define CHECK_RANGE_MIN(value) CHECK_RANGE_EXCEPTION(value, "Minute", 0, 59)
162 #define CHECK_RANGE_SEC(value) CHECK_RANGE_EXCEPTION(value, "Second", 0, 61)
163 #define CHECK_RANGE_NSEC(value) CHECK_RANGE_EXCEPTION(value, "Nanosecond", 0, kNanoSecondsPerSecond - 1)
165 #define CHECK_RANGE2_YEAR(value, err) CHECK_RANGE2(value, "Year", 1583, kMax_Int, err)
166 #define CHECK_RANGE2_MONTH(value, err) CHECK_RANGE2(value, "Month", 1, 12, err)
167 #define CHECK_RANGE2_DAY(value, err) CHECK_RANGE2(value, "Day", 1, 31, err)
168 #define CHECK_RANGE2_HOUR24(value, err) CHECK_RANGE2(value, "Hour", 0, 23, err)
169 #define CHECK_RANGE2_HOUR12(value, err) CHECK_RANGE2(value, "Hour", 0, 12, err)
170 #define CHECK_RANGE2_MIN(value, err) CHECK_RANGE2(value, "Minute", 0, 59, err)
171 #define CHECK_RANGE2_SEC(value, err) CHECK_RANGE2(value, "Second", 0, 61, err)
172 #define CHECK_RANGE2_NSEC(value, err) CHECK_RANGE2(value, "Nanosecond", 0, kNanoSecondsPerSecond - 1, err)
176 #define SET_YEAR(value) m_Data.year = static_cast<unsigned int>((value) & 0xFFF)
177 #define SET_MONTH(value) m_Data.month = static_cast<unsigned char>((value) & 0x0F)
178 #define SET_DAY(value) m_Data.day = static_cast<unsigned char>((value) & 0x1F)
179 #define SET_HOUR(value) m_Data.hour = static_cast<unsigned char>((value) & 0x1F)
180 #define SET_MIN(value) m_Data.min = static_cast<unsigned char>((value) & 0x3F)
181 #define SET_SEC(value) m_Data.sec = static_cast<unsigned char>((value) & 0x3F)
193 unsigned d = date.
Day();
194 unsigned m = date.
Month();
195 unsigned y = date.
Year();
207 return ((146097 * c) >> 2) + ((1461 * ya) >> 2) +
208 (153 * m + 2) / 5 + d + 1721119;
217 unsigned j = num - 1721119;
222 year = (((j<<2) - 1) / 146097);
223 j = (j<<2) - 1 - 146097 * year;
225 j = ((d<<2) + 3) / 1461;
226 d = (d<<2) + 3 - 1461 * j;
228 month = (5*d - 3) / 153;
229 d = 5*d - 3 - 153 * month;
231 year = 100 * year + j;
241 CTime(year, month, day,
t.Hour(),
t.Minute(),
t.Second(),
242 t.NanoSecond(),
t.GetTimeZone(),
t.GetTimeZonePrecision());
270 buf[--pos] = char((
value % 10) +
'0');
285 const size_t size = 9;
291 buf[--pos] = char((
value % 10) +
'0');
299 if (ignore_trailing_zeros) {
300 for (;
len > 1 && p[
len-1] ==
'0'; --
len) {}
358 "Incompatible flags specified together: fFormat_Simple | fFormat_Ncbi");
366 "Incompatible flags specified together: fMatch_Strict | fMatch_Weak");
379 if ( &fmt ==
this ) {
391 static const char* s_Predefined[][2] =
395 {
"Y-M-D",
"$Y-$M-$D"},
396 {
"Y-M-DTh:m",
"$Y-$M-$DT$h:$m"},
397 {
"Y-M-DTh:m:s",
"$Y-$M-$DT$h:$m:$s"},
398 {
"Y-M-DTh:m:G",
"$Y-$M-$DT$h:$m:$G"},
443 t.AddDay(yearDayNumber - 1);
451 #define X_INIT_ERROR(type, msg) \
452 if (err_action == eErr_Throw) { \
453 NCBI_THROW(CTimeException, type, msg); \
459 #define SKIP_SPACES(s) \
460 while (isspace((unsigned char)(*s))) ++s;
472 bool str(
const char*& s) {
475 if (*s !=
':')
return false;
522 bool is_year_present =
false;
523 bool is_month_present =
false;
524 bool is_day_present =
false;
525 bool is_time_present =
false;
527 const string& fmt =
format.GetString();
529 bool is_escaped_symbol =
false;
532 const char* sss =
str.c_str();
533 bool adjust_needed =
false;
539 EHourFormat hour_format = e24;
541 bool is_12hour =
false;
545 bool is_format_space =
false;
548 for (fff = fmt.c_str(); *fff !=
'\0'; ++fff) {
552 if (!is_escaped_symbol) {
554 if (
isspace((
unsigned char)(*fff))) {
555 is_format_space =
true;
558 if (is_ignore_spaces) {
563 if (
isspace((
unsigned char)(*sss))) {
564 if (is_format_space) {
571 if (is_format_space) {
575 is_format_space =
false;
580 if (is_escaped_fmt && !is_escaped_symbol) {
582 is_escaped_symbol =
true;
589 if (is_escaped_fmt) {
599 is_escaped_symbol =
false;
616 if (*fff ==
'b' || *fff ==
'B') {
623 for (
unsigned char i = 0;
i < 12; ++
i) {
624 size_t namelen = strlen(*name);
632 is_month_present =
true;
637 if (*fff ==
'w' || *fff ==
'W') {
639 for (
unsigned char i = 0;
i < 7; ++
i) {
640 size_t len = strlen(*day);
657 sss += ((*sss ==
'Z') ? 1 : 3);
665 if (*fff ==
'z' || tz_fmt_check.
fmt(fff)) {
672 int sign = (*sss ==
'+') ? 1 : ((*sss ==
'-') ? -1 : 0);
684 len && *sss &&
isdigit((
unsigned char)(*sss));
696 if ( *sss !=
'\0' ) {
697 if (!tz_fmt_check.
str(sss)) {
702 len && *sss &&
isdigit((
unsigned char)(*sss));
714 adjust_needed =
true;
715 adjust_tz = sign * (x_hour * 60 + x_min) * 60;
720 if (*fff ==
'p' || *fff ==
'P') {
736 case 'Y':
len = 4;
break;
737 case 'S':
len = 9;
break;
738 case 'l':
len = 3;
break;
739 case 'r':
len = 6;
break;
741 for ( ;
len && *sss &&
isdigit((
unsigned char)(*sss)); --
len) {
752 is_year_present =
true;
762 is_year_present =
true;
767 is_month_present =
true;
773 is_day_present =
true;
778 is_time_present =
true;
784 is_time_present =
true;
789 is_time_present =
true;
794 is_time_present =
true;
799 is_time_present =
true;
804 is_time_present =
true;
809 is_time_present =
true;
821 n && *sss &&
isdigit((
unsigned char)(*sss)); --
n) {
826 size_t n = strlen(value_str);
835 while (
isdigit((
unsigned char)(*sss)) ) {
839 is_time_present =
true;
843 X_INIT_ERROR(eFormat,
"Format '" + fmt +
"' has incorrect format symbol '" + *fff +
"'");
848 if (is_12hour && hour_format == ePM) {
853 if (is_ignore_spaces) {
856 if (
isspace((
unsigned char)(*sss)) && is_format_space) {
865 "' is too short for time format '" + fmt +
"'");
870 "' is too long for time format '" + fmt +
"'");
872 if (*fff !=
'\0' && *sss !=
'\0' &&
875 "' does not match time format '" + fmt +
"'");
880 ptcache += (is_year_present ? 2000 : 1000);
881 ptcache += (is_month_present ? 200 : 100);
882 ptcache += (is_day_present ? 20 : 10);
883 ptcache += (is_time_present ? 2 : 1);
887 if ( !adjust_needed ) {
927 if (weekday != -1 && weekday !=
DayOfWeek()) {
932 X_INIT_ERROR(eConvert,
"Unable to convert string '" +
str +
"' to CTime");
935 if ( adjust_needed ) {
952 int minute,
int second,
long nanosecond,
1050 "Unable to set year number '" +
1067 "Unable to set month number '" +
1077 if ( day > n_days ) {
1085 "Unable to set day number '" +
1149 "Day of week with value " +
1158 wday -= first_day_of_week;
1166 week_num = yday / 7;
1167 if ( (yday % 7) >= wday ) {
1172 return week_num + 1;
1179 int week_num_first = first_of_month.
YearWeekNumber(first_day_of_week);
1181 return week_num_current - week_num_first + 1;
1194 return (y + y/4 - y/100 + y/400 +
"-bed=pen+mad."[m] +
Day()) % 7;
1205 n_days =
IsLeap() ? 29 : 28;
1214 for (
int i = 0;
i < 12; ++
i) {
1223 "Invalid month name '" + month +
"'");
1231 if (month < 1 || month > 12) {
1243 for (
int i = 0;
i <= 6; ++
i) {
1252 "Invalid day of week name '" + day +
"'");
1260 if (day < 0 || day > 6) {
1295 #if defined(HAVE_TIMEGM) || defined(NCBI_OS_DARWIN)
1296 t.tm_sec =
ct.Second();
1301 t.tm_min =
ct.Minute();
1302 t.tm_hour =
ct.Hour();
1303 t.tm_mday =
ct.Day();
1304 t.tm_mon =
ct.Month()-1;
1305 t.tm_year =
ct.Year()-1900;
1307 #if defined(NCBI_OS_DARWIN)
1308 time_t tt = mktime(&
t);
1309 if ( tt == (time_t)(-1L) ) {
1312 return ct.IsUniversalTime() ? tt+
t.tm_gmtoff : tt;
1313 #elif defined(HAVE_TIMEGM)
1314 return ct.IsUniversalTime() ? timegm(&
t) : mktime(&
t);
1319 if ( timer == (time_t)(-1L) ) {
1324 if (
ct.IsUniversalTime() ) {
1334 t.tm_min =
ct.Minute();
1335 t.tm_hour =
ct.Hour();
1336 t.tm_mday =
ct.Day();
1337 t.tm_mon =
ct.Month()-1;
1338 t.tm_year =
ct.Year()-1900;
1341 if ( timer == (time_t)(-1L) ) {
1345 # if defined(HAVE_LOCALTIME_R)
1347 localtime_r(&timer, &temp);
1350 ttemp = localtime(&timer);
1353 return (time_t)(-1L);
1354 if (ttemp->tm_isdst > 0 &&
Daylight())
1366 if (timer == (time_t)(-1L)) {
1370 # if defined(HAVE_LOCALTIME_R)
1372 localtime_r(&timer, &temp);
1375 t = localtime(&timer);
1380 return (
t->tm_isdst > 0);
1410 t.tm_sec =
lt.Second();
1411 t.tm_min =
lt.Minute();
1412 t.tm_hour =
lt.Hour();
1413 t.tm_mday =
lt.Day();
1414 t.tm_mon =
lt.Month()-1;
1415 t.tm_year =
lt.Year()-1900;
1416 t.tm_wday =
lt.DayOfWeek();
1474 dbt.
time = (
Int4)((
t.Hour() * 3600 +
t.Minute() * 60 +
t.Second()) * 300 +
1525 if (
format.IsEmpty() ) {
1527 fmt =
f.GetString();
1528 fmt_flags =
f.GetFlags();
1530 fmt =
format.GetString();
1531 fmt_flags =
format.GetFlags();
1534 bool is_format_symbol = !is_escaped;
1543 #if defined(NCBI_TIMEZONE_IS_UNDEFINED)
1545 ERR_POST_X(4,
"Output timezone is unsupported on this platform");
1549 TSeconds x_timezone = 0, x_dstbias = 0;
1550 bool x_isdst =
false;
1560 t_out =
new CTime(*
this);
1578 if ( !is_format_symbol ) {
1580 is_format_symbol =
true;
1587 is_format_symbol =
false;
1615 case 'p':
str += (
t->Hour() < 12) ?
"am" :
"pm" ;
break;
1616 case 'P':
str += (
t->Hour() < 12) ?
"AM" :
"PM" ;
break;
1619 #if defined(NCBI_TIMEZONE_IS_UNDEFINED)
1620 ERR_POST_X(5,
"Format symbol 'z' is unsupported "
1621 "on this platform");
1623 if (!tz_fmt_make.
active()) {
1636 str += (tz > 0) ?
'-' :
'+';
1637 if (tz < 0) tz = -tz;
1651 default :
str += *it;
break;
1675 #if defined(NCBI_OS_MSWIN)
1679 GetSystemTimeAsFileTime(&systime);
1681 systemp = systime.dwHighDateTime;
1683 systemp |= systime.dwLowDateTime;
1685 ns = (systemp % 10000000) * 100;
1686 #elif defined(NCBI_OS_UNIX)
1688 if (gettimeofday(&tp,0) == 0) {
1692 *sec = (time_t)(-1L);
1699 if (*sec == (time_t)(-1L)) {
1701 "Unable to get time value");
1724 #ifdef HAVE_LOCALTIME_R
1727 localtime_r(&timer, &temp);
1729 gmtime_r(&timer, &temp);
1737 "localtime/gmtime error, possible incorrect time_t value");
1767 pt =
new CTime(*
this);
1773 long newMonth =
Month() - 1;
1774 int newYear =
Year();
1798 pt =
new CTime(*
this);
1830 pt =
new CTime(*
this);
1837 long newHour =
Hour();
1838 s_Offset(&newHour, hours, 24, &dayOffset);
1860 pt =
new CTime(*
this);
1867 long newMinute =
Minute();
1868 s_Offset(&newMinute, minutes, 60, &hourOffset);
1887 int minuteOffset = 0;
1888 long newSecond =
Second();
1889 s_Offset(&newSecond, seconds, 60, &minuteOffset);
1903 int secondOffset = 0;
1948 / 1000000 * 1000000;
1957 "Rounding precision is out of range");
2056 return t.ToLocalTime();
2069 return t.ToUniversalTime();
2082 if (timer == (time_t)(-1L)) {
2088 #if defined(HAVE_LOCALTIME_R)
2091 localtime_r(&timer, &temp);
2094 gmtime_r(&timer, &temp);
2098 t = (tz ==
eLocal) ? localtime(&timer) : gmtime(&timer);
2102 "localtime/gmtime error, possible incorrect time_t value");
2122 if ( !
tmp.IsEmptyDate() ) {
2139 if ( !
tmp.IsEmptyDate() ) {
2176 if ( !
tmp.IsEmptyDate() ) {
2213 return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
2226 return ((dDays * 24 + dHours) * 60 + dMins) * 60 + dSecs;
2250 if (timer == (time_t)(-1L)) {
2257 #if defined(HAVE_LOCALTIME_R)
2259 localtime_r(&timer, &temp);
2262 t = localtime(&timer);
2267 #if defined(__USE_BSD)
2283 const CTime* p1, *p2;
2300 return ((dDays * 24 + dHours) * 60 + dMins) * 60 + dSecs;
2307 if (sec < kMin_Long || sec > kMax_Long) {
2309 "Difference in time " +
2311 " is too big to convert to CTimeSpan");
2319 if (seconds < (
double)kMin_Long || seconds > (
double)kMax_Long) {
2322 " is too big to convert to CTimeSpan");
2324 m_Sec = long(seconds);
2333 if (
Day() > n_days) {
2369 const int kShiftHours = 4;
2380 sign = ( *
this > from ) ? 1 : -1;
2398 CTime tn(
t + (time_t)diff + 3600 * kShiftHours * sign);
2431 if (sec < kMin_Long || seconds > kMax_Long) {
2438 ", nanosec) is too big to convert to CTimeSpan");
2482 if (
str.empty() ) {
2485 const string& fmt =
format.GetString();
2487 bool is_escaped_symbol =
false;
2491 const char* sss =
str.c_str();
2494 for (fff = fmt.c_str(); *fff !=
'\0'; ++fff) {
2497 if (is_escaped_fmt && !is_escaped_symbol) {
2499 is_escaped_symbol =
true;
2506 if (is_escaped_fmt) {
2516 is_escaped_symbol =
false;
2546 char* s = value_str;
2548 size_t len = (
f ==
'\1') ? 9 : 10;
2549 for (;
len && *sss &&
isdigit((
unsigned char)(*sss)); --
len) {
2582 if ( *sss ==
'.' ) {
2586 goto read_next_value;
2591 if ( *sss ==
'.' ) {
2595 goto read_next_value;
2603 size_t n = strlen(value_str);
2606 for (;
n < 9; ++
n) {
2612 while (
isdigit((
unsigned char)(*sss)) ) {
2626 "Time string '" +
str +
2627 "' is too short for time format '" + fmt +
"'");
2632 "Time string '" +
str +
2633 "' is too long for time format '" + fmt +
"'");
2651 }
else if (m_Sec < 0 && m_NanoSec > 0) {
2687 if (
format.IsEmpty() ) {
2689 fmt =
f.GetString();
2690 fmt_flags =
f.GetFlags();
2692 fmt =
format.GetString();
2693 fmt_flags =
format.GetFlags();
2696 bool is_format_symbol = !is_escaped;
2700 if ( !is_format_symbol ) {
2702 is_format_symbol =
true;
2709 is_format_symbol =
false;
2740 default :
str += *it;
2780 {
"millisecond",
"ms" },
2781 {
"microsecond",
"us" },
2782 {
"nanosecond",
"ns" }
2819 for (adjust_level =
eYear; adjust_level <
eSecond; adjust_level++) {
2828 switch (
EUnit(adjust_level) ) {
2850 const int max_count = 6;
2851 long span[max_count];
2856 span[
eDay] = sec/(3600L*24); sec %= (3600L*24);
2857 span[
eHour] = sec/3600L; sec %= 3600L;
2858 span[
eMinute] = sec/60L; sec %= 60L;
2866 for (; start < 5; ++start) {
2867 if ( span[start] ) {
2879 while (start <= prec) {
2880 long val = span[start];
2917 int milli =
int(nanoseconds / 1000000);
2918 int micro =
int(nanoseconds / 1000 % 1000);
2919 int nano =
int(nanoseconds % 1000);
2930 }
else if ( milli ) {
2934 }
else if ( micro ) {
2938 }
else if ( nano ) {
2948 bool plural = (v1 != 1);
2956 }
else if (
len == 2) {
2974 unit =
EUnit(unit-1);
2985 if (
v2 &&
len < 3) {
3032 if ( !is_named_precision ) {
3036 for (adjust_level =
eYear; adjust_level <=
eSecond; adjust_level++) {
3042 if (adjust_level <=
eSecond) {
3058 switch (
EUnit(adjust_level) ) {
3095 SItem(
long v,
EUnit u) :
value(v), unit(u) {};
3099 const int max_count = 7;
3100 SItem span[max_count];
3104 span[2] = SItem(sec/(3600L*24),
eDay ); sec %= (3600L*24);
3105 span[3] = SItem(sec/3600L,
eHour ); sec %= 3600L;
3106 span[4] = SItem(sec/60L,
eMinute); sec %= 60L;
3107 span[5] = SItem(sec,
eSecond);
3130 for (
int i = 0;
i < max_count && start <=
precision; ++
i) {
3131 long val = span[
i].value;
3139 if ( is_named_precision ) {
3151 j < max_count && (cp <=
precision); ++j, ++cp) {
3152 sum += span[j].value;
3193 "Negative CTimeSpan cannot be converted to smart string");
3207 const string kMsg =
"Incompatible flags specified together: ";
3213 if ( !(
f && !(
f & (
f-1))) ) {
3265 if (
str.empty() ) {
3269 const char* sss =
str.c_str();
3270 bool numeric_expected =
true;
3273 size_t frac_len = 0;
3276 memset(repetitions, 0,
kUnitCount *
sizeof(repetitions[0]));
3278 for (; *sss !=
'\0'; ++sss) {
3281 if (
isspace((
unsigned char)(*sss))) {
3286 if (numeric_expected) {
3288 value = 0; frac = 0;
3290 if (
isdigit((
unsigned char)(*sss))) {
3292 const char* start = sss++;
3293 while (*sss &&
isdigit((
unsigned char)(*sss))) ++sss;
3294 size_t n = sss - start;
3297 "Too long numeric value '" +
string(start,
n) +
3298 "': string '" +
str +
"' (pos = " +
3311 if (*sss &&
isdigit((
unsigned char)(*sss))) {
3312 const char* start = sss++;
3313 while (*sss &&
isdigit((
unsigned char)(*sss))) ++sss;
3314 frac_len = sss - start;
3317 "Too long fractional part '" +
string(start, frac_len) +
3318 "': string '" +
str +
"' (pos = " +
3326 numeric_expected =
false;
3332 if (!
isalpha((
unsigned char)(*sss))) {
3335 const char* start = sss++;
3336 while (*sss &&
isalpha((
unsigned char)(*sss))) ++sss;
3337 size_t n = sss - start;
3339 string spec(start,
n);
3352 "Unknown time specifier '" + spec +
"': string '" +
str +
3384 unsigned int div = 10;
3386 while (--frac_len) div *= 10;
3398 if (((
TSeconds)frac * 10 / div) >=5 ) {
3408 if (repetitions[
i]) {
3410 "Time component for '" +
string(
kUnitNames[
i].name_full) +
3411 "s' already exists: string '" +
str +
3414 repetitions[
i] =
true;
3423 if ( sec <= kMin_Long || sec >= kMax_Long ||
3424 ns <= kMin_Long || ns >= kMax_Long) {
3426 "Value is too big to convert to CTimeSpan: string '" +
str +
3431 numeric_expected =
true;
3436 if (!numeric_expected) {
3438 "Time specifier expected: string '" +
str +
3443 "Unexpected symbol: string '" +
str +
3480 "IsZero() cannot be used with " +
3493 "Cannot convert from " +
3496 #if (SIZEOF_INT == SIZEOF_LONG)
3503 " too big to convert to unsigned long");
3515 "Cannot convert from " +
3526 "Cannot convert from " +
3529 #if (SIZEOF_INT == SIZEOF_LONG)
3530 if (
m_Sec > (
unsigned int) kMax_Long ) {
3534 " too big to convert to CTimeSpan");
3548 "Cannot convert from " +
3564 "Cannot convert from " +
3615 "Cannot set negative value " +
3633 "Cannot convert from negative CTimeSpan(" +
3638 "CTimeSpan value (" +
3650 #define COMPARE_TIMEOUT_TYPES(t1, t2) ((int(t1) << 2) | int(t2))
3665 "Unable to compare with " +
3683 "Unable to compare with " +
3701 "Unable to compare with " +
3724 "Unable to compare with " +
3747 "Unable to compare with " +
3761 : m_Seconds(0), m_Nanoseconds(0), m_Infinite(
false)
3764 if (seconds || nanoseconds) {
3771 : m_Seconds(0), m_Nanoseconds(0), m_Infinite(
false)
3776 else if (timeout.
IsZero()) {
3780 unsigned int sec, usec;
3781 timeout.
Get(&sec, &usec);
3791 : m_Seconds(0), m_Nanoseconds(0), m_Infinite(
type == eInfinite)
3798 #if defined(NCBI_OS_MSWIN)
3802 GetSystemTimeAsFileTime(&systime);
3804 systemp = systime.dwHighDateTime;
3806 systemp |= systime.dwLowDateTime;
3811 struct timespec timebuffer;
3812 if (clock_gettime(CLOCK_REALTIME, &timebuffer) == 0) {
3817 "Cannot get current deadline time value");
3821 if (gettimeofday(&tp, 0) == 0) {
3827 "Cannot get current deadline time value");
3832 if (seconds || nanoseconds) {
3845 "Cannot convert from " +
3862 "Cannot convert from " +
3883 if (thenS < nowS || (thenS == nowS && thenNS <= nowNS)) {
3886 if (thenNS >= nowNS) {
3909 "Cannot compare two " +
3911 " deadline values");
3925 : m_SecAfterHour(sec_after_hour),
3926 m_LastTuneupTime(0), m_LastSysTime(0),
3927 m_Timezone(0), m_IsTuneup(
NULL)
3929 #if !defined(NCBI_TIMEZONE_IS_UNDEFINED)
3967 #if !defined(NCBI_TIMEZONE_IS_UNDEFINED)
4000 #if !defined(NCBI_TIMEZONE_IS_UNDEFINED)
4014 #
if !defined(NCBI_TIMEZONE_IS_UNDEFINED)
4024 LOCK.
Guard(s_FastLocalTimeMutex);
4044 #if !defined(NCBI_TIMEZONE_IS_UNDEFINED)
4096 #if defined(NCBI_OS_MSWIN)
4099 LARGE_INTEGER bigint;
4101 static bool first =
true;
4104 LARGE_INTEGER nfreq;
4105 QueryPerformanceFrequency(&nfreq);
4106 freq = double(nfreq.QuadPart);
4110 if ( !QueryPerformanceCounter(&bigint) ) {
4113 return double(bigint.QuadPart) / freq;
4117 struct timeval time;
4118 if ( gettimeofday (&time, 0) ) {
4121 return double(time.tv_sec) + double(time.tv_usec) / 1e6;
4183 case eFormat:
return "eFormat";
void Guard(resource_type &resource)
Manually force the guard to protect some other resource.
void Release()
Manually force the resource to be released.
CNanoTimeout – Timeout interval, using nanoseconds.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
CTimeout – Timeout interval.
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
std::ofstream out("events_result.xml")
main entry point for tests
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
@ eNegative
Value is negative.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
TErrCode GetErrCode(void) const
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
int32_t Int4
4-byte (32-bit) signed integer
uint16_t Uint2
2-byte (16-bit) unsigned integer
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
static string DoubleToString(double value, int precision=-1, TNumToStringFlags flags=0)
Convert double to string.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
static string LongToString(long value, TNumToStringFlags flags=0, int base=10)
Convert Int to string.
static int strncasecmp(const char *s1, const char *s2, size_t n)
Case-insensitive comparison of two zero-terminated strings, narrowed to the specified number of chara...
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static unsigned long StringToULong(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned long.
static long StringToLong(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to long.
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string & ToLower(string &str)
Convert string to lower case – string& version.
@ fAllowTrailingSymbols
Ignore trailing non-numerics characters.
#define NCBI_SCHED_YIELD()
Int8 TSeconds
Number of seconds.
unsigned int TFlags
Binary OR of "EFlags".
CFastLocalTime(unsigned int sec_after_hour=5)
Constructor.
bool x_Init(const string &str, const CTimeFormat &fmt, EErrAction err_action=eErr_Throw)
Helper method to set time value from string "str" using format "fmt".
double m_Total
Accumulated elapsed time.
int Minute(void) const
Get minute.
static string DayOfWeekNumToName(int day, ENameFormat format=eFull)
Get name of the day of week by numerical value.
CTime & Truncate(ERoundPrecision precision=eRound_Day)
Truncate time.
string TimeZoneOffsetStr(void)
Get time zone offset string in format [+/-]HHMM.
int x_Second(void) const
Get second.
void SetMinute(int minute)
Set minute.
ETimeZonePrecision GetTimeZonePrecision(void) const
Get time zone precision.
CTime & ToLocalTime(void)
Convert the time into local time.
CTime(EInitMode mode=eEmpty, ETimeZone tz=eLocal, ETimeZonePrecision tzp=eTZPrecisionDefault)
Constructor.
TSeconds TimeZoneOffset(void) const
Get difference between local timezone for current time object and UTC in seconds.
void SetMonth(int month)
Set month.
EInitMode
Which initial value to use for time.
unsigned int TSmartStringFlags
Binary OR of "ESmartStringFlags".
CTimeSpan & operator=(const CTimeSpan &t)
Assignment operator.
void SetSecond(int second)
Set second.
EDayOfWeek
Day of week names.
int DayOfWeek(void) const
Get day of week.
CNanoTimeout GetRemainingTime(void) const
Get time left to the expiration.
Int4 days
days from 1/1/1900
static void SetFormat(const CTimeFormat &fmt)
Set the current time format.
CTime & AddTimeSpan(const CTimeSpan ×pan)
Add specified time span.
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
CDeadline(unsigned int rel_seconds, unsigned int rel_nanoseconds=0)
Initialize deadline using seconds and nanoseconds (adding to the current time)
static void SetFormat(const CTimeFormat &format)
Set the current time span format.
EErrAction
Defines how to behave on error.
CTime & x_AddHour(int hours=1, EDaylight daylight=eDaylightDefault, bool shift_time=true)
Helper method to add hour with/without shift time.
void SetMicroSecond(long microsecond)
Set microseconds.
TData m_Data
Packed members.
bool operator>(const CTime &t) const
Operator to test if time is later.
bool IsUniversalTime(void) const
Is time universal (GMT/UTC/Z)?
ETimeZone
Which initial value to use for timezone.
CTime & SetTimeDBI(const TDBTimeI &t)
Set time using database format time, TDBTimeI.
CTime & AddNanoSecond(long nanoseconds=1)
Add specified nanoseconds.
void SetFormat(const char *fmt, TFlags flags=fDefault)
Set the current time format.
CTime & Round(ERoundPrecision precision=eRound_Day, EDaylight adl=eDaylightDefault)
Round time.
long GetCompleteMinutes(void) const
Get number of complete minutes.
bool x_Tuneup(time_t timer, long nanosec)
Internal version of Tuneup()
CTimeSpan GetAsTimeSpan(void) const
Convert to CTimeSpan.
void x_Normalize(void)
Helper method to normalize stored time value.
CTime & AddSecond(TSeconds seconds=1, EDaylight adl=eDaylightDefault)
Add specified seconds.
long GetCompleteDays(void) const
Get number of complete days.
ETimeZone GetTimeZone(void) const
Get time zone.
int m_Timezone
Cached timezone adjustment for local time.
bool x_NeedAdjustTime(void) const
Helper method to check if there is a need adjust time in timezone.
long GetNanoSecondsAfterSecond(void) const
Get number of nanoseconds.
CTime & x_AdjustTime(const CTime &from, bool shift_time=true)
Helper method to adjust the time to correct timezone (across the barrier of winter & summer times) us...
void Set(long seconds, long nanoseconds=0)
Set time span in seconds and nanoseconds.
int DiffWholeDays(const CTime &t) const
Difference in whole days from specified time.
EDaylight
Whether to adjust for daylight saving time.
CTime GetUniversalTime(void) const
Get the time as universal (GMT/UTC) time.
int MonthWeekNumber(EDayOfWeek first_day_of_week=eSunday) const
Get this date's week number in the month.
ETimeZonePrecision SetTimeZonePrecision(ETimeZonePrecision val)
Set time zone precision.
CTime m_TunedTime
Last tuned time (changed by Tuneup())
CTime & AddMonth(int months=1, EDaylight adl=eDaylightDefault)
Add specified months and adjust for daylight saving time.
CTime & Clear(void)
Make the time "empty",.
long NanoSecond(void) const
Get nano-seconds.
void SetYear(int year)
Set year.
unsigned int m_SecAfterHour
Time interval in seconds after hour.
int Year(void) const
Get year.
void SetMilliSecond(long millisecond)
Set milliseconds.
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
int YearWeekNumber(EDayOfWeek first_day_of_week=eSunday) const
Get this date's week number within the year.
string x_AsSmartString_Precision(TSmartStringFlags flags) const
void x_Init(const string &str, const CTimeFormat &fmt)
Helper method to set time value from string "str" using format "fmt".
string x_AsSmartString_Smart_Small(TSmartStringFlags flags) const
const long kMilliSecondsPerSecond
Number milliseconds in one second.
void SetHour(int hour)
Set hour.
CTime & ToTime(ETimeZone val)
Convert the time into specified time zone time.
time_t m_LastSysTime
Last system time.
bool IsEmpty(void) const
Is time object empty (date and time)?
bool operator<(const CTimeout &t) const
Operator to test if timeout is less.
double GetAsDouble(void) const
Get as number of seconds (fractional value).
TFlags m_Flags
Format flags.
bool operator<(const CTime &t) const
Operator to test if time is earlier.
CStopWatch(EStart state=eStop)
Constructor.
CTime & ToUniversalTime(void)
Convert the time into universal (GMT/UTC) time.
bool IsValid(void) const
Is time valid?
static CTimeFormat GetFormat(void)
Get the current time span format.
ESign GetSign(void) const
Get sign of time span.
string TimeZoneName(void)
Get current time zone name.
bool operator==(const CTimeout &t) const
Operator to test equality of timeouts.
void Invert(void)
Invert time span. Changes time span sign.
CTime & SetCurrent(void)
Make the time current in the presently active time zone.
void x_AdjustDay(void)
Helper method to adjust day number to correct value after day manipulations.
void Tuneup(void)
Do unscheduled check.
CTime & SetTimeDBU(const TDBTimeU &t)
Set time using database format time, TDBTimeU.
unsigned int m_Nanoseconds
CTimeSpan & AssignFromSmartString(const string &str)
Assign value to time span object from string representation of time in formats produced by AsSmartStr...
EPredefined
Predefined formats.
ETimeZonePrecision
What time zone precision to use for adjusting daylight saving time.
CTime & x_SetTime(const time_t *t=0)
Helper method to set time from 'time_t' – If "t" not specified, then set to current time.
string AsSmartString(ESmartStringPrecision precision, ERound rounding, ESmartStringZeroMode zero_mode=eSSZ_SkipZero) const
Transform time span to "smart" string.
void SetNano(unsigned int sec, unsigned int nanosec)
Set timeout in seconds and nanoseconds.
static CTimeFormat GetFormat(void)
Get the current stopwatch time format.
static void SetFormat(const CTimeFormat &fmt)
Set the current stopwatch time format.
const TSeconds kAverageSecondsPerMonth
CTimeSpan DiffTimeSpan(const CTime &t) const
Difference in nanoseconds from specified time.
int DaysInMonth(void) const
Get number of days in the month.
bool operator<(const CDeadline &right_hand_operand) const
Compare two CDeadline values.
time_t GetTimeT(void) const
Get time in time_t format.
TDBTimeI GetTimeDBI(void) const
Get time in database format time, TDBTimeI.
unsigned int m_Sec
Seconds part of the timeout.
CTimeSpan(void)
Default constructor.
int GetLocalTimezone(void)
Get difference in seconds between UTC and current local time (daylight information included)
bool operator<=(const CTimeout &t) const
Operator to test if timeout is less or equal.
void SetDay(int day)
Set day.
ETimeZonePrecision tzprec
int Day(void) const
Get day.
void GetNano(unsigned int *sec, unsigned int *nanosec) const
Get timeout in seconds and nanoseconds.
unsigned long GetAsMilliSeconds(void) const
Get as number of milliseconds.
static double GetTimeMark()
Get current time mark.
TSeconds DiffSecond(const CTime &t) const
Difference in seconds from specified time.
TDBTimeU GetTimeDBU(void) const
Get time in database format time, TDBTimeU.
unsigned int m_NanoSec
Nanoseconds part of the timeout.
int x_Hour(void) const
Get hour.
Uint2 days
Days from 1/1/1900.
static CTimeFormat GetPredefined(EPredefined fmt, TFlags flags=fDefault)
Get predefined format.
void Start(void)
Start the timer.
static CTimeFormat GetFormat(void)
Get the current time format.
bool IsLeap(void) const
Is time in a leap year?
bool IsEmpty(void) const
Check that format string is empty.
CTime & SetTimeTM(const struct tm &t)
Set time using "struct tm" time value.
long m_NanoSec
Nanoseconds after the second.
string AsString(const CTimeFormat &fmt=kEmptyStr) const
Transform time span to string.
static int MonthNameToNum(const string &month)
Get numerical value of the month by name.
Uint2 time
Minutes from the beginning of current day.
Int4 time
x/300 seconds from the beginning of current day
CTime m_LocalTime
Current local time.
string AsString(const CTimeFormat &fmt=kEmptyStr) const
Transform stopwatch time to string.
void Set(EType type)
Set special value.
int m_Daylight
Cached system daylight information.
CTime GetFastLocalTime(void)
Quick and dirty getter of local time.
int x_Minute(void) const
Get minute.
void Get(unsigned int *sec, unsigned int *microsec) const
Get timeout in seconds and microseconds.
ERoundPrecision
Precision for rounding time.
CTime & x_AdjustTimeImmediately(const CTime &from, bool shift_time=true)
Helper method to forcibly adjust timezone using "from" as a reference point.
void SetNanoSecond(long nanosecond)
Set nanoseconds.
CTime & SetTimeT(const time_t t)
Set time using time_t time value.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
CTimeFormat(void)
Default constructor.
bool operator>=(const CTimeout &t) const
Operator to test if timeout is greater or equal.
int Hour(void) const
Get hour.
bool IsInfinite(void) const
Check if the deadline is infinite.
CTime & x_SetTimeMTSafe(const time_t *t=0)
Version of x_SetTime() with MT-safe locks.
bool IsFinite() const
Check if timeout holds a numeric value.
void TuneupFastLocalTime(void)
double m_Start
Start time value.
CTime GetLocalTime(void) const
Get the time as local time.
CTime GetLocalTime(void)
Get local time.
CTimeSpan & Clear(void)
Make the time span "empty",.
string m_Str
String format.
void x_SetNowPlus(unsigned int seconds, unsigned int nanoseconds)
CTime & AddDay(int days=1, EDaylight adl=eDaylightDefault)
Add specified days and adjust for daylight saving time.
CTimeFormat & operator=(const CTimeFormat &fmt)
Assignment operator.
EType
Type of special deadlines.
bool IsLocalTime(void) const
Is time local time?
const long kMicroSecondsPerSecond
Number of microseconds in one second.
long GetCompleteSeconds(void) const
Get number of complete seconds.
static string MonthNumToName(int month, ENameFormat format=eFull)
Get name of the month by numerical value.
EStart m_State
Stopwatch state (started/stopped)
CTime & AddHour(int hours=1, EDaylight adl=eDaylightDefault)
Add specified hours and adjust for daylight saving time.
bool IsDST(void) const
Is DST (daylight savings time) in effect for this time?
const TSeconds kAverageSecondsPerYear
The average length of the year in the Gregorian (modern) calendar (in seconds)
int Second(void) const
Get second.
int Month(void) const
Get month.
long GetCompleteHours(void) const
Get number of complete hours.
CTime & AddMinute(int minutes=1, EDaylight adl=eDaylightDefault)
Add specified minutes and adjust for daylight saving time.
void *volatile m_IsTuneup
(bool) Tuneup() in progress (MT)
static int DayOfWeekNameToNum(const string &day)
Get numerical value of the day of week by name.
const long kNanoSecondsPerSecond
Number of nanoseconds in one second.
EType m_Type
Type of timeout.
static void GetCurrentTimeT(time_t *sec, long *nanosec=0)
Get current UTC time in time_t format (with nanoseconds).
static bool ValidateString(const string &str, const CTimeFormat &fmt=kEmptyStr)
Validate if string match time format.
int YearDayNumber(void) const
Get year's day number.
ENameFormat
Which format use to get name of month or week of day.
time_t m_LastTuneupTime
Last Tuneup() time.
bool operator>(const CTimeout &t) const
Operator to test if timeout is greater.
bool operator==(const CTime &t) const
Operator to test equality of time.
long m_Sec
Seconds part of the time span.
bool IsEmptyDate(void) const
Is date empty?
void GetExpirationTime(time_t *sec, unsigned int *nanosec) const
Get the number of seconds and nanoseconds (since 1/1/1970).
string x_AsSmartString_Smart_Big(TSmartStringFlags flags) const
Helpers for AsSmartString()
@ eCurrent
Use current time. See also CCurrentTime.
@ eErr_Throw
Throw an exception on error.
@ eErr_NoThrow
Return default value on error.
@ eUTC
UTC (Universal Coordinated Time)
@ eGmt
GMT (Greenwich Mean Time)
@ eConvert
Error converting value from one format to another.
@ eFormat
Incorrect format.
@ eInvalid
Invalid time value.
@ eArgument
Bad function argument.
@ eAdjustDaylight
Adjust for daylight saving time.
@ eIgnoreDaylight
Ignore daylight saving time.
@ eDefault
Default timeout (to be interpreted by the client code)
@ eInfinite
Infinite timeout.
@ eFinite
A finite timeout value has been set.
@ eZero
Zero timeout, equal to CTimeout(0,0).
@ eMinute
Check condition - new minute.
@ eMonth
Check condition - new month.
@ eDay
Check condition - new day.
@ eHour
Check condition - new hour.
@ eStop
Do not start timer, just create it.
@ fSS_Precision4
Floating precision level 4.
@ fSS_Nanosecond
Do not round at all (accurate time span)
@ fSS_Year
Round to years.
@ fSS_Precision6
Floating precision level 6.
@ fSS_Millisecond
Round to milliseconds.
@ fSS_Hour
Round to hours.
@ fSS_Precision7
Floating precision level 7.
@ fSS_Precision2
Floating precision level 2.
@ fSS_Microsecond
Round to microseconds.
@ fSS_Precision5
Floating precision level 5.
@ fSS_Precision1
Floating precision level 1.
@ fSS_Smart
Be as smart as possible (see above)
@ fSS_PrecisionMask
Mask of precision flags (sum of all above)
@ fSS_Precision3
Floating precision level 3.
@ fSS_Month
Round to months.
@ fSS_Minute
Round to minutes.
@ fSS_Second
Round to seconds.
@ eRound_Minute
Round to minutes.
@ eRound_Day
Round to days.
@ eRound_Hour
Round to hours.
@ eRound_Millisecond
Round to milliseconds.
@ eRound_Second
Round to seconds.
@ eRound_Microsecond
Round to microseconds.
@ fFormat_Ncbi
Specify each format symbol with a preceding symbol '$'.
@ fMatch_Weak
Combination of both modes above.
@ fMatch_IgnoreSpaces
Ignore all white spaces in the time and format strings on the matching/parsing step (CTime only).
@ fMatch_ShortFormat
eg "Y" and "1997/07/16"
@ fConf_UTC
Prefer "UTC" over "GMT" abbreviation for universal time.
@ fMatch_ShortTime
A time/format string can have extra trailing format symbols, that do not have matching symbols in the...
@ fFormat_Simple
Use single characters as format symbols.
@ fMatch_Strict
A time string should strictly match the format string.
unsigned int
A callback function used to compare two keys in a database.
Definition of all error codes used in corelib (xncbi.lib).
const struct ncbi::grid::netcache::search::fields::SIZE size
Static variables safety - create on demand, destroy on application termination.
#define NCBI_CONST_UINT8(v)
void * SwapPointers(void *volatile *location, void *new_value)
Multi-threading – mutexes; rw-locks; semaphore.
Multi-threading – classes, functions, and features.
static int s_DaysInMonth[12]
#define CHECK_RANGE_MONTH(value)
const unsigned int kUnitCount
static const char * kDefaultFormatSpan
#define CHECK_RANGE2_NSEC(value, err)
#define COMPARE_TIMEOUT_TYPES(t1, t2)
static const char * kWeekdayAbbr[7]
static const char * kDefaultFormatSpanIn
static const char * kDefaultFormatStopWatch
#define CHECK_RANGE_DAY(value)
static const char * kMonthAbbr[12]
static CTime s_Number2Date(unsigned num, const CTime &t)
#define CHECK_RANGE2_YEAR(value, err)
static const TSeconds kTimeSpanUnitMultipliers[kUnitCount]
#define CHECK_RANGE2_SEC(value, err)
static const char * kMonthFull[12]
static void s_AddZeroPadInt(string &str, long value, size_t len, bool ignore_trailing_zeros=false)
static const char * kWeekdayFull[7]
#define CHECK_RANGE2_HOUR24(value, err)
static CStaticTls< CTimeFormat > s_TlsFormatTime
static string s_TimeDump(const CTime &time)
static void s_AddZeroPadInt2(string &str, long value)
#define CHECK_RANGE2_MONTH(value, err)
#define CHECK_RANGE2_HOUR12(value, err)
static CStaticTls< CTimeFormat > s_TlsFormatStopWatch
#define CHECK_RANGE_SEC(value)
bool s_IsDST(const CTime &ct)
#define CHECK_RANGE_MIN(value)
static CSafeStatic< CFastLocalTime > s_FastLocalTime
static unsigned s_Date2Number(const CTime &date)
static const char * kFormatSymbolsSpan
static const SUnitName kUnitNames[kUnitCount]
static void s_Offset(long *value, Int8 offset, long bound, int *major)
static const char * kFormatSymbolsTime
static CStaticTls< CTimeFormat > s_TlsFormatSpan
#define X_INIT_ERROR(type, msg)
static void s_AddInt(string &str, long value)
#define CHECK_RANGE2_DAY(value, err)
DEFINE_STATIC_MUTEX(s_TimeMutex)
const char kFormatEscapeSymbol
time_t s_GetTimeT(const CTime &ct)
#define CHECK_RANGE_NSEC(value)
#define CHECK_RANGE_YEAR(value)
static const char * kDefaultFormatTime
#define CHECK_RANGE2_MIN(value, err)
static string s_SpecialValueName(CTimeout::EType type)
#define CHECK_RANGE_HOUR(value)
Defines: CTimeFormat - storage class for time format.
T bound(T x_, T xlo_, T xhi_)
double f(double x_, const double &y_)
static const char * str(char *buf, int n)
Database format for time where day and time is signed 32 bit.
Database format for time where day and time is unsigned 16 bit.