75
75
if (not temporal.from_string(from, (size_t) len))
77
my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
77
my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
110
110
ASSERT_COLUMN_MARKED_FOR_WRITE;
112
if (from < 0 || from > 99991231235959.0)
112
uint64_t from_tmp= (uint64_t)from;
113
type::Time::usec_t fractional_seconds= (type::Time::usec_t)((from - from_tmp) * type::Time::FRACTIONAL_DIGITS);
115
MicroTimestamp temporal;
116
if (not temporal.from_int64_t(from_tmp))
114
/* Convert the double to a string using stringstream */
115
std::stringstream ss;
117
ss.precision(18); /* 18 places should be fine for error display of double input. */
118
/* Convert the integer to a string using boost::lexical_cast */
119
std::string tmp(boost::lexical_cast<std::string>(from));
121
my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
121
my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
124
return Microtime::store((int64_t) rint(from), false);
126
temporal.to_time_t(tmp);
128
uint64_t tmp_micro= tmp;
130
pack_num(fractional_seconds, ptr +8);
135
int Microtime::store_decimal(const type::Decimal *value)
137
char buff[DECIMAL_MAX_STR_LENGTH+1];
139
String str(buff, sizeof(buff), &my_charset_bin);
140
class_decimal2string(E_DEC_FATAL_ERROR, value, 0, 0, 0, &str);
142
return store(str.ptr(), str.length(), str.charset());
127
145
int Microtime::store(int64_t from, bool)
134
152
/* Convert the integer to a string using boost::lexical_cast */
135
153
std::string tmp(boost::lexical_cast<std::string>(from));
137
my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
155
my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
151
169
double Microtime::val_real(void)
153
return (double) Microtime::val_int();
172
type::Time::usec_t micro_temp;
174
ASSERT_COLUMN_MARKED_FOR_READ;
177
unpack_num(micro_temp, ptr +8);
180
(void) temporal.from_time_t((time_t) temp);
182
/* We must convert into a "timestamp-formatted integer" ... */
184
temporal.to_int64_t(&result);
186
result+= micro_temp % type::Time::FRACTIONAL_DIGITS;
191
type::Decimal *Microtime::val_decimal(type::Decimal *decimal_value)
197
return date2_class_decimal(<ime, decimal_value);
156
200
int64_t Microtime::val_int(void)
209
253
unpack_num(temp);
210
254
unpack_num(micro_temp, ptr +8);
212
memset(ltime, 0, sizeof(*ltime));
214
258
Timestamp temporal;
215
259
(void) temporal.from_time_t((time_t) temp);
225
269
ltime->second= temporal.seconds();
226
270
ltime->second_part= temporal.useconds();
231
275
bool Microtime::get_time(type::Time *ltime)
233
return Microtime::get_date(ltime,0);
277
return Microtime::get_date(ltime, 0);
236
280
int Microtime::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
276
320
Session *session= getTable() ? getTable()->in_use : current_session;
278
uint32_t fractional_seconds= 0;
322
type::Time::usec_t fractional_seconds= 0;
279
323
uint64_t epoch_seconds= session->getCurrentTimestampEpoch(fractional_seconds);