795
#ifdef NOTYETIMPLEMENTED
796
Date& Date::operator+=(const TemporalIntervalYear &rhs)
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)
804
* Set everything to zero. We got an overflow.
805
* @TODO Exceptions would be great here...
811
_years= (uint32_t) new_years;
812
if (_months == 2 && _days == 29 && days_in_gregorian_year_month(_years, _months) != 366)
817
Date& Date::operator-=(const TemporalIntervalYear &rhs)
819
/* Simple one...subtract the years and adjust for any leaps */
820
int64_t new_years= _years;
821
new_years-= rhs._years;
825
* Set everything to zero. We got an overflow.
826
* @TODO Exceptions would be great here...
832
_years= (uint32_t) new_years;
833
if (_months == 2 && _days == 29 && days_in_gregorian_year_month(_years, _months) != 366)
838
Date& Date::operator+=(const TemporalIntervalDayOrWeek &rhs)
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);
846
Date& Date::operator-=(const TemporalIntervalDayOrWeek &rhs)
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);
854
Date& Date::operator+=(const TemporalIntervalYearMonth &rhs)
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)
862
* Set everything to zero. We got an overflow.
863
* @TODO Exceptions would be great here...
869
_years= (uint32_t) new_years;
870
_months= (uint32_t) (period % 12) + 1;
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;
879
Date& Date::operator-=(const TemporalIntervalYearMonth &rhs)
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);
887
* Set everything to zero. We got an overflow.
888
* @TODO Exceptions would be great here...
894
_years= (uint32_t) (period / 12);
895
_months= (uint32_t) (period % 12) + 1;
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;
904
Date& Date::operator+=(const TemporalIntervalDayOrLess &rhs)
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
913
int64_t new_microseconds;
916
new_microseconds= _useconds + rhs._useconds;
917
extra_sec= new_microseconds / INT64_C(1000000);
918
new_microseconds= new_microseconds % INT64_C(1000000);
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;
924
if (new_microseconds < 0)
926
new_microseconds+= INT64_C(1000000);
930
new_days= new_seconds / (3600 * 24L);
931
new_seconds-= new_days * 3600 * 24L;
935
new_seconds+= 3600 * 24L;
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);
946
Date& Date::operator-=(const TemporalIntervalDayOrLess &rhs)
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
955
int64_t new_microseconds;
958
new_microseconds= _useconds - rhs._useconds;
959
extra_sec= new_microseconds / INT64_C(1000000);
960
new_microseconds= new_microseconds % INT64_C(1000000);
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;
966
if (new_microseconds < 0)
968
new_microseconds+= INT64_C(1000000);
972
new_days= new_seconds / (3600 * 24L);
973
new_seconds-= new_days * 3600 * 24L;
977
new_seconds+= 3600 * 24L;
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);
987
#endif /* NOTYETIMPLEMENTED */
836
989
* Comparison operators between a Date and a Timestamp
1031
1184
return is_valid();
1034
int Time::to_string(char *to, size_t to_len) const
1036
return snprintf(to, to_len,
1037
"%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
1038
_hours, _minutes, _seconds);
1041
int Date::to_string(char *to, size_t to_len) const
1043
return snprintf(to, to_len,
1044
"%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32,
1045
_years, _months, _days);
1048
int DateTime::to_string(char *to, size_t to_len) const
1187
void Time::to_string(char *to, size_t *to_len) const
1190
, "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32
1196
void Date::to_string(char *to, size_t *to_len) const
1199
, "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
1205
void DateTime::to_string(char *to, size_t *to_len) const
1050
1207
/* If the temporal has a microsecond component, use a slightly different output */
1051
1208
if (_useconds == 0)
1053
return snprintf(to, to_len,
1054
"%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
1055
" %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32,
1056
_years, _months, _days,
1057
_hours, _minutes, _seconds);
1211
, "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32
1061
return snprintf(to, to_len,
1062
"%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
1063
" %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
1064
_years, _months, _days,
1065
_hours, _minutes, _seconds, _useconds);
1222
, "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32
1069
int MicroTimestamp::to_string(char *to, size_t to_len) const
1233
void MicroTimestamp::to_string(char *to, size_t *to_len) const
1071
return snprintf(to, to_len,
1072
"%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32
1073
" %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32,
1074
_years, _months, _days,
1075
_hours, _minutes, _seconds, _useconds);
1236
, "%04" PRIu32 "-%02" PRIu32 "-%02" PRIu32 " %02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32
1078
1246
void Time::to_decimal(my_decimal *to) const