| 277 | } |
| 278 | |
| 279 | TimestampValue TimestampValue::Add(const boost::posix_time::time_duration& t) const { |
| 280 | if (!IsValidTime(t) || !HasDateAndTime()) return TimestampValue(); |
| 281 | |
| 282 | int64_t this_in_nano_sec = time_.total_nanoseconds(); |
| 283 | int64_t t_in_nano_sec = t.total_nanoseconds(); |
| 284 | |
| 285 | if (this_in_nano_sec + t_in_nano_sec < NANOS_PER_DAY) { |
| 286 | return TimestampValue(date_, time_ + t); |
| 287 | } else { |
| 288 | int64_t total_in_nano_sec = this_in_nano_sec + t_in_nano_sec; |
| 289 | int64_t days = total_in_nano_sec / NANOS_PER_DAY; |
| 290 | int64_t nano_secs_remaining = total_in_nano_sec % NANOS_PER_DAY; |
| 291 | return TimestampValue(date_ + boost::gregorian::date_duration(days), |
| 292 | boost::posix_time::time_duration(0, 0, 0, nano_secs_remaining)); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | TimestampValue TimestampValue::Subtract(const boost::posix_time::time_duration& t) const { |
| 297 | if (!IsValidTime(t) || !HasDateAndTime()) return TimestampValue(); |