Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions prometheus_client/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def __ne__(self, other: object) -> bool:
return not self == other

def __gt__(self, other: "Timestamp") -> bool:
return self.sec > other.sec or self.nsec > other.nsec
return self.nsec > other.nsec if self.sec == other.sec else self.sec > other.sec

def __lt__(self, other: "Timestamp") -> bool:
return self.sec < other.sec or self.nsec < other.nsec
return self.nsec < other.nsec if self.sec == other.sec else self.sec < other.sec


# Timestamp and exemplar are optional.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def test_gt(self):
self.assertEqual(samples.Timestamp(1, 2) > samples.Timestamp(1, 1), True)
self.assertEqual(samples.Timestamp(2, 1) > samples.Timestamp(1, 1), True)
self.assertEqual(samples.Timestamp(2, 2) > samples.Timestamp(1, 1), True)
self.assertEqual(samples.Timestamp(0, 2) > samples.Timestamp(1, 1), False)
self.assertEqual(samples.Timestamp(2, 0) > samples.Timestamp(1, 1), True)

def test_lt(self):
self.assertEqual(samples.Timestamp(1, 1) < samples.Timestamp(1, 1), False)
Expand All @@ -21,6 +23,8 @@ def test_lt(self):
self.assertEqual(samples.Timestamp(1, 2) < samples.Timestamp(1, 1), False)
self.assertEqual(samples.Timestamp(2, 1) < samples.Timestamp(1, 1), False)
self.assertEqual(samples.Timestamp(2, 2) < samples.Timestamp(1, 1), False)
self.assertEqual(samples.Timestamp(0, 2) < samples.Timestamp(1, 1), True)
self.assertEqual(samples.Timestamp(2, 0) < samples.Timestamp(1, 1), False)


if __name__ == '__main__':
Expand Down