~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal.cc

Merge Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
1184
1184
    return is_valid();
1185
1185
}
1186
1186
 
1187
 
void Time::to_string(char *to, size_t *to_len) const
1188
 
{
1189
 
  *to_len= sprintf(to
1190
 
                 , "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32
1191
 
                 , _hours
1192
 
                 , _minutes
1193
 
                 , _seconds);
1194
 
}
1195
 
 
1196
 
void Date::to_string(char *to, size_t *to_len) const
1197
 
{
1198
 
  *to_len= sprintf(to
1199
 
                 , "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
1200
 
                 , _years
1201
 
                 , _months
1202
 
                 , _days);
1203
 
}
1204
 
 
1205
 
void DateTime::to_string(char *to, size_t *to_len) const
 
1187
int Time::to_string(char *to, size_t to_len) const
 
1188
{
 
1189
  return snprintf(to, to_len,
 
1190
                  "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
 
1191
                  _hours, _minutes, _seconds);
 
1192
}
 
1193
 
 
1194
int Date::to_string(char *to, size_t to_len) const
 
1195
{
 
1196
  return snprintf(to, to_len,
 
1197
                  "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32,
 
1198
                  _years, _months, _days);
 
1199
}
 
1200
 
 
1201
int DateTime::to_string(char *to, size_t to_len) const
1206
1202
{
1207
1203
  /* If the temporal has a microsecond component, use a slightly different output */
1208
1204
  if (_useconds == 0)
1209
1205
  {
1210
 
    *to_len= sprintf(to
1211
 
                  , "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32
1212
 
                  , _years
1213
 
                  , _months
1214
 
                  , _days
1215
 
                  , _hours
1216
 
                  , _minutes
1217
 
                  , _seconds);
 
1206
    return snprintf(to, to_len,
 
1207
                    "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
 
1208
                          " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
 
1209
                    _years, _months, _days,
 
1210
                    _hours, _minutes, _seconds);
1218
1211
  }
1219
1212
  else
1220
1213
  {
1221
 
    *to_len= sprintf(to
1222
 
                  , "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32
1223
 
                  , _years
1224
 
                  , _months
1225
 
                  , _days
1226
 
                  , _hours
1227
 
                  , _minutes
1228
 
                  , _seconds
1229
 
                  , _useconds);
 
1214
    return snprintf(to, to_len,
 
1215
                    "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
 
1216
                       " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
 
1217
                    _years, _months, _days,
 
1218
                    _hours, _minutes, _seconds, _useconds);
1230
1219
  }
1231
1220
}
1232
1221
 
1233
 
void MicroTimestamp::to_string(char *to, size_t *to_len) const
 
1222
int MicroTimestamp::to_string(char *to, size_t to_len) const
1234
1223
{
1235
 
  *to_len= sprintf(to
1236
 
                 , "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32
1237
 
                 , _years
1238
 
                 , _months
1239
 
                 , _days
1240
 
                 , _hours
1241
 
                 , _minutes
1242
 
                 , _seconds
1243
 
                 , _useconds);
 
1224
  return snprintf(to, to_len,
 
1225
                  "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
 
1226
                      " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
 
1227
                  _years, _months, _days,
 
1228
                  _hours, _minutes, _seconds, _useconds);
1244
1229
}
1245
1230
 
1246
1231
void Time::to_decimal(my_decimal *to) const
1364
1349
 * This is pretty much a hack for usability, but keeps us compatible
1365
1350
 * with MySQL.
1366
1351
 */
1367
 
bool DateTime::from_int64_t(const int64_t from)
 
1352
bool DateTime::from_int64_t(const int64_t from, bool convert)
1368
1353
{
1369
1354
  int64_t copy_from= from;
1370
1355
  int64_t part1;
1373
1358
  if (copy_from == 0LL)
1374
1359
    return false;
1375
1360
 
1376
 
  if (copy_from < 10000101000000LL)
 
1361
  if (convert && copy_from < 10000101000000LL)
1377
1362
  {
1378
1363
    if (copy_from < 101)
1379
1364
      return false;