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>
21
#include <drizzled/current_session.h>
23
#include <drizzled/function/time/sec_to_time.h>
26
Convert seconds to DRIZZLE_TIME value with overflow checking
30
seconds number of seconds
31
unsigned_flag 1, if 'seconds' is unsigned, 0, otherwise
32
ltime output DRIZZLE_TIME value
35
If the 'seconds' argument is inside DRIZZLE_TIME data range, convert it to a
37
Otherwise, truncate the resulting value to the nearest endpoint, and
38
produce a warning message.
41
1 if the value was truncated during conversion
45
static bool sec_to_time(int64_t seconds, bool unsigned_flag, DRIZZLE_TIME *ltime)
49
memset(ltime, 0, sizeof(*ltime));
54
if (seconds < -3020399)
58
else if (seconds > 3020399)
61
sec= (uint) ((uint64_t) seconds % 3600);
62
ltime->hour= (uint) (seconds/3600);
63
ltime->minute= sec/60;
64
ltime->second= sec % 60;
69
ltime->hour= TIME_MAX_HOUR;
70
ltime->minute= TIME_MAX_MINUTE;
71
ltime->second= TIME_MAX_SECOND;
74
int len= (int)(int64_t10_to_str(seconds, buf, unsigned_flag ? 10 : -10)
76
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
77
buf, len, DRIZZLE_TIMESTAMP_TIME,
83
String *Item_func_sec_to_time::val_str(String *str)
87
int64_t arg_val= args[0]->val_int();
89
if ((null_value=args[0]->null_value) ||
90
str->alloc(MAX_DATE_STRING_REP_LENGTH))
96
sec_to_time(arg_val, args[0]->unsigned_flag, <ime);
98
make_time((DATE_TIME_FORMAT *) 0, <ime, str);
102
int64_t Item_func_sec_to_time::val_int()
106
int64_t arg_val= args[0]->val_int();
108
if ((null_value=args[0]->null_value))
111
sec_to_time(arg_val, args[0]->unsigned_flag, <ime);
113
return (ltime.neg ? -1 : 1) *
114
((ltime.hour)*10000 + ltime.minute*100 + ltime.second);