Drizzled Public API Documentation

curtime.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2011 Matthew Rheaume
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 <config.h>
21 
22 #include <drizzled/function/time/curtime.h>
23 #include <drizzled/temporal.h>
24 #include <drizzled/session.h>
25 #include <drizzled/session/times.h>
26 #include <drizzled/current_session.h>
27 
28 namespace drizzled
29 {
30 
31 void Item_func_curtime::fix_length_and_dec()
32 {
33  collation.set(&my_charset_bin);
34  decimals=0;
35  max_length=Time::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
36 
37  store_now_in_TIME(&ltime);
38 
39  ltime.year= ltime.month= ltime.day= 0;
40  ltime.time_type = type::DRIZZLE_TIMESTAMP_TIME;
41 
42  cached_temporal.set_hours(ltime.hour);
43  cached_temporal.set_minutes(ltime.minute);
44  cached_temporal.set_seconds(ltime.second);
45 }
46 
47 void Item_func_curtime_local::store_now_in_TIME(type::Time *now_time)
48 {
49  (void) cached_temporal.from_time_t(current_session->times.getCurrentTimestampEpoch());
50 
51  now_time->year= 0;
52  now_time->month= 0;
53  now_time->day= 0;
54  now_time->hour= cached_temporal.hours();
55  now_time->minute= cached_temporal.minutes();
56  now_time->second= cached_temporal.seconds();
57 }
58 
59 void Item_func_curtime_utc::store_now_in_TIME(type::Time *now_time)
60 {
61  (void) cached_temporal.from_time_t(current_session->times.getCurrentTimestampEpoch());
62 
63  now_time->year= 0;
64  now_time->month= 0;
65  now_time->day= 0;
66  now_time->hour= cached_temporal.hours();
67  now_time->minute= cached_temporal.minutes();
68  now_time->second= cached_temporal.seconds();
69 }
70 
71 bool Item_func_curtime::get_temporal(Time &to)
72 {
73  to= cached_temporal;
74  return true;
75 }
76 
78 {
79  res= ltime;
80  return 0;
81 }
82 
83 } /* namespace drizzled */
void set_hours(const uint32_t hour)
Definition: temporal.h:136
bool get_time(type::Time &res)
Definition: curtime.cc:77
uint32_t hours() const
Definition: temporal.h:138
void set_minutes(const uint32_t minute)
Definition: temporal.h:132
uint32_t minutes() const
Definition: temporal.h:134
void set_seconds(const uint32_t second)
Definition: temporal.h:128
bool from_time_t(const time_t from)
Definition: temporal.cc:1224
uint32_t seconds() const
Definition: temporal.h:130
static const int MAX_STRING_LENGTH
Definition: temporal.h:494