Drizzled Public API Documentation

date.cc
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/date.h>
23 #include <drizzled/temporal.h>
24 
25 namespace drizzled
26 {
27 
29 {
30  assert(fixed);
31 
32  /* We have our subclass convert a Date temporal for us */
33  Date temporal;
34  if (! get_temporal(temporal))
35  return (String *) NULL; /* get_temporal throws error. */
36 
37  str->alloc(type::Time::MAX_STRING_LENGTH);
38 
39  /* Convert the Date to a string and return it */
40  size_t new_length;
41  new_length= temporal.to_string(str->c_ptr(), type::Time::MAX_STRING_LENGTH);
42  assert(new_length < type::Time::MAX_STRING_LENGTH);
43  str->length(new_length);
44  return str;
45 }
46 
48 {
49  assert(fixed);
50 
51  /* We have our subclass convert a Date temporal for us */
52  Date temporal;
53  if (! get_temporal(temporal))
54  return 0; /* get_temporal throws error. */
55 
56  /* Convert the Date to a string and return it */
57  int32_t int_value;
58  temporal.to_int32_t(&int_value);
59  return (int64_t) int_value;
60 }
61 
62 } /* namespace drizzled */
bool fixed
Definition: item.h:120
virtual void to_int32_t(int32_t *to) const
Definition: temporal.cc:1057
int64_t val_int()
Definition: date.cc:47
String * val_str(String *str)
Definition: date.cc:28
virtual int to_string(char *to, size_t to_len) const
Definition: temporal.cc:994
virtual bool get_temporal(Date &temporal)=0