~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/unix_timestamp.cc

  • Committer: Monty Taylor
  • Date: 2009-03-05 02:06:48 UTC
  • mfrom: (907.1.8 trunk-with-temporal)
  • mto: This revision was merged to the branch mainline in revision 912.
  • Revision ID: mordred@inaugust.com-20090305020648-7jk1gie4lqsi22g8
Merged from Jay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/field/timestamp.h>
24
24
#include <drizzled/session.h>
25
25
 
 
26
#include "drizzled/temporal.h"
 
27
 
26
28
int64_t Item_func_unix_timestamp::val_int()
27
29
{
28
30
  DRIZZLE_TIME ltime;
29
 
  bool not_used;
30
31
 
31
32
  assert(fixed == 1);
32
33
  if (arg_count == 0)
49
50
    return 0;
50
51
  }
51
52
 
52
 
  return (int64_t) TIME_to_timestamp(current_session, &ltime, &not_used);
 
53
  drizzled::Timestamp temporal;
 
54
 
 
55
  temporal.set_years(ltime.year);
 
56
  temporal.set_months(ltime.month);
 
57
  temporal.set_days(ltime.day);
 
58
  temporal.set_hours(ltime.hour);
 
59
  temporal.set_minutes(ltime.minute);
 
60
  temporal.set_seconds(ltime.second);
 
61
  temporal.set_epoch_seconds();
 
62
 
 
63
  if (! temporal.is_valid())
 
64
  {
 
65
    null_value= true;
 
66
    char buff[MAX_DATETIME_WIDTH];
 
67
    size_t buff_len;
 
68
    temporal.to_string(buff, &buff_len);
 
69
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(0), buff);
 
70
    return 0;
 
71
  }
 
72
 
 
73
  time_t tmp;
 
74
  temporal.to_time_t(&tmp);
 
75
 
 
76
  return (int64_t) tmp;
53
77
}
54