00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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(<ime);
00038
00039
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 }