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/sec_to_time.h>
25
Convert seconds to DRIZZLE_TIME value with overflow checking
29
seconds number of seconds
30
unsigned_flag 1, if 'seconds' is unsigned, 0, otherwise
31
ltime output DRIZZLE_TIME value
34
If the 'seconds' argument is inside DRIZZLE_TIME data range, convert it to a
36
Otherwise, truncate the resulting value to the nearest endpoint, and
37
produce a warning message.
40
1 if the value was truncated during conversion
44
static bool sec_to_time(int64_t seconds, bool unsigned_flag, DRIZZLE_TIME *ltime)
48
memset(ltime, 0, sizeof(*ltime));
53
if (seconds < -3020399)
57
else if (seconds > 3020399)
60
sec= (uint) ((uint64_t) seconds % 3600);
61
ltime->hour= (uint) (seconds/3600);
62
ltime->minute= sec/60;
63
ltime->second= sec % 60;
68
ltime->hour= TIME_MAX_HOUR;
69
ltime->minute= TIME_MAX_MINUTE;
70
ltime->second= TIME_MAX_SECOND;
73
int len= (int)(int64_t10_to_str(seconds, buf, unsigned_flag ? 10 : -10)
75
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
76
buf, len, DRIZZLE_TIMESTAMP_TIME,
82
String *Item_func_sec_to_time::val_str(String *str)
86
int64_t arg_val= args[0]->val_int();
88
if ((null_value=args[0]->null_value) ||
89
str->alloc(MAX_DATE_STRING_REP_LENGTH))
95
sec_to_time(arg_val, args[0]->unsigned_flag, <ime);
97
make_time((DATE_TIME_FORMAT *) 0, <ime, str);
101
int64_t Item_func_sec_to_time::val_int()
105
int64_t arg_val= args[0]->val_int();
107
if ((null_value=args[0]->null_value))
110
sec_to_time(arg_val, args[0]->unsigned_flag, <ime);
112
return (ltime.neg ? -1 : 1) *
113
((ltime.hour)*10000 + ltime.minute*100 + ltime.second);