OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_time.h" | 5 #include "net/quic/quic_time.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 | 93 |
94 QuicTime QuicTime::Subtract(const Delta& delta) const { | 94 QuicTime QuicTime::Subtract(const Delta& delta) const { |
95 return QuicTime(ticks_ - delta.delta_); | 95 return QuicTime(ticks_ - delta.delta_); |
96 } | 96 } |
97 | 97 |
98 QuicTime::Delta QuicTime::Subtract(const QuicTime& other) const { | 98 QuicTime::Delta QuicTime::Subtract(const QuicTime& other) const { |
99 return QuicTime::Delta(ticks_ - other.ticks_); | 99 return QuicTime::Delta(ticks_ - other.ticks_); |
100 } | 100 } |
101 | 101 |
| 102 // static |
| 103 QuicWallTime QuicWallTime::FromUNIXSeconds(uint64 seconds) { |
| 104 return QuicWallTime(seconds); |
| 105 } |
| 106 |
| 107 uint64 QuicWallTime::ToUNIXSeconds() const { |
| 108 return seconds_; |
| 109 } |
| 110 |
| 111 bool QuicWallTime::IsAfter(QuicWallTime other) const { |
| 112 return seconds_ > other.seconds_; |
| 113 } |
| 114 |
| 115 bool QuicWallTime::IsBefore(QuicWallTime other) const { |
| 116 return seconds_ < other.seconds_; |
| 117 } |
| 118 |
| 119 QuicTime::Delta QuicWallTime::AbsoluteDifference(QuicWallTime other) const { |
| 120 uint64 d; |
| 121 |
| 122 if (seconds_ > other.seconds_) { |
| 123 d = seconds_ - other.seconds_; |
| 124 } else { |
| 125 d = other.seconds_ - seconds_; |
| 126 } |
| 127 |
| 128 if (d > static_cast<uint64>(kint64max)) { |
| 129 d = kint64max; |
| 130 } |
| 131 return QuicTime::Delta::FromSeconds(d); |
| 132 } |
| 133 |
| 134 QuicWallTime QuicWallTime::Add(QuicTime::Delta delta) const { |
| 135 uint64 seconds = seconds_ + delta.ToSeconds(); |
| 136 if (seconds < seconds_) { |
| 137 seconds = kuint64max; |
| 138 } |
| 139 return QuicWallTime(seconds); |
| 140 } |
| 141 |
| 142 QuicWallTime QuicWallTime::Subtract(QuicTime::Delta delta) const { |
| 143 uint64 seconds = seconds_ - delta.ToSeconds(); |
| 144 if (seconds > seconds_) { |
| 145 seconds = 0; |
| 146 } |
| 147 return QuicWallTime(seconds); |
| 148 } |
| 149 |
| 150 QuicWallTime::QuicWallTime(uint64 seconds) |
| 151 : seconds_(seconds) { |
| 152 } |
| 153 |
102 } // namespace net | 154 } // namespace net |
OLD | NEW |