diff options
author | unknown <konstantin@mysql.com> | 2004-10-20 16:45:09 +0400 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-10-20 16:45:09 +0400 |
commit | 7c20b1328866061273617ec7e8ae7b4e00c8674c (patch) | |
tree | b63f30c547d9c739a72eccdd5b8817f371e31a6d /sql-common | |
parent | 6875cf36d1625449f539c9eaefb8171158231ee2 (diff) | |
parent | 8fe8912f4c1d01b9bb8c5c1aefe4ac6405a87976 (diff) | |
download | mariadb-git-7c20b1328866061273617ec7e8ae7b4e00c8674c.tar.gz |
Merge bk-internal.mysql.com:/home/bk/mysql-4.1
into mysql.com:/home/kostja/work/mysql-4.1-6049
libmysql/libmysql.c:
Auto merged
sql/field.cc:
Auto merged
sql/item.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
tests/client_test.c:
Auto merged
Diffstat (limited to 'sql-common')
-rw-r--r-- | sql-common/my_time.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 4b5daf53bea..93549f7340c 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -726,3 +726,75 @@ void set_zero_time(MYSQL_TIME *tm) tm->time_type= MYSQL_TIMESTAMP_NONE; } + +/* + Functions to convert time/date/datetime value to a string, + using default format. + This functions don't check that given TIME structure members are + in valid range. If they are not, return value won't reflect any + valid date either. Additionally, make_time doesn't take into + account time->day member: it's assumed that days have been converted + to hours already. + + RETURN + number of characters written to 'to' +*/ + +int my_time_to_str(const MYSQL_TIME *l_time, char *to) +{ + return my_sprintf(to, (to, "%s%02d:%02d:%02d", + (l_time->neg ? "-" : ""), + l_time->hour, + l_time->minute, + l_time->second)); +} + +int my_date_to_str(const MYSQL_TIME *l_time, char *to) +{ + return my_sprintf(to, (to, "%04d-%02d-%02d", + l_time->year, + l_time->month, + l_time->day)); +} + +int my_datetime_to_str(const MYSQL_TIME *l_time, char *to) +{ + return my_sprintf(to, (to, "%04d-%02d-%02d %02d:%02d:%02d", + l_time->year, + l_time->month, + l_time->day, + l_time->hour, + l_time->minute, + l_time->second)); +} + + +/* + Convert struct DATE/TIME/DATETIME value to string using built-in + MySQL time conversion formats. + + SYNOPSIS + my_TIME_to_string() + + NOTE + The string must have at least MAX_DATE_STRING_REP_LENGTH bytes reserved. +*/ + +int my_TIME_to_str(const MYSQL_TIME *l_time, char *to) +{ + switch (l_time->time_type) { + case MYSQL_TIMESTAMP_DATETIME: + return my_datetime_to_str(l_time, to); + case MYSQL_TIMESTAMP_DATE: + return my_date_to_str(l_time, to); + case MYSQL_TIMESTAMP_TIME: + return my_time_to_str(l_time, to); + case MYSQL_TIMESTAMP_NONE: + case MYSQL_TIMESTAMP_ERROR: + to[0]='\0'; + return 0; + default: + DBUG_ASSERT(0); + return 0; + } +} |