~stewart/drizzle/nofrm

« back to all changes in this revision

Viewing changes to drizzled/temporal.cc

  • Committer: Stewart Smith
  • Date: 2009-02-22 06:28:04 UTC
  • mfrom: (869.1.29 drizzle)
  • Revision ID: stewart@flamingspork.com-20090222062804-ssplgcffmroxwjph
mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
326
326
 * are easy.  We simply compare the cumulative time
327
327
 * value of each.
328
328
 */
329
 
bool DateTime::operator==(const DateTime& rhs)
 
329
bool Date::operator==(const DateTime& rhs)
330
330
{
331
331
  return (
332
332
          _years == rhs._years
339
339
       && _nseconds == rhs._nseconds
340
340
      );
341
341
}
342
 
bool DateTime::operator!=(const DateTime& rhs)
 
342
bool Date::operator!=(const DateTime& rhs)
343
343
{
344
344
  return ! (*this == rhs);
345
345
}
346
 
bool DateTime::operator<(const DateTime& rhs)
 
346
bool Date::operator<(const DateTime& rhs)
347
347
{
348
348
  int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
349
349
  int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
354
354
  /* Here if both dates are the same, so compare times */
355
355
  return (_cumulative_seconds_in_time() < rhs._cumulative_seconds_in_time());
356
356
}
357
 
bool DateTime::operator<=(const DateTime& rhs)
 
357
bool Date::operator<=(const DateTime& rhs)
358
358
{
359
359
  int64_t days_left= julian_day_number_from_gregorian_date(_years, _months, _days);
360
360
  int64_t days_right= julian_day_number_from_gregorian_date(rhs._years, rhs._months, rhs._days);
365
365
  /* Here if both dates are the same, so compare times */
366
366
  return (_cumulative_seconds_in_time() <= rhs._cumulative_seconds_in_time());
367
367
}
368
 
bool DateTime::operator>(const DateTime& rhs)
 
368
bool Date::operator>(const DateTime& rhs)
369
369
{
370
370
  return ! (*this <= rhs);
371
371
}
372
 
bool DateTime::operator>=(const DateTime& rhs)
 
372
bool Date::operator>=(const DateTime& rhs)
373
373
{
374
374
  return ! (*this < rhs);
375
375
}
378
378
 * We can add or subtract a Time value to/from a DateTime value 
379
379
 * as well...it always produces a DateTime.
380
380
 */
381
 
const DateTime DateTime::operator-(const Time& rhs)
 
381
const Date Date::operator-(const Time& rhs)
382
382
{
383
383
  DateTime result;
384
384
 
422
422
 
423
423
  return result;
424
424
}
425
 
const DateTime DateTime::operator+(const Time& rhs)
 
