~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal.cc

Reverted 1103

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  Authors:
7
7
 *
34
34
 * their single parameter.
35
35
 */
36
36
 
37
 
#include "config.h"
 
37
#include "drizzled/global.h"
38
38
 
39
 
#include "drizzled/charset_info.h"
40
 
#include "drizzled/type/decimal.h"
 
39
#include "mystrings/m_ctype.h"
 
40
#include "drizzled/my_decimal.h"
41
41
#include "drizzled/calendar.h"
42
42
#include "drizzled/temporal.h"
 
43
#ifdef NOTYETIMPLEMENTED
 
44
#include "drizzled/temporal_interval.h"
 
45
#endif
43
46
#include "drizzled/temporal_format.h"
44
 
#include "drizzled/time_functions.h"
45
47
#include "time.h"
46
48
 
47
 
#include <drizzled/util/gmtime.h>
48
 
 
49
 
#include <time.h>
50
 
 
51
 
#include <cstdio>
52
49
#include <ostream>
53
50
#include <iomanip>
54
51
#include <vector>
55
52
#include <string.h>
56
53
 
 
54
extern std::vector<drizzled::TemporalFormat *> known_datetime_formats;
 
55
extern std::vector<drizzled::TemporalFormat *> known_date_formats;
 
56
extern std::vector<drizzled::TemporalFormat *> known_time_formats;
 
57
 
57
58
namespace drizzled 
58
59
{
59
60
 
60
 
extern std::vector<TemporalFormat *> known_datetime_formats;
61
 
extern std::vector<TemporalFormat *> known_date_formats;
62
 
extern std::vector<TemporalFormat *> known_time_formats;
63
 
 
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)
 
61
Temporal::Temporal()
 
62
:
 
63
  _calendar(GREGORIAN)
 
64
, _years(0)
 
65
, _months(0)
 
66
, _days(0)
 
67
, _hours(0)
 
68
, _minutes(0)
 
69
, _seconds(0)
 
70
, _epoch_seconds(0)
 
71
, _useconds(0)
 
72
, _nseconds(0)
 
73
, _overflow(false)
76
74
{}
77
75
 
78
76
uint64_t Temporal::_cumulative_seconds_in_time() const
82
80
      + _seconds);
83
81
}
84
82
 
85
 
#if defined(TARGET_OS_SOLARIS)
86
 
/* @TODO: Replace this with Boost.DateTime */
87
 
static time_t timegm(struct tm *my_time)
88
 
{
89
 
        time_t local_secs, gm_secs;
90
 
        struct tm gm__rec, *gm_time;
91
 
 
92
 
        // Interpret 't' as the local time and convert it to seconds since the Epoch
93
 
        local_secs = mktime(my_time);
94
 
        if (local_secs == -1)
95
 
  {
96
 
                my_time->tm_hour--;
97
 
                local_secs = mktime (my_time);
98
 
                if (local_secs == -1)
99
 
                        return -1; 
100
 
                local_secs += 3600;
101
 
        }
102
 
        
103
 
        // Get the gmtime based on the local seconds since the Epoch
104
 
        gm_time = util::gmtime(local_secs, &gm__rec);
105
 
        gm_time->tm_isdst = 0;
106
 
        
107
 
        // Interpret gmtime as the local time and convert it to seconds since the Epoch
108
 
        gm_secs = mktime (gm_time);
109
 
        if (gm_secs == -1)
110
 
  {
111
 
                gm_time->tm_hour--;
112
 
                gm_secs = mktime (gm_time);
113
 
                if (gm_secs == -1)
114
 
                        return -1; 
115
 
                gm_secs += 3600;
116
 
        }
117
 
        
118
 
        // Return the local time adjusted by the difference from GM time.
119
 
        return (local_secs - (gm_secs - local_secs));
120
 
}
121
 
