datetime.cpp 845 B

1234567891011121314151617181920212223
  1. #include "datetime.h"
  2. namespace NYql::DateTime {
  3. TInstant DoAddMonths(TInstant current, i64 months, const NUdf::IDateBuilder& builder) {
  4. TTMStorage storage;
  5. storage.FromTimestamp(builder, current.GetValue());
  6. if (!DoAddMonths(storage, months, builder)) {
  7. ythrow yexception() << "Shift error " << current.ToIsoStringLocal() << " by " << months << " months";
  8. }
  9. return TInstant::FromValue(storage.ToTimestamp(builder));
  10. }
  11. TInstant DoAddYears(TInstant current, i64 years, const NUdf::IDateBuilder& builder) {
  12. TTMStorage storage;
  13. storage.FromTimestamp(builder, current.GetValue());
  14. if (!DoAddYears(storage, years, builder)) {
  15. ythrow yexception() << "Shift error " << current.ToIsoStringLocal() << " by " << years << " years";
  16. }
  17. return TInstant::FromValue(storage.ToTimestamp(builder));
  18. }
  19. }