diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-02-15 11:48:30 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-02-15 11:48:30 +0200 |
commit | cc3b5d1fe75cf1d9b83b7918151f8d90e9263d34 (patch) | |
tree | 126aa92625cbe953175cefec87dbd92d97ce7a54 /sql/sql_time.cc | |
parent | b006d2ead4640f0ab4e29687fd7d24988b1c98f1 (diff) | |
parent | 22770a9f9a7fb4c30dbdc204e5a8f829303b7373 (diff) | |
download | mariadb-git-cc3b5d1fe75cf1d9b83b7918151f8d90e9263d34.tar.gz |
Merge bb-10.2-ext into 10.3
Diffstat (limited to 'sql/sql_time.cc')
-rw-r--r-- | sql/sql_time.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 95435c698f8..b0de8dab4c5 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -1392,3 +1392,46 @@ bool datetime_to_time_with_warn(THD *thd, const MYSQL_TIME *dt, int warnings= 0; return check_time_range(tm, dec, &warnings); } + + +longlong pack_time(const MYSQL_TIME *my_time) +{ + return ((((((my_time->year * 13ULL + + my_time->month) * 32ULL + + my_time->day) * 24ULL + + my_time->hour) * 60ULL + + my_time->minute) * 60ULL + + my_time->second) * 1000000ULL + + my_time->second_part) * (my_time->neg ? -1 : 1); +} + +#define get_one(WHERE, FACTOR) WHERE= (ulong)(packed % FACTOR); packed/= FACTOR + +void unpack_time(longlong packed, MYSQL_TIME *my_time, + enum_mysql_timestamp_type ts_type) +{ + if ((my_time->neg= packed < 0)) + packed= -packed; + get_one(my_time->second_part, 1000000ULL); + get_one(my_time->second, 60U); + get_one(my_time->minute, 60U); + get_one(my_time->hour, 24U); + get_one(my_time->day, 32U); + get_one(my_time->month, 13U); + my_time->year= (uint)packed; + my_time->time_type= ts_type; + switch (ts_type) { + case MYSQL_TIMESTAMP_TIME: + my_time->hour+= (my_time->month * 32 + my_time->day) * 24; + my_time->month= my_time->day= 0; + break; + case MYSQL_TIMESTAMP_DATE: + my_time->hour= my_time->minute= my_time->second= my_time->second_part= 0; + break; + case MYSQL_TIMESTAMP_NONE: + case MYSQL_TIMESTAMP_ERROR: + DBUG_ASSERT(0); + case MYSQL_TIMESTAMP_DATETIME: + break; + } +} |