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/functions/time/maketime.h>
25
MAKETIME(h,m,s) is a time function that calculates a time value
26
from the total number of hours, minutes, and seconds.
30
String *Item_func_maketime::val_str(String *str)
36
int64_t hour= args[0]->val_int();
37
int64_t minute= args[1]->val_int();
38
int64_t second= args[2]->val_int();
40
if ((null_value=(args[0]->null_value ||
41
args[1]->null_value ||
42
args[2]->null_value ||
43
minute < 0 || minute > 59 ||
44
second < 0 || second > 59 ||
45
str->alloc(MAX_DATE_STRING_REP_LENGTH))))
48
memset(<ime, 0, sizeof(ltime));
51
/* Check for integer overflows */
55
if (-hour > UINT_MAX || hour > UINT_MAX)
60
ltime.hour= (uint) ((hour < 0 ? -hour : hour));
61
ltime.minute= (uint) minute;
62
ltime.second= (uint) second;
66
ltime.hour= TIME_MAX_HOUR;
67
ltime.minute= TIME_MAX_MINUTE;
68
ltime.second= TIME_MAX_SECOND;
70
char *ptr= int64_t10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
71
int len = (int)(ptr - buf) +
72
sprintf(ptr, ":%02u:%02u", (uint)minute, (uint)second);
73
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
74
buf, len, DRIZZLE_TIMESTAMP_TIME,
78
if (make_time_with_warn((DATE_TIME_FORMAT *) 0, <ime, str))