~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/microtime.cc

  • Committer: Brian Aker
  • Date: 2011-01-21 20:42:14 UTC
  • mto: This revision was merged to the branch mainline in revision 2103.
  • Revision ID: brian@tangent.org-20110121204214-gqzojh2q9mko1nqx
Isolate out the time code/conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
#include <boost/lexical_cast.hpp>
23
23
#include <drizzled/field/microtime.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/tztime.h>
26
26
#include <drizzled/table.h>
27
27
#include <drizzled/session.h>
28
 
#include <drizzled/current_session.h>
29
28
 
30
29
#include <math.h>
31
30
 
33
32
 
34
33
#include <boost/date_time/posix_time/posix_time.hpp>
35
34
 
36
 
#include <drizzled/temporal.h>
 
35
#include "drizzled/temporal.h"
37
36
 
38
37
namespace drizzled
39
38
{
91
90
  return 0;
92
91
}
93
92
 
94
 
int Microtime::store_time(type::Time &ltime, type::timestamp_t )
 
93
int Microtime::store_time(type::Time *ltime, type::timestamp_t )
95
94
{
96
95
  long my_timezone;
97
96
  bool in_dst_time_gap;
98
97
 
99
 
  type::Time::epoch_t time_tmp;
100
 
  ltime.convert(time_tmp, &my_timezone, &in_dst_time_gap, true);
 
98
  type::Time::epoch_t time_tmp= my_system_gmt_sec(ltime, &my_timezone, &in_dst_time_gap, true);
101
99
  uint64_t tmp_seconds= time_tmp;
102
 
  uint32_t tmp_micro= ltime.second_part;
 
100
  uint32_t tmp_micro= ltime->second_part;
103
101
 
104
102
  pack_num(tmp_seconds);
105
103
  pack_num(tmp_micro, ptr +8);
158
156
  return 0;
159
157
}
160
158
 
161
 
double Microtime::val_real(void) const
 
159
double Microtime::val_real(void)
162
160
{
163
161
  uint64_t temp;
164
162
  type::Time::usec_t micro_temp;
180
178
  return result;
181
179
}
182
180
 
183
 
type::Decimal *Microtime::val_decimal(type::Decimal *decimal_value) const
 
181
type::Decimal *Microtime::val_decimal(type::Decimal *decimal_value)
184
182
{
185
183
  type::Time ltime;
186
184
 
187
 
  get_date(ltime, 0);
 
185
  get_date(&ltime, 0);
188
186
 
189
187
  return date2_class_decimal(&ltime, decimal_value);
190
188
}
191
189
 
192
 
int64_t Microtime::val_int(void) const
 
190
int64_t Microtime::val_int(void)
193
191
{
194
192
  uint64_t temp;
195
193
 
207
205
  return result;
208
206
}
209
207
 
210
 
String *Microtime::val_str(String *val_buffer, String *) const
 
208
String *Microtime::val_str(String *val_buffer, String *)
211
209
{
212
210
  uint64_t temp= 0;
213
211
  type::Time::usec_t micro_temp= 0;
224
222
  return val_buffer;
225
223
}
226
224
 
227
 
bool Microtime::get_date(type::Time &ltime, uint32_t) const
 
225
bool Microtime::get_date(type::Time *ltime, uint32_t)
228
226
{
229
227
  uint64_t temp;
230
228
  uint32_t micro_temp= 0;
232
230
  unpack_num(temp);
233
231
  unpack_num(micro_temp, ptr +8);
234
232
  
235
 
  ltime.reset();
 
233
  ltime->reset();
236
234
 
237
 
  ltime.store(temp, micro_temp);
 
235
  ltime->store(temp, micro_temp);
238
236
 
239
237
  return false;
240
238
}
241
239
 
242
 
bool Microtime::get_time(type::Time &ltime) const
 
240
bool Microtime::get_time(type::Time *ltime)
243
241
{
244
242
  return Microtime::get_date(ltime, 0);
245
243
}
294
292
  pack_num(fractional_seconds, ptr +8);
295
293
}
296
294
 
297
 
long Microtime::get_timestamp(bool *null_value) const
 
295
long Microtime::get_timestamp(bool *null_value)
298
296
{
299
297
  if ((*null_value= is_null()))
300
298
    return 0;