~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2011-01-06 20:35:26 UTC
  • mto: This revision was merged to the branch mainline in revision 2064.
  • Revision ID: brian@tangent.org-20110106203526-p9k1sub71wqajv7y
We no longer look at the sign of a timestamp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
22
#include <drizzled/function/time/now.h>
23
 
#include <drizzled/current_session.h>
24
23
#include <drizzled/session.h>
25
24
 
26
 
#include <drizzled/temporal.h>
 
25
#include "drizzled/temporal.h"
27
26
 
28
27
namespace drizzled
29
28
{
32
31
{
33
32
  assert(fixed == 1);
34
33
  str_value.set(buff, buff_length, &my_charset_bin);
35
 
 
36
34
  return &str_value;
37
35
}
38
36
 
42
40
  decimals= DATETIME_DEC;
43
41
  collation.set(&my_charset_bin);
44
42
  
45
 
  ltime.reset();
46
 
 
47
 
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
48
 
 
49
 
  store_now_in_TIME(ltime);
50
 
 
51
 
  ltime.convert(value);
52
 
 
53
 
  size_t length= type::Time::MAX_STRING_LENGTH;
54
 
  ltime.convert(buff, length);
55
 
 
56
 
  max_length= buff_length= length;
 
43
  memset(&ltime, 0, sizeof(type::Time));
 
44
 
 
45
  ltime.time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
46
 
 
47
  store_now_in_TIME(&ltime);
 
48
  value= (int64_t) TIME_to_uint64_t_datetime(&ltime);
 
49
 
 
50
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
 
51
  max_length= buff_length;
57
52
}
58
53
 
59
54
/**
60
55
    Converts current time in time_t to type::Time represenatation for local
61
56
    time zone. Defines time zone (local) used for whole NOW function.
62
57
*/
63
 
void Item_func_now_local::store_now_in_TIME(type::Time &now_time)
 
58
void Item_func_now_local::store_now_in_TIME(type::Time *now_time)
64
59
{
65
60
  Session *session= current_session;
66
 
  uint32_t fractional_seconds= 0;
67
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
68
 
 
69
 
#if 0
70
 
  now_time->store(tmp, fractional_seconds, true);
71
 
#endif
72
 
  now_time.store(tmp, fractional_seconds);
 
61
  time_t tmp= session->getCurrentTimestampEpoch();
 
62
 
 
63
  (void) cached_temporal.from_time_t(tmp);
 
64
 
 
65
  now_time->year= cached_temporal.years();
 
66
  now_time->month= cached_temporal.months();
 
67
  now_time->day= cached_temporal.days();
 
68
  now_time->hour= cached_temporal.hours();
 
69
  now_time->minute= cached_temporal.minutes();
 
70
  now_time->second= cached_temporal.seconds();
73
71
}
74
72
 
75
73
 
77
75
    Converts current time in time_t to type::Time represenatation for UTC
78
76
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
79
77
*/
80
 
void Item_func_now_utc::store_now_in_TIME(type::Time &now_time)
 
78
void Item_func_now_utc::store_now_in_TIME(type::Time *now_time)
81
79
{
82
80
  Session *session= current_session;
83
 
  uint32_t fractional_seconds= 0;
84
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
85
 
 
86
 
  now_time.store(tmp, fractional_seconds);
 
81
  time_t tmp= session->getCurrentTimestampEpoch();
 
82
 
 
83
  (void) cached_temporal.from_time_t(tmp);
 
84
 
 
85
  now_time->year= cached_temporal.years();
 
86
  now_time->month= cached_temporal.months();
 
87
  now_time->day= cached_temporal.days();
 
88
  now_time->hour= cached_temporal.hours();
 
89
  now_time->minute= cached_temporal.minutes();
 
90
  now_time->second= cached_temporal.seconds();
87
91
}
88
92
 
89
93
bool Item_func_now::get_temporal(DateTime &to)
92
96
  return true;
93
97
}
94
98
 
95
 
bool Item_func_now::get_date(type::Time &res, uint32_t )
 
99
bool Item_func_now::get_date(type::Time *res,
 
100
                             uint32_t )
96
101
{
97
 
  res= ltime;
 
102
  *res= ltime;
98
103
  return 0;
99
104
}
100
105
 
102
107
int Item_func_now::save_in_field(Field *to, bool )
103
108
{
104
109
  to->set_notnull();
105
 
  return to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
 
110
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
106
111
}
107
112
 
108
113
} /* namespace drizzled */