| 1 |
.. title:: clang-tidy - abseil-time-comparison |
| 2 |
|
| 3 |
abseil-time-comparison |
| 4 |
====================== |
| 5 |
|
| 6 |
Prefer comparisons in the ``absl::Time`` domain instead of the integer domain. |
| 7 |
|
| 8 |
N.B.: In cases where an ``absl::Time`` is being converted to an integer, |
| 9 |
alignment may occur. If the comparison depends on this alignment, doing the |
| 10 |
comparison in the ``absl::Time`` domain may yield a different result. In |
| 11 |
practice this is very rare, and still indicates a bug which should be fixed. |
| 12 |
|
| 13 |
Examples: |
| 14 |
|
| 15 |
.. code-block:: c++ |
| 16 |
|
| 17 |
// Original - Comparison in the integer domain |
| 18 |
int x; |
| 19 |
absl::Time t; |
| 20 |
if (x < absl::ToUnixSeconds(t)) ... |
| 21 |
|
| 22 |
// Suggested - Compare in the absl::Time domain instead |
| 23 |
if (absl::FromUnixSeconds(x) < t) ... |