2025-01-15 14:51:53 +01:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity 0.8.28;
|
|
|
|
|
|
|
|
type Timestamp is uint64;
|
|
|
|
|
2025-01-23 15:05:07 +01:00
|
|
|
using {_timestampEquals as ==} for Timestamp global;
|
|
|
|
using {_timestampNotEqual as !=} for Timestamp global;
|
|
|
|
using {_timestampLessThan as <} for Timestamp global;
|
|
|
|
using {_timestampAtMost as <=} for Timestamp global;
|
2025-01-23 10:19:41 +01:00
|
|
|
|
2025-01-23 15:05:07 +01:00
|
|
|
function _timestampEquals(Timestamp a, Timestamp b) pure returns (bool) {
|
|
|
|
return Timestamp.unwrap(a) == Timestamp.unwrap(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _timestampNotEqual(Timestamp a, Timestamp b) pure returns (bool) {
|
2025-01-23 10:29:53 +01:00
|
|
|
return Timestamp.unwrap(a) != Timestamp.unwrap(b);
|
|
|
|
}
|
|
|
|
|
2025-01-23 15:05:07 +01:00
|
|
|
function _timestampLessThan(Timestamp a, Timestamp b) pure returns (bool) {
|
2025-01-23 10:19:41 +01:00
|
|
|
return Timestamp.unwrap(a) < Timestamp.unwrap(b);
|
|
|
|
}
|
|
|
|
|
2025-01-23 15:05:07 +01:00
|
|
|
function _timestampAtMost(Timestamp a, Timestamp b) pure returns (bool) {
|
2025-01-23 10:19:41 +01:00
|
|
|
return Timestamp.unwrap(a) <= Timestamp.unwrap(b);
|
|
|
|
}
|
|
|
|
|
2025-01-15 14:51:53 +01:00
|
|
|
library Timestamps {
|
2025-01-22 15:07:51 +01:00
|
|
|
function currentTime() internal view returns (Timestamp) {
|
|
|
|
return Timestamp.wrap(uint64(block.timestamp));
|
|
|
|
}
|
2025-01-23 10:29:53 +01:00
|
|
|
|
|
|
|
function earliest(
|
|
|
|
Timestamp a,
|
|
|
|
Timestamp b
|
|
|
|
) internal pure returns (Timestamp) {
|
|
|
|
if (a <= b) {
|
|
|
|
return a;
|
|
|
|
} else {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
2025-01-15 14:51:53 +01:00
|
|
|
}
|