~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-05-11 17:50:22 UTC
  • Revision ID: brian@gaz-20090511175022-y35q9ky6uh9ldcjt
Replacing Sun employee copyright headers (aka... anything done by a Sun
employee is copyright by Sun).

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