~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Stewart Smith
  • Date: 2008-10-15 04:21:24 UTC
  • mto: This revision was merged to the branch mainline in revision 516.
  • Revision ID: stewart@flamingspork.com-20081015042124-kdmb74bcbky1k1nz
remove my_pthread_[gs]etspecific

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) 2008 Sun Microsystems, Inc.
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/curdate.h>
23
 
#include <drizzled/tztime.h>
24
 
#include <drizzled/temporal.h>
25
 
#include <drizzled/session.h>
26
 
#include <drizzled/current_session.h>
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
void Item_func_curdate::fix_length_and_dec()
32
 
{
33
 
  collation.set(&my_charset_bin);
34
 
  decimals=0;
35
 
  max_length=Date::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
36
 
 
37
 
  store_now_in_TIME(&ltime);
38
 
 
39
 
  /* We don't need to set second_part and neg because they already 0 */
40
 
  ltime.hour= ltime.minute= ltime.second= 0;
41
 
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
42
 
 
43
 
  /** 
44
 
   * @TODO Remove ltime completely when timezones are reworked.  Using this
45
 
   * technique now to avoid a large patch...
46
 
   */
47
 
  cached_temporal.set_years(ltime.year);
48
 
  cached_temporal.set_months(ltime.month);
49
 
  cached_temporal.set_days(ltime.day);
50
 
}
51
 
 
52
 
/**
53
 
    Converts current time in time_t to type::Time represenatation for local
54
 
    time zone. Defines time zone (local) used for whole CURDATE function.
55
 
*/
56
 
void Item_func_curdate_local::store_now_in_TIME(type::Time *now_time)
57
 
{
58
 
  Session *session= current_session;
59
 
  time_t tmp= session->getCurrentTimestampEpoch();
60
 
 
61
 
  (void) cached_temporal.from_time_t(tmp);
62
 
 
63
 
  now_time->year= cached_temporal.years();
64
 
  now_time->month= cached_temporal.months();
65
 
  now_time->day= cached_temporal.days();
66
 
  now_time->hour= 0;
67
 
  now_time->minute= 0;
68
 
  now_time->second= 0;
69
 
  now_time->second_part= 0;
70
 
}
71
 
 
72
 
/**
73
 
    Converts current time in time_t to type::Time represenatation for UTC
74
 
    time zone. Defines time zone (UTC) used for whole UTC_DATE function.
75
 
*/
76
 
void Item_func_curdate_utc::store_now_in_TIME(type::Time *now_time)
77
 
{
78
 
  Session *session= current_session;
79
 
  time_t tmp= session->getCurrentTimestampEpoch();
80
 
 
81
 
  (void) cached_temporal.from_time_t(tmp);
82
 
 
83
 
  now_time->year= cached_temporal.years();
84
 
  now_time->month= cached_temporal.months();
85
 
  now_time->day= cached_temporal.days();
86
 
  now_time->hour= 0;
87
 
  now_time->minute= 0;
88
 
  now_time->second= 0;
89
 
  now_time->second_part= 0;
90
 
}
91
 
 
92
 
bool Item_func_curdate::get_temporal(Date &to)
93
 
{
94
 
  to= cached_temporal;
95
 
  return true;
96
 
}
97
 
 
98
 
} /* namespace drizzled */