Drizzled Public API Documentation

time.cc
00001 /* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
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; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <drizzled/function/cast/time.h>
00024 #include <drizzled/time_functions.h>
00025 
00026 namespace drizzled {
00027 namespace function {
00028 namespace cast {
00029 
00030 bool Time::get_time(type::Time &ltime)
00031 {
00032   bool res= get_arg0_time(ltime);
00033 
00034   ltime.truncate(type::DRIZZLE_TIMESTAMP_TIME);
00035 
00036   return res;
00037 }
00038 
00039 String *Time::val_str(String *str)
00040 {
00041   assert(fixed == 1);
00042   type::Time ltime;
00043 
00044   if (not get_arg0_time(ltime))
00045   {
00046     null_value= 0;
00047     ltime.convert(*str, type::DRIZZLE_TIMESTAMP_TIME);
00048 
00049     return str;
00050   }
00051 
00052   null_value= 1;
00053   return 0;
00054 }
00055 
00056 int64_t Time::val_int()
00057 {
00058   assert(fixed == 1);
00059   type::Time ltime;
00060 
00061   if (get_time(ltime))
00062     return 0;
00063 
00064   return (ltime.neg ? -1 : 1) * (int64_t)((ltime.hour)*10000 + ltime.minute*100 + ltime.second);
00065 }
00066 
00067 } // namespace cast
00068 } // namespace function
00069 } // namespace drizzled