292
303
bool Date::operator<(const Date& rhs)
294
int days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
295
int days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
305
int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
306
int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
296
307
return (days_left < days_right);
298
309
bool Date::operator<=(const Date& rhs)
300
int days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
301
int days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
311
int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
312
int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
302
313
return (days_left <= days_right);
304
315
bool Date::operator>(const Date& rhs)
769
791
microsecond_diff= (-1 * microsecond_diff);
772
_useconds= microsecond_diff;
794
_useconds= (uint32_t) microsecond_diff;
798
#ifdef NOTYETIMPLEMENTED
799
DateTime& DateTime::operator+=(const TemporalIntervalYear &rhs)
801
/* Simple one...add the years and adjust for any leaps */
802
int64_t new_years= _years;
803
new_years+= rhs._years;
804
if (new_years > DRIZZLE_MAX_YEARS_SQL)
807
* Set everything to zero. We got an overflow.
808
* @TODO Exceptions would be great here...
814
_years= (uint32_t) new_years;
815
if (_months == 2 && _days == 29 && days_in_gregorian_year_month(_years, _months) != 366)
820
DateTime& DateTime::operator-=(const TemporalIntervalYear &rhs)
822
/* Simple one...subtract the years and adjust for any leaps */
823
int64_t new_years= _years;
824
new_years-= rhs._years;
828
* Set everything to zero. We got an overflow.
829
* @TODO Exceptions would be great here...
835
_years= (uint32_t) new_years;
836
if (_months == 2 && _days == 29 && days_in_gregorian_year_month(_years, _months) != 366)
841
DateTime& DateTime::operator+=(const TemporalIntervalDayOrWeek &rhs)
843
/* Simple one...add the days */
844
int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, _days) + rhs._days;
845
gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
849
DateTime& DateTime::operator-=(const TemporalIntervalDayOrWeek &rhs)
851
/* Simple one...subtract the days */
852
int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, _days) - rhs._days;
853
gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
857
DateTime& DateTime::operator+=(const TemporalIntervalYearMonth &rhs)
859
/* Simple one...add the months in the period adjust */
860
int64_t period= (_years * 12) + (rhs._years * 12) + (_months - 1) + rhs._months;
861
int64_t new_years= (period / 12);
862
if (new_years > DRIZZLE_MAX_YEARS_SQL)
865
* Set everything to zero. We got an overflow.
866
* @TODO Exceptions would be great here...
872
_years= (uint32_t) new_years;
873
_months= (uint32_t) (period % 12) + 1;
875
/* Adjust day if the new month doesn't have enough days */
876
uint32_t days_in_new_month= days_in_gregorian_year_month(_years, _months);
877
if (_days > days_in_new_month)
878
_days= days_in_new_month;
882
DateTime& DateTime::operator-=(const TemporalIntervalYearMonth &rhs)
884
/* Simple one...subtract the months in the period and adjust */
885
int64_t period= (_years * 12) - (rhs._years * 12) + (_months - 1) - rhs._months;
886
int64_t new_years= (period / 12);
890
* Set everything to zero. We got an overflow.
891
* @TODO Exceptions would be great here...
897
_years= (uint32_t) (period / 12);
898
_months= (uint32_t) (period % 12) + 1;
900
/* Adjust day if the new month doesn't have enough days */
901
uint32_t days_in_new_month= days_in_gregorian_year_month(_years, _months);
902
if (_days > days_in_new_month)
903
_days= days_in_new_month;
907
DateTime& DateTime::operator+=(const TemporalIntervalDayOrLess &rhs)
910
* Convert the temporal and the interval into a number of
911
* microseconds, then add them together and convert the
912
* resulting microseconds back into a broken-down temporal
916
int64_t new_microseconds;
919
new_microseconds= _useconds + rhs._useconds;
920
extra_sec= new_microseconds / INT64_C(1000000);
921
new_microseconds= new_microseconds % INT64_C(1000000);
923
new_seconds= ((_days - 1) * 3600 * 24) + (_hours * 3600) + (_minutes * 60) + _seconds;
924
new_seconds+= (rhs._days * 3600 * 24) + (rhs._hours * 3600) + (rhs._minutes * 60) + rhs._seconds;
925
new_seconds+= extra_sec;
927
if (new_microseconds < 0)
929
new_microseconds+= INT64_C(1000000);
933
new_days= new_seconds / (3600 * 24L);
934
new_seconds-= new_days * 3600 * 24L;
938
new_seconds+= 3600 * 24L;
940
_useconds= (uint32_t) new_microseconds;
941
_seconds= (uint32_t) (new_seconds % 60);
942
_minutes= (uint32_t) ((new_seconds / 60) % 60);
943
_hours= (uint32_t) (new_seconds / 3600);
944
int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, 1) + new_days;
945
gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
949
DateTime& DateTime::operator-=(const TemporalIntervalDayOrLess &rhs)
952
* Convert the temporal and the interval into a number of
953
* microseconds, then subtract them from each other and convert
954
* the resulting microseconds back into a broken-down temporal
958
int64_t new_microseconds;
961
new_microseconds= _useconds - rhs._useconds;
962
extra_sec= new_microseconds / INT64_C(1000000);
963
new_microseconds= new_microseconds % INT64_C(1000000);
965
new_seconds= ((_days - 1) * 3600 * 24) + (_hours * 3600) + (_minutes * 60) + _seconds;
966
new_seconds-= (rhs._days * 3600 * 24) + (rhs._hours * 3600) + (rhs._minutes * 60) + rhs._seconds;
967
new_seconds+= extra_sec;
969
if (new_microseconds < 0)
971
new_microseconds+= INT64_C(1000000);
975
new_days= new_seconds / (3600 * 24L);
976
new_seconds-= new_days * 3600 * 24L;
980
new_seconds+= 3600 * 24L;
982
_useconds= (uint32_t) new_microseconds;
983
_seconds= (uint32_t) (new_seconds % 60);
984
_minutes= (uint32_t) ((new_seconds / 60) % 60);
985
_hours= (uint32_t) (new_seconds / 3600);
986
int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, 1) + new_days;
987
gregorian_date_from_julian_day_number(julian_day, &_years, &_months, &_days);
990
#endif /* NOTYETIMPLEMENTED */
778
992
* Comparison operators between two Timestamps
1008
if (! (copy_from == 0LL || copy_from >= 10000101000000LL))
1232
if (copy_from == 0LL)
1235
if (copy_from < 10000101000000LL)
1010
1237
if (copy_from < 101)
1012
if (copy_from <= (DRIZZLE_YY_PART_YEAR-1)*10000L+1231L)
1239
else if (copy_from <= (DRIZZLE_YY_PART_YEAR-1)*10000L+1231L)
1013
1240
copy_from= (copy_from+20000000L)*1000000L; /* YYMMDD, year: 2000-2069 */
1014
if (copy_from < (DRIZZLE_YY_PART_YEAR)*10000L+101L)
1241
else if (copy_from < (DRIZZLE_YY_PART_YEAR)*10000L+101L)
1016
if (copy_from <= 991231L)
1243
else if (copy_from <= 991231L)
1017
1244
copy_from= (copy_from+19000000L)*1000000L; /* YYMMDD, year: 1970-1999 */
1018
if (copy_from < 10000101L)
1245
else if (copy_from < 10000101L)
1020
if (copy_from <= 99991231L)
1247
else if (copy_from <= 99991231L)
1021
1248
copy_from= copy_from*1000000L;
1022
if (copy_from < 101000000L)
1249
else if (copy_from < 101000000L)
1024
if (copy_from <= (DRIZZLE_YY_PART_YEAR-1) * 10000000000LL + 1231235959LL)
1251
else if (copy_from <= (DRIZZLE_YY_PART_YEAR-1) * 10000000000LL + 1231235959LL)
1025
1252
copy_from= copy_from + 20000000000000LL; /* YYMMDDHHMMSS, 2000-2069 */
1026
if (copy_from < DRIZZLE_YY_PART_YEAR * 10000000000LL + 101000000LL)
1253
else if (copy_from < DRIZZLE_YY_PART_YEAR * 10000000000LL + 101000000LL)
1028
if (copy_from <= 991231235959LL)
1255
else if (copy_from <= 991231235959LL)
1029
1256
copy_from= copy_from + 19000000000000LL; /* YYMMDDHHMMSS, 1970-1999 */