| 294 | } |
| 295 | |
| 296 | TimestampValue TimestampValue::Subtract(const boost::posix_time::time_duration& t) const { |
| 297 | if (!IsValidTime(t) || !HasDateAndTime()) return TimestampValue(); |
| 298 | |
| 299 | int64_t this_in_nano_sec = time_.total_nanoseconds(); |
| 300 | int64_t t_in_nano_sec = t.total_nanoseconds(); |
| 301 | if (this_in_nano_sec - t_in_nano_sec >= 0) { |
| 302 | return TimestampValue(date_, time_ - t); |
| 303 | } else { |
| 304 | return TimestampValue(date_ - boost::gregorian::date_duration(1), |
| 305 | boost::posix_time::time_duration( |
| 306 | 0, 0, 0, NANOS_PER_DAY + this_in_nano_sec - t_in_nano_sec)); |
| 307 | } |
| 308 | } |
| 309 | } |