Drizzled Public API Documentation

curdate.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <drizzled/function/time/curdate.h>
00023 #include <drizzled/tztime.h>
00024 #include <drizzled/temporal.h>
00025 #include <drizzled/session.h>
00026 #include <drizzled/current_session.h>
00027 
00028 namespace drizzled
00029 {
00030 
00031 void Item_func_curdate::fix_length_and_dec()
00032 {
00033   collation.set(&my_charset_bin);
00034   decimals=0;
00035   max_length=Date::MAX_STRING_LENGTH*MY_CHARSET_BIN_MB_MAXLEN;
00036 
00037   store_now_in_TIME(&ltime);
00038 
00039   /* We don't need to set second_part and neg because they already 0 */
00040   ltime.hour= ltime.minute= ltime.second= 0;
00041   ltime.time_type= type::DRIZZLE_TIMESTAMP_DATE;
00042 
00047   cached_temporal.set_years(ltime.year);
00048   cached_temporal.set_months(ltime.month);
00049   cached_temporal.set_days(ltime.day);
00050 }
00051 
00056 void Item_func_curdate_local::store_now_in_TIME(type::Time *now_time)
00057 {
00058   Session *session= current_session;
00059   time_t tmp= session->getCurrentTimestampEpoch();
00060 
00061   (void) cached_temporal.from_time_t(tmp);
00062 
00063   now_time->year= cached_temporal.years();
00064   now_time->month= cached_temporal.months();
00065   now_time->day= cached_temporal.days();
00066   now_time->hour= 0;
00067   now_time->minute= 0;
00068   now_time->second= 0;
00069   now_time->second_part= 0;
00070 }
00071 
00076 void Item_func_curdate_utc::store_now_in_TIME(type::Time *now_time)
00077 {
00078   Session *session= current_session;
00079   time_t tmp= session->getCurrentTimestampEpoch();
00080 
00081   (void) cached_temporal.from_time_t(tmp);
00082 
00083   now_time->year= cached_temporal.years();
00084   now_time->month= cached_temporal.months();
00085   now_time->day= cached_temporal.days();
00086   now_time->hour= 0;
00087   now_time->minute= 0;
00088   now_time->second= 0;
00089   now_time->second_part= 0;
00090 }
00091 
00092 bool Item_func_curdate::get_temporal(Date &to)
00093 {
00094   to= cached_temporal;
00095   return true;
00096 }
00097 
00098 } /* namespace drizzled */