#endif
122
 
 
123
83
void Temporal::set_epoch_seconds()
124
84
{
125
85
  /* 
154
114
  TemporalFormat *current_format;
155
115
  std::vector<TemporalFormat *>::iterator current= known_date_formats.begin();
156
116
 
157
 
  _useconds= 0; // We may not match on it, so we need to make sure we zero it out.
158
117
  while (current != known_date_formats.end())
159
118
  {
160
119
    current_format= *current;
244
203
 * This operator is called in the following situation:
245
204
 *
246
205
 * @code
247
 
 * Time lhs;
 
206
 * drizzled::Time lhs;
248
207
 * lhs.from_string("20:00:00");
249
 
 * Time rhs;
 
208
 * drizzled::Time rhs;
250
209
 * rhs.from_string("19:00:00");
251
210
 *
252
 
 * Time result= lhs - rhs;
 
211
 * drizzled::Time result= lhs - rhs;
253
212
 * @endcode
254
213
 *
255
214
 * @note
833
792
 
834
793
  return *this;
835
794
}
836
 
 
 
795
#ifdef NOTYETIMPLEMENTED
 
796
Date& Date::operator+=(const TemporalIntervalYear &rhs)
 
797
{
 
798
  /* Simple one...add the years and adjust for any leaps */
 
799
  int64_t new_years= _years;
 
800
  new_years+= rhs._years;
 
801
  if (new_years > DRIZZLE_MAX_YEARS_SQL)
 
802
  {
 
803
    /* 
 
804
     * Set everything to zero. We got an overflow.
 
805
     * @TODO Exceptions would be great here...
 
806
     */
 
807
    _reset();
 
808
    _overflow= true;
 
809
    return *this;
 
810
  }
 
811
  _years= (uint32_t) new_years;
 
812
  if (_months == 2 && _days == 29 && days_in_gregorian_year_month(_years, _months) != 366)
 
813
    _days= 28;
 
814
  return *this;
 
815
 
816
 
 
817
Date& Date::operator-=(const TemporalIntervalYear &rhs)
 
818
{
 
819
  /* Simple one...subtract the years and adjust for any leaps */
 
820
  int64_t new_years= _years;
 
821
  new_years-= rhs._years;
 
822
  if (new_years < 0)
 
823
  {
 
824
    /* 
 
825
     * Set everything to zero. We got an overflow.
 
826
     * @TODO Exceptions would be great here...
 
827
     */
 
828
    _reset();
 
829
    _overflow= true;
 
830
    return *this;
 
831
  }
 
832
  _years= (uint32_t) new_years;
 
833
  if (_months == 2 && _days == 29 && days_in_gregorian_year_month(_years, _months) != 366)
 
834
    _days= 28;
 
835
  return *this;
 
836
 
837
 
 
838
Date& Date::operator+=(const TemporalIntervalDayOrWeek &rhs)
 
839
{
 
840
  /* Simple one...add the days */
 
841
  int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, _days) + rhs._days;
 
842
  gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
 
843
  return *this;
 
844
 
845
 
 
846
Date& Date::operator-=(const TemporalIntervalDayOrWeek &rhs)
 
847
{
 
848
  /* Simple one...subtract the days */
 
849
  int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, _days) - rhs._days;
 
850
  gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
 
851
  return *this;
 
852
 
853
 
 
854
Date& Date::operator+=(const TemporalIntervalYearMonth &rhs)
 
855
{
 
856
  /* Simple one...add the months in the period adjust */
 
857
  int64_t period= (_years * 12) + (rhs._years * 12) + (_months - 1) + rhs._months;
 
858
  int64_t new_years= (period / 12);
 
859
  if (new_years > DRIZZLE_MAX_YEARS_SQL)
 
860
  {
 
861
    /* 
 
862
     * Set everything to zero. We got an overflow.
 
863
     * @TODO Exceptions would be great here...
 
864
     */
 
865
    _reset();
 
866
    _overflow= true;
 
867
    return *this;
 
868
  }
 
869
  _years= (uint32_t) new_years;
 
870
  _months= (uint32_t) (period % 12) + 1;
 
871
  
 
872
  /* Adjust day if the new month doesn't have enough days */
 
873
  uint32_t days_in_new_month= days_in_gregorian_year_month(_years, _months);
 
874
  if (_days > days_in_new_month)
 
875
    _days= days_in_new_month;
 
876
  return *this;
 
877
 
878
 
 
879
Date& Date::operator-=(const TemporalIntervalYearMonth &rhs)
 
880
{
 
881
  /* Simple one...subtract the months in the period and adjust */
 
882
  int64_t period= (_years * 12) - (rhs._years * 12) + (_months - 1) - rhs._months;
 
883
  int64_t new_years= (period / 12);
 
884
  if (new_years < 0)
 
885
  {
 
886
    /* 
 
887
     * Set everything to zero. We got an overflow.
 
888
     * @TODO Exceptions would be great here...
 
889
     */
 
890
    _reset();
 
891
    _overflow= true;
 
892
    return *this;
 
893
  }
 
894
  _years= (uint32_t) (period / 12);
 
895
  _months= (uint32_t) (period % 12) + 1;
 
896
  
 
897
  /* Adjust day if the new month doesn't have enough days */
 
898
  uint32_t days_in_new_month= days_in_gregorian_year_month(_years, _months);
 
899
  if (_days > days_in_new_month)
 
900
    _days= days_in_new_month;
 
901
  return *this;
 
902
 
903
 
 
904
Date& Date::operator+=(const TemporalIntervalDayOrLess &rhs)
 
905
{
 
906
  /* 
 
907
   * Convert the temporal and the interval into a number of 
 
908
   * microseconds, then add them together and convert the
 
909
   * resulting microseconds back into a broken-down temporal
 
910
   * component.
 
911
   */
 
912
  int64_t new_seconds;
 
913
  int64_t new_microseconds;
 
914
  int64_t extra_sec;
 
915
  int64_t new_days;
 
916
  new_microseconds= _useconds + rhs._useconds;
 
917
  extra_sec= new_microseconds / INT64_C(1000000);
 
918
  new_microseconds= new_microseconds % INT64_C(1000000);
 
919
 
 
920
  new_seconds= ((_days - 1) * 3600 * 24) + (_hours * 3600) + (_minutes * 60) + _seconds;
 
921
  new_seconds+= (rhs._days * 3600 * 24) + (rhs._hours * 3600) + (rhs._minutes * 60) + rhs._seconds;
 
922
  new_seconds+= extra_sec;
 
923
 
 
924
  if (new_microseconds < 0)
 
925
  {
 
926
    new_microseconds+= INT64_C(1000000);
 
927
    new_seconds--;
 
928
  }
 
929
  
 
930
  new_days= new_seconds / (3600 * 24L);
 
931
  new_seconds-= new_days * 3600 * 24L;
 
932
  if (new_seconds < 0)
 
933
  {
 
934
    new_days--;
 
935
    new_seconds+= 3600 * 24L;
 
936
  }
 
937
  _useconds= (uint32_t) new_microseconds;
 
938
  _seconds= (uint32_t) (new_seconds % 60);
 
939
  _minutes= (uint32_t) ((new_seconds / 60) % 60);
 
940
  _hours= (uint32_t) (new_seconds / 3600);
 
941
  int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, 1) + new_days;
 
942
  gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
 
943
  return *this;
 
944
}
 
945
 
 
946
Date& Date::operator-=(const TemporalIntervalDayOrLess &rhs)
 
947
{
 
948
  /* 
 
949
   * Convert the temporal and the interval into a number of 
 
950
   * microseconds, then subtract them from each other and convert 
 
951
   * the resulting microseconds back into a broken-down temporal
 
952
   * component.
 
953
   */
 
954
  int64_t new_seconds;
 
955
  int64_t new_microseconds;
 
956
  int64_t extra_sec;
 
957
  int64_t new_days;
 
958
  new_microseconds= _useconds - rhs._useconds;
 
959
  extra_sec= new_microseconds / INT64_C(1000000);
 
960
  new_microseconds= new_microseconds % INT64_C(1000000);
 
961
 
 
962
  new_seconds= ((_days - 1) * 3600 * 24) + (_hours * 3600) + (_minutes * 60) + _seconds;
 
963
  new_seconds-= (rhs._days * 3600 * 24) + (rhs._hours * 3600) + (rhs._minutes * 60) + rhs._seconds;
 
964
  new_seconds+= extra_sec;
 
965
 
 
966
  if (new_microseconds < 0)
 
967
  {
 
968
    new_microseconds+= INT64_C(1000000);
 
969
    new_seconds--;
 
970
  }
 
971
  
 
972
  new_days= new_seconds / (3600 * 24L);
 
973
  new_seconds-= new_days * 3600 * 24L;
 
974
  if (new_seconds < 0)
 
975
  {
 
976
    new_days--;
 
977
    new_seconds+= 3600 * 24L;
 
978
  }
 
979
  _useconds= (uint32_t) new_microseconds;
 
980
  _seconds= (uint32_t) (new_seconds % 60);
 
981
  _minutes= (uint32_t) ((new_seconds / 60) % 60);
 
982
  _hours= (uint32_t) (new_seconds / 3600);
 
983
  int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, 1) + new_days;
 
984
  gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
 
985
  return *this;
 
986
}
 
987
#endif /* NOTYETIMPLEMENTED */
837
988
/*
838
989
 * Comparison operators between a Date and a Timestamp
839
990
 */
865
1016
}
866
1017
bool Date::operator>(const Timestamp& rhs)
867
1018
{
868
 
  return ! (*this <= rhs);
 
1019
  return ! (*this < rhs);
869
1020
}
870
1021
bool Date::operator>=(const Timestamp& rhs)
871
1022
{
872
 
  return ! (*this < rhs);
 
1023
  return ! (*this <= rhs);
873
1024
}
874
1025
/*
875
1026
 * Comparison operators between a Timestamp and a Date
902
1053
}
903
1054
bool Timestamp::operator>(const Date& rhs)
904
1055
{
905
 
  return ! (*this <= rhs);
 
1056
  return ! (*this < rhs);
906
1057
}
907
1058
bool Timestamp::operator>=(const Date& rhs)
908
1059
{
909
 
  return ! (*this < rhs);
 
1060
  return ! (*this <= rhs);
910
1061
}
911
1062
/*
912
1063
 * Comparison operators between a Timestamp and a DateTime
955
1106
}
956
1107
bool Timestamp::operator>(const DateTime& rhs)
957
1108
{
958
 
  return ! (*this <= rhs);
 
1109
  return ! (*this < rhs);
959
1110
}
960
1111
bool Timestamp::operator>=(const DateTime& rhs)
961
1112
{
962
 
  return ! (*this < rhs);
 
1113
  return ! (*this <= rhs);
963
1114
}
964
1115
/*
965
1116
 * Comparison operators between two Timestamps
982
1133
}
983
1134
bool Timestamp::operator>(const Timestamp& rhs)
984
1135
{
985
 
  return ! (*this <= rhs);
 
1136
  return ! (*this < rhs);
986
1137
}
987
1138
bool Timestamp::operator>=(const Timestamp& rhs)
988
1139
{
989
 
  return ! (*this < rhs);
 
1140
  return ! (*this <= rhs);
990
1141
}
991
1142
 
992
1143
/**
1027
1178
    current++;
1028
1179
  }
1029
1180
 
1030
 
  if (not matched)
 
1181
  if (! matched)
1031
1182
    return false;
1032
 
 
1033
 
  return is_fuzzy_valid();
 
1183
  else
 
1184
    return is_valid();
1034
1185
}
1035
1186
 
1036
1187
int Time::to_string(char *to, size_t to_len) const
1071
1222
int MicroTimestamp::to_string(char *to, size_t to_len) const
1072
1223
{
1073
1224
  return snprintf(to, to_len,
1074
 
                  "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
1075
 
                  " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
1076
 
                  _years, _months, _days,
1077
 
                  _hours, _minutes, _seconds, _useconds);
 
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);
1078
1229
}
1079
1230
 
1080
 
void Time::to_decimal(type::Decimal *to) const
 
1231
void Time::to_decimal(my_decimal *to) const
1081
1232
{
1082
1233
  int64_t time_portion= (((_hours * 100L) + _minutes) * 100L) + _seconds;
1083
 
  (void) int2_class_decimal(E_DEC_FATAL_ERROR, time_portion, false, to);
 
1234
  (void) int2my_decimal(E_DEC_FATAL_ERROR, time_portion, false, to);
1084
1235
  if (_useconds > 0)
1085
1236
  {
1086
1237
    to->buf[(to->intg-1) / 9 + 1]= _useconds * 1000;
1088
1239
  }
1089
1240
}
1090
1241
 
1091
 
void Date::to_decimal(type::Decimal *to) const
 
1242
void Date::to_decimal(my_decimal *to) const
1092
1243
{
1093
1244
  int64_t date_portion= (((_years * 100L) + _months) * 100L) + _days;
1094
 
  (void) int2_class_decimal(E_DEC_FATAL_ERROR, date_portion, false, to);
 
1245
  (void) int2my_decimal(E_DEC_FATAL_ERROR, date_portion, false, to);
1095
1246
}
1096
1247
 
1097
 
void DateTime::to_decimal(type::Decimal *to) const
 
1248
void DateTime::to_decimal(my_decimal *to) const
1098
1249
{
1099
1250
  int64_t date_portion= (((_years * 100L) + _months) * 100L) + _days;
1100
1251
  int64_t time_portion= (((((date_portion * 100L) + _hours) * 100L) + _minutes) * 100L) + _seconds;
1101
 
  (void) int2_class_decimal(E_DEC_FATAL_ERROR, time_portion, false, to);
 
1252
  (void) int2my_decimal(E_DEC_FATAL_ERROR, time_portion, false, to);
1102
1253
  if (_useconds > 0)
1103
1254
  {
1104
1255
    to->buf[(to->intg-1) / 9 + 1]= _useconds * 1000;
1127
1278
     + _seconds;
1128
1279
}
1129
1280
 
1130
 
// We fill the structure based on just int
1131
 
void Time::to_uint64_t(uint64_t &to) const
1132
 
{
1133
 
  to= _hours * 24
1134
 
     + _minutes * 60
1135
 
     + _seconds;
1136
 
}
1137
 
 
1138
1281
void DateTime::to_int64_t(int64_t *to) const
1139
1282
{
1140
1283
  *to= ((
1195
1338
bool Time::from_int32_t(const int32_t from)
1196
1339
{
1197
1340
  uint32_t copy_from= (uint32_t) from;
1198
 
  _hours= copy_from / INT32_C(10000);
1199
 
  _minutes= (copy_from % INT32_C(10000)) / INT32_C(100);
1200
 
  _seconds= copy_from % INT32_C(100); /* Masks off all but last 2 digits */
 
1341
  _hours= copy_from % INT32_C(10000);
 
1342
  _minutes= copy_from % INT32_C(100);
 
1343
  _seconds= copy_from & 3; /* Masks off all but last 2 digits */
1201
1344
  return is_valid();
1202
1345
}
1203
1346
 
