1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
22
#include <drizzled/function/time/make_datetime.h>
27
- Replace the switch with a function that should be called for each
29
- Remove sprintf and opencode the conversion, like we do in
32
The reason for this functions existence is that as we don't have a
33
way to know if a datetime/time value has microseconds in them
34
we are now only adding microseconds to the output if the
35
value has microseconds.
37
We can't use a standard make_date_time() for this as we don't know
38
if someone will use %f in the format specifier in which case we would get
39
the microseconds twice.
42
bool make_datetime(date_time_format_types format, DRIZZLE_TIME *ltime,
46
const CHARSET_INFO * const cs= &my_charset_bin;
47
uint32_t length= MAX_DATE_STRING_REP_LENGTH;
49
if (str->alloc(length))
51
buff= (char*) str->ptr();
55
length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d",
56
ltime->neg ? "-" : "",
57
ltime->hour, ltime->minute, ltime->second);
59
case TIME_MICROSECOND:
60
length= cs->cset->snprintf(cs, buff, length, "%s%02d:%02d:%02d.%06ld",
61
ltime->neg ? "-" : "",
62
ltime->hour, ltime->minute, ltime->second,
66
length= cs->cset->snprintf(cs, buff, length, "%04d-%02d-%02d",
67
ltime->year, ltime->month, ltime->day);
70
length= cs->cset->snprintf(cs, buff, length,
71
"%04d-%02d-%02d %02d:%02d:%02d",
72
ltime->year, ltime->month, ltime->day,
73
ltime->hour, ltime->minute, ltime->second);
75
case DATE_TIME_MICROSECOND:
76
length= cs->cset->snprintf(cs, buff, length,
77
"%04d-%02d-%02d %02d:%02d:%02d.%06ld",
78
ltime->year, ltime->month, ltime->day,
79
ltime->hour, ltime->minute, ltime->second,