425
const Date Date::operator+(const Time& rhs)
426
426
{
427
427
  DateTime result;
428
428
 
469
469
 * Variation of + and - operator which returns a reference to the left-hand
470
470
 * side DateTime object and adds the right-hand side Time to itself.
471
471
 */
472
 
DateTime& DateTime::operator+=(const Time& rhs)
 
472
Date& Date::operator+=(const Time& rhs)
473
473
{
474
474
  int64_t second_diff= _cumulative_seconds_in_time() + rhs._cumulative_seconds_in_time();
475
475
  /* 
502
502
   */
503
503
  return *this;
504
504
}
505
 
DateTime& DateTime::operator-=(const Time& rhs)
 
505
Date& Date::operator-=(const Time& rhs)
506
506
{
507
507
  int64_t second_diff= _cumulative_seconds_in_time() - rhs._cumulative_seconds_in_time();
508
508
 
616
616
 * We can add/subtract two DateTimes to/from each other.  The result
617
617
 * is always another DateTime instance.
618
618
 */
619
 
const DateTime DateTime::operator-(const DateTime &rhs)
 
619
const Date Date::operator-(const DateTime &rhs)
620
620
{
621
621
  /* Figure out the difference in days between the two dates. */
622
622
  int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
660
660
 
661
661
  return result;
662
662
}
663
 
const DateTime DateTime::operator+(const DateTime &rhs)
 
663
const Date Date::operator+(const DateTime &rhs)
664
664
{
665
 
  /* 
 
665
  /*
666
666
   * Figure out the new Julian Day Number by adding the JDNs of both
667
667
   * dates together.
668
668
   */
707
707
  return result;
708
708
}
709
709
/* Similar to the above, but we add/subtract the right side to this object itself */
710
 
DateTime& DateTime::operator-=(const DateTime &rhs)
 
710
Date& Date::operator-=(const DateTime &rhs)
711
711
{
712
712
  /* Figure out the difference in days between the two dates.  */
713
713
  int64_t day_left= julian_day_number_from_gregorian_date(_years, _months, _days);
750
750
 
751
751
  return *this;
752
752
}
753
 
DateTime& DateTime::operator+=(const DateTime &rhs)
 
753
Date& Date::operator+=(const DateTime &rhs)
754
754
{
755
755
  /* 
756
756
   * Figure out the new Julian Day Number by adding the JDNs of both
796
796
  return *this;
797
797
}
798
798
#ifdef NOTYETIMPLEMENTED
799
 
DateTime& DateTime::operator+=(const TemporalIntervalYear &rhs)
 
799
Date& Date::operator+=(const TemporalIntervalYear &rhs)
800
800
{
801
801
  /* Simple one...add the years and adjust for any leaps */
802
802
  int64_t new_years= _years;
817
817
  return *this;
818
818
819
819
 
820
 
DateTime& DateTime::operator-=(const TemporalIntervalYear &rhs)
 
820
Date& Date::operator-=(const TemporalIntervalYear &rhs)
821
821
{
822
822
  /* Simple one...subtract the years and adjust for any leaps */
823
823
  int64_t new_years= _years;
838
838
  return *this;
839
839
840
840
 
841
 
DateTime& DateTime::operator+=(const TemporalIntervalDayOrWeek &rhs)
 
841
Date& Date::operator+=(const TemporalIntervalDayOrWeek &rhs)
842
842
{
843
843
  /* Simple one...add the days */
844
844
  int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, _days) + rhs._days;
846
846
  return *this;
847
847
848
848
 
849
 
DateTime& DateTime::operator-=(const TemporalIntervalDayOrWeek &rhs)
 
849
Date& Date::operator-=(const TemporalIntervalDayOrWeek &rhs)
850
850
{
851
851
  /* Simple one...subtract the days */
852
852
  int64_t julian_day= julian_day_number_from_gregorian_date(_years, _months, _days) - rhs._days;
854
854
  return *this;
855
855
856
856
 
857
 
DateTime& DateTime::operator+=(const TemporalIntervalYearMonth &rhs)
 
857
Date& Date::operator+=(const TemporalIntervalYearMonth &rhs)
858
858
{
859
859
  /* Simple one...add the months in the period adjust */
860
860
  int64_t period= (_years * 12) + (rhs._years * 12) + (_months - 1) + rhs._months;
879
879
  return *this;
880
880
881
881
 
882
 
DateTime& DateTime::operator-=(const TemporalIntervalYearMonth &rhs)
 
882
Date& Date::operator-=(const TemporalIntervalYearMonth &rhs)
883
883
{
884
884
  /* Simple one...subtract the months in the period and adjust */
885
885
  int64_t period= (_years * 12) - (rhs._years * 12) + (_months - 1) - rhs._months;
904
904
  return *this;
905
905
906
906
 
907
 
DateTime& DateTime::operator+=(const TemporalIntervalDayOrLess &rhs)
 
907
Date& Date::operator+=(const TemporalIntervalDayOrLess &rhs)
908
908
{
909
909
  /* 
910
910
   * Convert the temporal and the interval into a number of 
946
946
  return *this;
947
947
}
948
948
 
949
 
DateTime& DateTime::operator-=(const TemporalIntervalDayOrLess &rhs)
 
949
Date& Date::operator-=(const TemporalIntervalDayOrLess &rhs)
950
950
{
951
951
  /* 
952
952
   * Convert the temporal and the interval into a number of 
991
991
/*
992
992
 * Comparison operators between two Timestamps
993
993
 */
994
 
bool Timestamp::operator==(const Timestamp& rhs)
 
994
bool Date::operator==(const Timestamp& rhs)
995
995
{
996
996
  return (_epoch_seconds == rhs._epoch_seconds);
997
997
}
998
 
bool Timestamp::operator!=(const Timestamp& rhs)
 
998
bool Date::operator!=(const Timestamp& rhs)
999
999
{
1000
1000
  return ! (*this == rhs);
1001
1001
}
1002
 
bool Timestamp::operator<(const Timestamp& rhs)
 
1002
bool Date::operator<(const Timestamp& rhs)
1003
1003
{
1004
1004
  return (_epoch_seconds < rhs._epoch_seconds);
1005
1005
}
1006
 
bool Timestamp::operator<=(const Timestamp& rhs)
 
1006
bool Date::operator<=(const Timestamp& rhs)
1007
1007
{
1008
1008
  return (_epoch_seconds <= rhs._epoch_seconds);
1009
1009
}
1010
 
bool Timestamp::operator>(const Timestamp& rhs)
 
1010
bool Date::operator>(const Timestamp& rhs)
1011
1011
{
1012
1012
  return ! (*this < rhs);
1013
1013
}
1014
 
bool Timestamp::operator>=(const Timestamp& rhs)
 
1014
bool Date::operator>=(const Timestamp& rhs)
1015
1015
{
1016
1016
  return ! (*this <= rhs);
1017
1017
}
1018
1018
 
1019
1019
bool Time::from_string(const char *from, size_t from_len)
1020
1020
{
1021
 
  /* 
1022
 
   * Loop through the known time formats and see if 
 
1021
  /*
 
1022
   * Loop through the known time formats and see if
1023
1023
   * there is a match.
1024
1024
   */
1025
1025
  bool matched= false;