1236
1379
    else if (copy_from <  DRIZZLE_YY_PART_YEAR * 10000000000LL + 101000000LL)
1237
1380
      return false;
1238
1381
    else if (copy_from <= 991231235959LL)
1239
 
      copy_from= copy_from + 19000000000000LL;    /* YYMMDDHHMMSS, 1970-1999 */
 
1382
      copy_from= copy_from + 19000000000000LL;          /* YYMMDDHHMMSS, 1970-1999 */
1240
1383
  }
1241
1384
 
1242
1385
  part1= (int64_t) (copy_from / 1000000LL);
1291
1434
  struct tm broken_time;
1292
1435
  struct tm *result;
1293
1436
 
1294
 
  result= util::gmtime(from, &broken_time);
 
1437
  result= gmtime_r(&from, &broken_time);
1295
1438
  if (result != NULL)
1296
1439
  {
1297
1440
    _years= 0;
1315
1458
  struct tm broken_time;
1316
1459
  struct tm *result;
1317
1460
 
1318
 
  result= util::gmtime(from, &broken_time);
 
1461
  result= gmtime_r(&from, &broken_time);
1319
1462
  if (result != NULL)
1320
1463
  {
1321
1464
    _years= 1900 + broken_time.tm_year;
1334
1477
    return false;
1335
1478
}
1336
1479
 
1337
 
bool DateTime::from_timeval(struct timeval &timeval_arg)
1338
 
{
1339
 
  struct tm broken_time;
1340
 
  struct tm *result;
1341
 
 
1342
 
  result= util::gmtime(timeval_arg.tv_sec, &broken_time);
1343
 
  if (result != NULL)
1344
 
  {
1345
 
    _years= 1900 + broken_time.tm_year;
1346
 
    _months= 1 + broken_time.tm_mon; /* Month is NOT ordinal for struct tm! */
1347
 
    _days= broken_time.tm_mday; /* Day IS ordinal for struct tm */
1348
 
    _hours= broken_time.tm_hour;
1349
 
    _minutes= broken_time.tm_min;
1350
 
    _seconds= broken_time.tm_sec;
1351
 
    _epoch_seconds= timeval_arg.tv_sec;
1352
 
    /* Set hires precision to zero */
1353
 
    _useconds= timeval_arg.tv_usec;
1354
 
    _nseconds= 0;
1355
 
    return is_valid();
1356
 
  }
1357
 
  else 
1358
 
  {
1359
 
    return false;
1360
 
  }
1361
 
}
1362
 
 
1363
1480
bool DateTime::from_time_t(const time_t from)
1364
1481
{
1365
1482
  struct tm broken_time;
1366
1483
  struct tm *result;
1367
1484
 
1368
 
  result= util::gmtime(from, &broken_time);
 
1485
  result= gmtime_r(&from, &broken_time);
1369
1486
  if (result != NULL)
1370
1487
  {
1371
1488
    _years= 1900 + broken_time.tm_year;
1381
1498
    return is_valid();
1382
1499
  }
1383
1500
  else 
1384
 
  {
1385
1501
    return false;
1386
 
  }
1387
1502
}
1388
1503
 
1389
 
void Date::to_time_t(time_t &to) const
 
1504
void Date::to_time_t(time_t *to) const
1390
1505
{
1391
1506
  if (in_unix_epoch())
1392
1507
  {
1393
 
    to= _epoch_seconds;
 
1508
    *to= _epoch_seconds;
1394
1509
  }
1395
1510
  else
1396
 
  {
1397
 
    to= 0;
1398
 
  }
1399
 
}
1400
 
 
1401
 
void Timestamp::to_time_t(time_t &to) const
1402
 
{
1403
 
  to= _epoch_seconds;
1404
 
}
1405
 
 
1406
 
void MicroTimestamp::to_timeval(struct timeval &to) const
1407
 
{
1408
 
  to.tv_sec= _epoch_seconds;
1409
 
  to.tv_usec= _useconds;
 
1511
    *to= 0;
 
1512
}
 
1513
 
 
1514
void Timestamp::to_time_t(time_t *to) const
 
1515
{
 
1516
  *to= _epoch_seconds;
 
1517
}
 
1518
 
 
1519
void MicroTimestamp::to_timeval(struct timeval *to) const
 
1520
{
 
1521
  to->tv_sec= _epoch_seconds;
 
1522
  to->tv_usec= _useconds;
1410
1523
}
1411
1524
 
1412
1525
void NanoTimestamp::to_timespec(struct timespec *to) const
1432
1545
      && (_seconds <= 59); /* No Leap second... TIME is for elapsed time... */
1433
1546
}
1434
1547
 
