1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
20
#include <drizzled/server_includes.h>
22
#include <drizzled/functions/time/makedate.h>
25
MAKEDATE(a,b) is a date function that creates a date value
26
from a year and day value.
29
As arguments are integers, we can't know if the year is a 2 digit or 4 digit year.
30
In this case we treat all years < 100 as 2 digit years. Ie, this is not safe
31
for dates between 0000-01-01 and 0099-12-31
34
String *Item_func_makedate::val_str(String *str)
38
long daynr= (long) args[1]->val_int();
39
long year= (long) args[0]->val_int();
42
if (args[0]->null_value || args[1]->null_value ||
43
year < 0 || daynr <= 0)
47
year= year_2000_handling(year);
49
days= calc_daynr(year,1,1) + daynr - 1;
50
/* Day number from year 0 to 9999-12-31 */
51
if (days >= 0 && days <= MAX_DAY_NUMBER)
54
get_date_from_daynr(days,&l_time.year,&l_time.month,&l_time.day);
55
if (str->alloc(MAX_DATE_STRING_REP_LENGTH))
57
make_date((DATE_TIME_FORMAT *) 0, &l_time, str);
68
MAKEDATE(a,b) is a date function that creates a date value
69
from a year and day value.
72
As arguments are integers, we can't know if the year is a 2 digit or 4 digit year.
73
In this case we treat all years < 100 as 2 digit years. Ie, this is not safe
74
for dates between 0000-01-01 and 0099-12-31
77
int64_t Item_func_makedate::val_int()
81
long daynr= (long) args[1]->val_int();
82
long year= (long) args[0]->val_int();
85
if (args[0]->null_value || args[1]->null_value ||
86
year < 0 || daynr <= 0)
90
year= year_2000_handling(year);
92
days= calc_daynr(year,1,1) + daynr - 1;
93
/* Day number from year 0 to 9999-12-31 */
94
if (days >= 0 && days < MAX_DAY_NUMBER)
97
get_date_from_daynr(days,&l_time.year,&l_time.month,&l_time.day);
98
return (int64_t) (l_time.year * 10000L + l_time.month * 100 + l_time.day);