Skip to content

Commit

Permalink
feat(LibEventRange): add LibEventRange
Browse files Browse the repository at this point in the history
  • Loading branch information
TuDo1403 committed May 21, 2024
1 parent 07d4305 commit 27aee4a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/LibEventRange.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

struct EventRange {
// uint40 is enough to represent the timestamp until year 36812
uint40 startedAt;
uint40 endedAt;
/// @dev Reserved space for future upgrades
uint176 __reserved;
}

using LibEventRange for EventRange global;

library LibEventRange {
/**
* @dev Checks whether the event range is valid.
*/
function valid(EventRange memory range) internal pure returns (bool) {
return range.startedAt <= range.endedAt;
}

/**
* @dev Returns whether the current range is not yet started.
*/
function isNotYetStarted(EventRange memory range) internal view returns (bool) {
return block.timestamp < range.startedAt;
}

/**
* @dev Returns whether the current range is ended or not.
*/
function isEnded(EventRange memory range) internal view returns (bool) {
return range.endedAt <= block.timestamp;
}

/**
* @dev Returns whether the current block is in period.
*/
function isInPeriod(EventRange memory range) internal view returns (bool) {
return range.startedAt <= block.timestamp && block.timestamp < range.endedAt;
}
}

0 comments on commit 27aee4a

Please sign in to comment.