214
214
int64_t Field_timestamp::val_int(void)
217
DRIZZLE_TIME time_tmp;
218
Session *session= table ? table->in_use : current_session;
220
218
#ifdef WORDS_BIGENDIAN
221
219
if (table && table->s->db_low_byte_first)
220
temp= uint4korr(ptr);
227
if (temp == 0L) // No time
228
return(0); /* purecov: inspected */
230
session->variables.time_zone->gmt_sec_to_TIME(&time_tmp, (time_t)temp);
232
return time_tmp.year * INT64_C(10000000000) +
233
time_tmp.month * INT64_C(100000000) +
234
time_tmp.day * 1000000 + time_tmp.hour * 10000 +
235
time_tmp.minute * 100 + time_tmp.second;
225
drizzled::Timestamp temporal;
226
(void) temporal.from_time_t((time_t) temp);
228
/* We must convert into a "timestamp-formatted integer" ... */
230
temporal.to_int64_t(&result);
238
String *Field_timestamp::val_str(String *val_buffer, String *val_ptr)
234
String *Field_timestamp::val_str(String *val_buffer, String *)
240
uint32_t temp, temp2;
241
DRIZZLE_TIME time_tmp;
242
Session *session= table ? table->in_use : current_session;
245
val_buffer->alloc(field_length+1);
246
to= (char*) val_buffer->ptr();
247
val_buffer->length(field_length);
239
val_buffer->alloc(field_length + 1);
240
to= (char *) val_buffer->ptr();
249
242
#ifdef WORDS_BIGENDIAN
250
243
if (table && table->s->db_low_byte_first)
244
temp= uint4korr(ptr);
257
{ /* Zero time is "000000" */
258
val_ptr->set(STRING_WITH_LEN("0000-00-00 00:00:00"), &my_charset_bin);
261
val_buffer->set_charset(&my_charset_bin); // Safety
263
session->variables.time_zone->gmt_sec_to_TIME(&time_tmp,(time_t)temp);
265
temp= time_tmp.year % 100;
266
if (temp < YY_PART_YEAR - 1)
276
temp2=temp/10; temp=temp-temp2*10;
277
*to++= (char) ('0'+(char) (temp2));
278
*to++= (char) ('0'+(char) (temp));
281
temp2=temp/10; temp=temp-temp2*10;
282
*to++= (char) ('0'+(char) (temp2));
283
*to++= (char) ('0'+(char) (temp));
286
temp2=temp/10; temp=temp-temp2*10;
287
*to++= (char) ('0'+(char) (temp2));
288
*to++= (char) ('0'+(char) (temp));
291
temp2=temp/10; temp=temp-temp2*10;
292
*to++= (char) ('0'+(char) (temp2));
293
*to++= (char) ('0'+(char) (temp));
295
temp=time_tmp.minute;
296
temp2=temp/10; temp=temp-temp2*10;
297
*to++= (char) ('0'+(char) (temp2));
298
*to++= (char) ('0'+(char) (temp));
300
temp=time_tmp.second;
301
temp2=temp/10; temp=temp-temp2*10;
302
*to++= (char) ('0'+(char) (temp2));
303
*to++= (char) ('0'+(char) (temp));
249
val_buffer->set_charset(&my_charset_bin); /* Safety */
251
drizzled::Timestamp temporal;
252
(void) temporal.from_time_t((time_t) temp);
255
temporal.to_string(to, &to_len);
256
val_buffer->length((uint32_t) to_len);
305
257
return val_buffer;
308
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
260
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t)
311
Session *session= table ? table->in_use : current_session;
312
264
#ifdef WORDS_BIGENDIAN
313
265
if (table && table->s->db_low_byte_first)
266
temp= uint4korr(ptr);
319
{ /* Zero time is "000000" */
320
if (fuzzydate & TIME_NO_ZERO_DATE)
322
memset(ltime, 0, sizeof(*ltime));
326
session->variables.time_zone->gmt_sec_to_TIME(ltime, (time_t)temp);
271
memset(ltime, 0, sizeof(*ltime));
273
drizzled::Timestamp temporal;
274
(void) temporal.from_time_t((time_t) temp);
276
/* @TODO Goodbye the below code when DRIZZLE_TIME is finally gone.. */
278
ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
279
ltime->year= temporal.years();
280
ltime->month= temporal.months();
281
ltime->day= temporal.days();
282
ltime->hour= temporal.hours();
283
ltime->minute= temporal.minutes();
284
ltime->second= temporal.seconds();