~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/function/time/curtime.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
77
bool Item_func_curtime::get_time(type::Time &res)
 
78
{
 
79
  res= ltime;
 
80
  return 0;
 
81
}
 
82
 
 
83
} /* namespace drizzled */