1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

MCOL-392 Fix negative time handling

This commit is contained in:
Andrew Hutchings
2018-04-26 14:28:17 +01:00
parent 3c1ebd8b94
commit edb2e2f36d
4 changed files with 44 additions and 9 deletions

View File

@ -863,12 +863,11 @@ bool mysql_str_to_time( const string& input, Time& output )
{
int32_t datesepct = 0;
uint32_t dtend = 0;
bool isNeg = false;
/**
* We need to deal with the time portion.
* The rules are:
* - Time portion may be empty
* - Time portion may start with 'T'
* - Time portion always ends with '\0'
* - Time portion always starts with hour
* - Without time separators (':'):
@ -890,7 +889,7 @@ bool mysql_str_to_time( const string& input, Time& output )
uint32_t timesep_ct = 0;
bool has_usec = false;
uint32_t len_before_msec = 0;
uint32_t tmstart = ( input[dtend] == ' ' || input[dtend] == 'T' ) ? dtend + 1 : dtend;
uint32_t tmstart = dtend;
uint32_t tmend = tmstart;
for ( ; tmend < input.length(); ++tmend )
@ -918,6 +917,11 @@ bool mysql_str_to_time( const string& input, Time& output )
len_before_msec = ( tmend - tmstart );
has_usec = true;
}
else if (c == '-' && (tmend == tmstart))
{
isNeg = true;
++tmstart;
}
else
{
timesep_ct++;
@ -998,7 +1002,7 @@ bool mysql_str_to_time( const string& input, Time& output )
return false;
}
output.hour = hour;
output.hour = isNeg ? 0-hour : hour;
output.minute = min;
output.second = sec;
output.msecond = usec;

View File

@ -566,10 +566,19 @@ inline void DataConvert::datetimeToString( long long datetimevalue, char* buf, u
inline void DataConvert::timeToString( long long timevalue, char* buf, unsigned int buflen )
{
// Handle negative correctly
int hour = 0;
if ((timevalue >> 40) & 0xf00)
{
hour = 0xfffff000;
}
hour |= ((timevalue >> 40) & 0xfff);
if ((timevalue & 0xffffff) > 0)
{
snprintf( buf, buflen, "%02d:%02d:%02d.%d",
(unsigned)((timevalue >> 40) & 0xfff),
hour,
(unsigned)((timevalue >> 32) & 0xff),
(unsigned)((timevalue >> 24) & 0xff),
(unsigned)((timevalue) & 0xffffff)
@ -578,7 +587,7 @@ inline void DataConvert::timeToString( long long timevalue, char* buf, unsigned
else
{
snprintf( buf, buflen, "%02d:%02d:%02d",
(unsigned)((timevalue >> 40) & 0xfff),
hour,
(unsigned)((timevalue >> 32) & 0xff),
(unsigned)((timevalue >> 24) & 0xff)
);
@ -608,8 +617,17 @@ inline void DataConvert::datetimeToString1( long long datetimevalue, char* buf,
inline void DataConvert::timeToString1( long long timevalue, char* buf, unsigned int buflen )
{
// Handle negative correctly
int hour = 0;
if ((timevalue >> 40) & 0xf00)
{
hour = 0xfffff000;
}
hour |= ((timevalue >> 40) & 0xfff);
snprintf( buf, buflen, "%02d%02d%02d",
(unsigned)((timevalue >> 40) & 0xfff),
hour,
(unsigned)((timevalue >> 32) & 0xff),
(unsigned)((timevalue >> 14) & 0xff)
);