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/timediff.h>
23
#include <drizzled/item/timefunc.h>
26
TIMEDIFF(t,s) is a time function that calculates the
27
time value between a start and end time.
29
t and s: time_or_datetime_expression
33
String *Item_func_timediff::val_str(String *str)
39
DRIZZLE_TIME l_time1 ,l_time2, l_time3;
42
if (args[0]->get_time(&l_time1) ||
43
args[1]->get_time(&l_time2) ||
44
l_time1.time_type != l_time2.time_type)
47
if (l_time1.neg != l_time2.neg)
50
memset(&l_time3, 0, sizeof(l_time3));
52
l_time3.neg= calc_time_diff(&l_time1, &l_time2, l_sign,
53
&seconds, µseconds);
56
For DRIZZLE_TIMESTAMP_TIME only:
57
If first argument was negative and diff between arguments
58
is non-zero we need to swap sign to get proper result.
60
if (l_time1.neg && (seconds || microseconds))
61
l_time3.neg= 1-l_time3.neg; // Swap sign of result
63
calc_time_from_sec(&l_time3, (long) seconds, microseconds);
65
if (!make_datetime_with_warn(l_time1.second_part || l_time2.second_part ?
66
TIME_MICROSECOND : TIME_ONLY,