1435
 
bool Time::is_fuzzy_valid() const
1436
 
{
1437
 
  if (is_valid())
1438
 
    return true;
1439
 
 
1440
 
  return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1441
 
      && (_months >= 1 && _months <= 12)
1442
 
      && (_days >= 1 && _days <= days_in_gregorian_year_month(_years, _months))
1443
 
      && (_hours <= 23)
1444
 
      && (_minutes <= 59)
1445
 
      && (_seconds <= 59); /* No Leap second... TIME is for elapsed time... */
1446
 
}
1447
 
 
1448
1548
bool DateTime::is_valid() const
1449
1549
{
1450
1550
  return (_years >= DRIZZLE_MIN_YEARS_SQL && _years <= DRIZZLE_MAX_YEARS_SQL)
1458
1558
bool Timestamp::is_valid() const
1459
1559
{
1460
1560
  return DateTime::is_valid() 
1461
 
      && in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds)
1462
 
      && (_seconds <= 59);
 
1561
      && in_unix_epoch_range(_years, _months, _days, _hours, _minutes, _seconds);
1463
1562
}
1464
1563
 
1465
1564
bool MicroTimestamp::is_valid() const
1475
1574
      && (_nseconds <= UINT32_C(999999999));
1476
1575
}
1477
1576
 
1478
 
} /* namespace drizzled */
 
1577
} /* end namespace drizzled */