~drizzle-trunk/drizzle/development

574.3.15 by Lee
moving functions from item_timefunc to functions/time directory
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
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.
9
 *
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.
14
 *
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
18
 */
19
20
#include <drizzled/server_includes.h>
21
#include CSTDINT_H
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
22
#include <drizzled/function/time/curtime.h>
574.3.15 by Lee
moving functions from item_timefunc to functions/time directory
23
#include <drizzled/tztime.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
24
#include <drizzled/session.h>
574.3.15 by Lee
moving functions from item_timefunc to functions/time directory
25
26
String *Item_func_curtime::val_str(String *str __attribute__((unused)))
27
{
28
  assert(fixed == 1);
29
  str_value.set(buff, buff_length, &my_charset_bin);
30
  return &str_value;
31
}
32
33
void Item_func_curtime::fix_length_and_dec()
34
{
35
  DRIZZLE_TIME ltime;
36
37
  decimals= DATETIME_DEC;
38
  collation.set(&my_charset_bin);
39
  store_now_in_TIME(&ltime);
40
  value= TIME_to_uint64_t_time(&ltime);
41
  buff_length= (uint) my_time_to_str(&ltime, buff);
42
  max_length= buff_length;
43
}
44
45
/**
46
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for local
47
    time zone. Defines time zone (local) used for whole CURTIME function.
48
*/
49
void Item_func_curtime_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
50
{
51
  Session *session= current_session;
52
  session->variables.time_zone->gmt_sec_to_TIME(now_time,
53
                                             (my_time_t)session->query_start());
54
}
55
56
/**
57
    Converts current time in my_time_t to DRIZZLE_TIME represenatation for UTC
58
    time zone. Defines time zone (UTC) used for whole UTC_TIME function.
59
*/
60
void Item_func_curtime_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
61
{
62
  my_tz_UTC->gmt_sec_to_TIME(now_time,
63
                             (my_time_t)(current_session->query_start()));
64
  /*
65
    We are not flagging this query as using time zone, since it uses fixed
66
    UTC-SYSTEM time-zone.
67
  */
68
}
69
70
71