1026
1026
static int my_time_to_str(const type::Time *l_time, char *to)
1028
1029
uint32_t extra_hours= 0;
1029
return sprintf(to, "%s%02u:%02u:%02u",
1030
(l_time->neg ? "-" : ""),
1031
extra_hours+ l_time->hour,
1031
length= sprintf(to, "%s%02u:%02u:%02u",
1032
(l_time->neg ? "-" : ""),
1033
extra_hours+ l_time->hour,
1039
return static_cast<size_t>(length);
1036
1042
static int my_date_to_str(const type::Time *l_time, char *to)
1038
return sprintf(to, "%04u-%02u-%02u",
1045
length= sprintf(to, "%04u-%02u-%02u",
1044
static int my_datetime_to_str(const type::Time *l_time, char *to)
1046
return sprintf(to, "%04u-%02u-%02u %02u:%02u:%02u",
1057
Convert struct DATE/TIME/DATETIME value to string using built-in
1058
MySQL time conversion formats.
1064
The string must have at least MAX_DATE_STRING_REP_LENGTH bytes reserved.
1067
int my_TIME_to_str(const type::Time *l_time, char *to)
1069
switch (l_time->time_type) {
1070
case type::DRIZZLE_TIMESTAMP_DATETIME:
1071
return my_datetime_to_str(l_time, to);
1073
case type::DRIZZLE_TIMESTAMP_DATE:
1074
return my_date_to_str(l_time, to);
1076
case type::DRIZZLE_TIMESTAMP_TIME:
1077
return my_time_to_str(l_time, to);
1079
case type::DRIZZLE_TIMESTAMP_NONE:
1080
case type::DRIZZLE_TIMESTAMP_ERROR:
1052
return static_cast<size_t>(length);
1055
static size_t my_datetime_to_str(const type::Time *l_time, char *to, size_t to_len)
1058
length= snprintf(to, to_len,
1059
"%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
1060
" %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
1067
l_time->second_part);
1071
return static_cast<size_t>(length);
1087
1075
namespace type {
1136
1124
void Time::convert(String &str, timestamp_t arg)
1138
str.alloc(MAX_DATE_STRING_REP_LENGTH);
1126
str.alloc(MAX_STRING_LENGTH);
1127
size_t length= MAX_STRING_LENGTH;
1129
convert(str.c_ptr(), length, arg);
1132
str.set_charset(&my_charset_bin);
1135
void Time::convert(char *str, size_t &to_length, timestamp_t arg)
1142
1138
case DRIZZLE_TIMESTAMP_DATETIME:
1143
length= (uint32_t) my_datetime_to_str(this, str.c_ptr());
1139
to_length= my_datetime_to_str(this, str, to_length);
1146
1142
case DRIZZLE_TIMESTAMP_DATE:
1147
length= (uint32_t) my_date_to_str(this, str.c_ptr());
1143
to_length= (uint32_t) my_date_to_str(this, str);
1150
1146
case DRIZZLE_TIMESTAMP_TIME:
1151
length= (uint32_t) my_time_to_str(this, str.c_ptr());
1147
to_length= (uint32_t) my_time_to_str(this, str);
1154
1150
case DRIZZLE_TIMESTAMP_NONE:
1155
1151
case DRIZZLE_TIMESTAMP_ERROR:
1161
str.set_charset(&my_charset_bin);