~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal.cc

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:11:45 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114051145-xiputq4lvmtct377
storage engine docs. add bit about some temp table only engines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 * their single parameter.
35
35
 */
36
36
 
37
 
#include <config.h>
 
37
#include "config.h"
38
38
 
39
 
#include <drizzled/charset_info.h>
40
 
#include <drizzled/type/decimal.h>
41
 
#include <drizzled/calendar.h>
42
 
#include <drizzled/temporal.h>
43
 
#include <drizzled/temporal_format.h>
44
 
#include <drizzled/time_functions.h>
 
39
#include "drizzled/charset_info.h"
 
40
#include "drizzled/type/decimal.h"
 
41
#include "drizzled/calendar.h"
 
42
#include "drizzled/temporal.h"
 
43
#include "drizzled/temporal_format.h"
 
44
#include "drizzled/time_functions.h"
45
45
#include "time.h"
46
46
 
47
 
#include <drizzled/util/gmtime.h>
48
 
 
49
47
#include <time.h>
50
48
 
51
49
#include <cstdio>
61
59
extern std::vector<TemporalFormat *> known_date_formats;
62
60
extern std::vector<TemporalFormat *> known_time_formats;
63
61
 
64
 
Temporal::Temporal() :
65
 
  _calendar(GREGORIAN),
66
 
  _years(0),
67
 
  _months(0),
68
 
  _days(0),
69
 
  _hours(0),
70
 
  _minutes(0),
71
 
  _seconds(0),
72
 
  _epoch_seconds(0),
73
 
  _useconds(0),
74
 
  _nseconds(0),
75
 
  _overflow(false)
 
62
Temporal::Temporal()
 
63
:
 
64
  _calendar(GREGORIAN)
 
65
, _years(0)
 
66
, _months(0)
 
67
, _days(0)
 
68
, _hours(0)
 
69
, _minutes(0)
 
70
, _seconds(0)
 
71
, _epoch_seconds(0)
 
72
, _useconds(0)
 
73
, _nseconds(0)
 
74
, _overflow(false)
76
75
{}
77
76
 
78
77
uint64_t Temporal::_cumulative_seconds_in_time() const
101
100
        }
102
101
        
103
102
        // Get the gmtime based on the local seconds since the Epoch
104
 
        gm_time = util::gmtime(local_secs, &gm__rec);
 
103
        gm_time = gmtime_r(&local_secs, &gm__rec);
105
104
        gm_time->tm_isdst = 0;
106
105
        
107
106
        // Interpret gmtime as the local time and convert it to seconds since the Epoch
1291
1290
  struct tm broken_time;
1292
1291
  struct tm *result;
1293
1292
 
1294
 
  result= util::gmtime(from, &broken_time);
 
1293
  result= gmtime_r(&from, &broken_time);
1295
1294
  if (result != NULL)
1296
1295
  {
1297
1296
    _years= 0;
1315
1314
  struct tm broken_time;
1316
1315
  struct tm *result;
1317
1316
 
1318
 
  result= util::gmtime(from, &broken_time);
 
1317
  result= gmtime_r(&from, &broken_time);
1319
1318
  if (result != NULL)
1320
1319
  {
1321
1320
    _years= 1900 + broken_time.tm_year;
1339
1338
  struct tm broken_time;
1340
1339
  struct tm *result;
1341
1340
 
1342
 
  result= util::gmtime(timeval_arg.tv_sec, &broken_time);
 
1341
  result= gmtime_r(&timeval_arg.tv_sec, &broken_time);
1343
1342
  if (result != NULL)
1344
1343
  {
1345
1344
    _years= 1900 + broken_time.tm_year;
1365
1364
  struct tm broken_time;
1366
1365
  struct tm *result;
1367
1366
 
1368
 
  result= util::gmtime(from, &broken_time);
 
1367
  result= gmtime_r(&from, &broken_time);
1369
1368
  if (result != NULL)
1370
1369
  {
1371
1370
    _years= 1900 + broken_time.tm_year;
1418
1417
bool Date::is_valid() const
1419
1418
{
1420
1419
  return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1421
 
      && (_months >= 1 && _months <= DRIZZLE_MAX_MONTHS)
 
1420
      && (_months >= 1 && _months <= 12)
1422
1421
      && (_days >= 1 && _days <= days_in_gregorian_year_month(_years, _months));
1423
1422
}
1424
1423
 
1427
1426
  return (_years == 0)
1428
1427
      && (_months == 0)
1429
1428
      && (_days == 0)
1430
 
      && (_hours <= DRIZZLE_MAX_HOURS)
1431
 
      && (_minutes <= DRIZZLE_MAX_MINUTES)
1432
 
      && (_seconds <= DRIZZLE_MAX_SECONDS); /* No Leap second... TIME is for elapsed time... */
 
1429
      && (_hours <= 23)
 
1430
      && (_minutes <= 59)
 
1431
      && (_seconds <= 59); /* No Leap second... TIME is for elapsed time... */
1433
1432
}
1434
1433
 
1435
1434
bool Time::is_fuzzy_valid() const
1438
1437
    return true;
1439
1438
 
1440
1439
  return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1441
 
      && (_months >= 1 && _months <= DRIZZLE_MAX_MONTHS)
 
1440
      && (_months >= 1 && _months <= 12)
1442
1441
      && (_days >= 1 && _days <= days_in_gregorian_year_month(_years, _months))
1443
 
      && (_hours <= DRIZZLE_MAX_HOURS)
1444
 
      && (_minutes <= DRIZZLE_MAX_MINUTES)
1445
 
      && (_seconds <= DRIZZLE_MAX_SECONDS); /* No Leap second... TIME is for elapsed time... */
 
1442
      && (_hours <= 23)
 
1443
      && (_minutes <= 59)
 
1444
      && (_seconds <= 59); /* No Leap second... TIME is for elapsed time... */
1446
1445
}
1447
1446
 
1448
1447
bool DateTime::is_valid() const
1449
1448
{
1450
1449
  return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1451
 
      && (_months >= 1 && _months <= DRIZZLE_MAX_MONTHS)
 
1450
      && (_months >= 1 && _months <= 12)
1452
1451
      && (_days >= 1 && _days <= days_in_gregorian_year_month(_years, _months))
1453
 
      && (_hours <= DRIZZLE_MAX_HOURS)
1454
 
      && (_minutes <= DRIZZLE_MAX_MINUTES)
1455
 
      && (_seconds <= DRIZZLE_MAX_SECONDS_WITH_LEAP); /* Leap second... */
 
1452
      && (_hours <= 23)
 
1453
      && (_minutes <= 59)
 
1454
      && (_seconds <= 61); /* Leap second... */
1456
1455
}
1457
1456
 
1458
1457
bool Timestamp::is_valid() const
1459
1458
{
1460
 
  return DateTime::is_valid()
 
1459
  return DateTime::is_valid() 
1461
1460
      && in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds)
1462
 
      && (_seconds <= DRIZZLE_MAX_SECONDS);
 
1461
      && (_seconds <= 59);
1463
1462
}
1464
1463
 
1465
1464
bool MicroTimestamp::is_valid() const