22
22
#include <drizzled/functions/time/date_format.h>
23
23
#include <drizzled/session.h>
26
Create a formated date/time value in a string.
29
static bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
30
enum enum_drizzle_timestamp_type type, String *str)
36
const char *ptr, *end;
37
Session *session= current_session;
38
MY_LOCALE *locale= session->variables.lc_time_names;
45
end= (ptr= format->format.str) + format->format.length;
46
for (; ptr != end ; ptr++)
48
if (*ptr != '%' || ptr+1 == end)
56
str->append(locale->month_names->type_names[l_time->month-1],
57
strlen(locale->month_names->type_names[l_time->month-1]),
63
str->append(locale->ab_month_names->type_names[l_time->month-1],
64
strlen(locale->ab_month_names->type_names[l_time->month-1]),
68
if (type == DRIZZLE_TIMESTAMP_TIME)
70
weekday= calc_weekday(calc_daynr(l_time->year,l_time->month,
72
str->append(locale->day_names->type_names[weekday],
73
strlen(locale->day_names->type_names[weekday]),
77
if (type == DRIZZLE_TIMESTAMP_TIME)
79
weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
81
str->append(locale->ab_day_names->type_names[weekday],
82
strlen(locale->ab_day_names->type_names[weekday]),
86
if (type == DRIZZLE_TIMESTAMP_TIME)
88
length= int10_to_str(l_time->day, intbuff, 10) - intbuff;
89
str->append_with_prefill(intbuff, length, 1, '0');
90
if (l_time->day >= 10 && l_time->day <= 19)
91
str->append(STRING_WITH_LEN("th"));
94
switch (l_time->day %10) {
96
str->append(STRING_WITH_LEN("st"));
99
str->append(STRING_WITH_LEN("nd"));
102
str->append(STRING_WITH_LEN("rd"));
105
str->append(STRING_WITH_LEN("th"));
111
length= int10_to_str(l_time->year, intbuff, 10) - intbuff;
112
str->append_with_prefill(intbuff, length, 4, '0');
115
length= int10_to_str(l_time->year%100, intbuff, 10) - intbuff;
116
str->append_with_prefill(intbuff, length, 2, '0');
119
length= int10_to_str(l_time->month, intbuff, 10) - intbuff;
120
str->append_with_prefill(intbuff, length, 2, '0');
123
length= int10_to_str(l_time->month, intbuff, 10) - intbuff;
124
str->append_with_prefill(intbuff, length, 1, '0');
127
length= int10_to_str(l_time->day, intbuff, 10) - intbuff;
128
str->append_with_prefill(intbuff, length, 2, '0');
131
length= int10_to_str(l_time->day, intbuff, 10) - intbuff;
132
str->append_with_prefill(intbuff, length, 1, '0');
135
length= int10_to_str(l_time->second_part, intbuff, 10) - intbuff;
136
str->append_with_prefill(intbuff, length, 6, '0');
139
length= int10_to_str(l_time->hour, intbuff, 10) - intbuff;
140
str->append_with_prefill(intbuff, length, 2, '0');
144
hours_i= (l_time->hour%24 + 11)%12+1;
145
length= int10_to_str(hours_i, intbuff, 10) - intbuff;
146
str->append_with_prefill(intbuff, length, 2, '0');
148
case 'i': /* minutes */
149
length= int10_to_str(l_time->minute, intbuff, 10) - intbuff;
150
str->append_with_prefill(intbuff, length, 2, '0');
153
if (type == DRIZZLE_TIMESTAMP_TIME)
155
length= int10_to_str(calc_daynr(l_time->year,l_time->month,
157
calc_daynr(l_time->year,1,1) + 1, intbuff, 10) - intbuff;
158
str->append_with_prefill(intbuff, length, 3, '0');
161
length= int10_to_str(l_time->hour, intbuff, 10) - intbuff;
162
str->append_with_prefill(intbuff, length, 1, '0');
165
hours_i= (l_time->hour%24 + 11)%12+1;
166
length= int10_to_str(hours_i, intbuff, 10) - intbuff;
167
str->append_with_prefill(intbuff, length, 1, '0');
170
hours_i= l_time->hour%24;
171
str->append(hours_i < 12 ? "AM" : "PM",2);
174
length= sprintf(intbuff,
175
((l_time->hour % 24) < 12) ?
176
"%02d:%02d:%02d AM" : "%02d:%02d:%02d PM",
177
(l_time->hour+11)%12+1,
180
str->append(intbuff, length);
184
length= int10_to_str(l_time->second, intbuff, 10) - intbuff;
185
str->append_with_prefill(intbuff, length, 2, '0');
188
length= sprintf(intbuff,
193
str->append(intbuff, length);
199
if (type == DRIZZLE_TIMESTAMP_TIME)
201
length= int10_to_str(calc_week(l_time,
203
WEEK_FIRST_WEEKDAY : WEEK_MONDAY_FIRST,
205
intbuff, 10) - intbuff;
206
str->append_with_prefill(intbuff, length, 2, '0');
213
if (type == DRIZZLE_TIMESTAMP_TIME)
215
length= int10_to_str(calc_week(l_time,
217
(WEEK_YEAR | WEEK_FIRST_WEEKDAY) :
218
(WEEK_YEAR | WEEK_MONDAY_FIRST)),
220
intbuff, 10) - intbuff;
221
str->append_with_prefill(intbuff, length, 2, '0');
228
if (type == DRIZZLE_TIMESTAMP_TIME)
230
(void) calc_week(l_time,
232
WEEK_YEAR | WEEK_FIRST_WEEKDAY :
233
WEEK_YEAR | WEEK_MONDAY_FIRST),
235
length= int10_to_str(year, intbuff, 10) - intbuff;
236
str->append_with_prefill(intbuff, length, 4, '0');
240
if (type == DRIZZLE_TIMESTAMP_TIME)
242
weekday=calc_weekday(calc_daynr(l_time->year,l_time->month,
244
length= int10_to_str(weekday, intbuff, 10) - intbuff;
245
str->append_with_prefill(intbuff, length, 1, '0');
25
257
void Item_func_date_format::fix_length_and_dec()
27
259
Session* session= current_session;