DateTime DateTime::operator-(const DateTimeSpan& dateSpan) const
   {
      DateTime dateResult;    // Initializes status_ to valid

      // If either operand NULL, result NULL
      if (GetStatus() == null || dateSpan.GetStatus() == null)
      {
         dateResult.SetStatus(null);
         return dateResult;
      }

      // If either operand invalid, result invalid
      if (GetStatus() == invalid || dateSpan.GetStatus() == invalid)
      {
         dateResult.SetStatus(invalid);
         return dateResult;
      }

      // Compute the actual date difference by subtracting underlying dates
      dateResult = DateFromDouble(DoubleFromDate(dt_) - dateSpan.span_);

      // Validate within range
      dateResult.CheckRange();

      return dateResult;
   }
   DateTimeSpan DateTimeSpan::operator-(const DateTimeSpan& dateSpan)
      const
   {
      DateTimeSpan dateSpanTemp;

      // If either operand Null, result Null
      if (GetStatus() == null || dateSpan.GetStatus() == null)
      {
         dateSpanTemp.SetStatus(null);
         return dateSpanTemp;
      }

      // If either operand Invalid, result Invalid
      if (GetStatus() == invalid || dateSpan.GetStatus() == invalid)
      {
         dateSpanTemp.SetStatus(invalid);
         return dateSpanTemp;
      }

      // Subtract spans and validate within legal range
      dateSpanTemp.span_ = span_ - dateSpan.span_;
      dateSpanTemp.CheckRange();

      return dateSpanTemp;
   }
예제 #3
0
   DateTimeSpan DateTimeSpan::operator+(const DateTimeSpan& dateSpan)
      const
   {
      DateTimeSpan dateSpanTemp;

      // If either operand Null, result Null
      if (GetStatus() == null || dateSpan.GetStatus() == null)
      {

         dateSpanTemp.SetStatus(null);
         return dateSpanTemp;
      }

      // If either operand Invalid, result Invalid
      if (GetStatus() == invalid || dateSpan.GetStatus() == invalid)
      {
         dateSpanTemp.SetStatus(invalid);
         return dateSpanTemp;
      }

      // Add spans and validate within legal range
      dateSpanTemp.m_span = m_span + dateSpan.m_span;
      dateSpanTemp.CheckRange();

      return dateSpanTemp;
   }