-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45ba170
commit da8a82f
Showing
4 changed files
with
694 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
// ---------------------------------------------------------------------------- | ||
// BokkyPooBah's DateTime Library v1.00 - Contract Instance | ||
// | ||
// A gas-efficient Solidity date and time library | ||
// | ||
// https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary | ||
// | ||
// Tested date range 1970/01/01 to 2345/12/31 | ||
// | ||
// Conventions: | ||
// Unit | Range | Notes | ||
// :-------- |:-------------:|:----- | ||
// timestamp | >= 0 | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC | ||
// year | 1970 ... 2345 | | ||
// month | 1 ... 12 | | ||
// day | 1 ... 31 | | ||
// hour | 0 ... 23 | | ||
// minute | 0 ... 59 | | ||
// second | 0 ... 59 | | ||
// dayOfWeek | 1 ... 7 | 1 = Monday, ..., 7 = Sunday | ||
// | ||
// | ||
// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018. | ||
// | ||
// GNU Lesser General Public License 3.0 | ||
// https://www.gnu.org/licenses/lgpl-3.0.en.html | ||
// ---------------------------------------------------------------------------- | ||
|
||
import "BokkyPooBahsDateTimeLibrary.sol"; | ||
|
||
contract BokkyPooBahsDateTimeContract { | ||
uint public constant SECONDS_PER_DAY = 24 * 60 * 60; | ||
uint public constant SECONDS_PER_HOUR = 60 * 60; | ||
uint public constant SECONDS_PER_MINUTE = 60; | ||
int public constant OFFSET19700101 = 2440588; | ||
|
||
uint public constant DOW_MON = 1; | ||
uint public constant DOW_TUE = 2; | ||
uint public constant DOW_WED = 3; | ||
uint public constant DOW_THU = 4; | ||
uint public constant DOW_FRI = 5; | ||
uint public constant DOW_SAT = 6; | ||
uint public constant DOW_SUN = 7; | ||
|
||
function _now() public view returns (uint timestamp) { | ||
timestamp = now; | ||
} | ||
function _nowDateTime() public view returns (uint year, uint month, uint day, uint hour, uint minute, uint second) { | ||
(year, month, day, hour, minute, second) = BokkyPooBahsDateTimeLibrary.timestampToDateTime(now); | ||
} | ||
function _daysFromDate(uint year, uint month, uint day) public pure returns (uint _days) { | ||
return BokkyPooBahsDateTimeLibrary._daysFromDate(year, month, day); | ||
} | ||
function _daysToDate(uint _days) public pure returns (uint year, uint month, uint day) { | ||
return BokkyPooBahsDateTimeLibrary._daysToDate(_days); | ||
} | ||
function timestampFromDate(uint year, uint month, uint day) public pure returns (uint timestamp) { | ||
return BokkyPooBahsDateTimeLibrary.timestampFromDate(year, month, day); | ||
} | ||
function timestampFromDateTime(uint year, uint month, uint day, uint hour, uint minute, uint second) public pure returns (uint timestamp) { | ||
return BokkyPooBahsDateTimeLibrary.timestampFromDateTime(year, month, day, hour, minute, second); | ||
} | ||
function timestampToDate(uint timestamp) public pure returns (uint year, uint month, uint day) { | ||
(year, month, day) = BokkyPooBahsDateTimeLibrary.timestampToDate(timestamp); | ||
} | ||
function timestampToDateTime(uint timestamp) public pure returns (uint year, uint month, uint day, uint hour, uint minute, uint second) { | ||
(year, month, day, hour, minute, second) = BokkyPooBahsDateTimeLibrary.timestampToDateTime(timestamp); | ||
} | ||
|
||
function isLeapYear(uint timestamp) public pure returns (bool leapYear) { | ||
leapYear = BokkyPooBahsDateTimeLibrary.isLeapYear(timestamp); | ||
} | ||
function _isLeapYear(uint year) public pure returns (bool leapYear) { | ||
leapYear = BokkyPooBahsDateTimeLibrary._isLeapYear(year); | ||
} | ||
function isWeekDay(uint timestamp) public pure returns (bool weekDay) { | ||
weekDay = BokkyPooBahsDateTimeLibrary.isWeekDay(timestamp); | ||
} | ||
function isWeekEnd(uint timestamp) public pure returns (bool weekEnd) { | ||
weekEnd = BokkyPooBahsDateTimeLibrary.isWeekEnd(timestamp); | ||
} | ||
|
||
function getDaysInMonth(uint timestamp) public pure returns (uint daysInMonth) { | ||
daysInMonth = BokkyPooBahsDateTimeLibrary.getDaysInMonth(timestamp); | ||
} | ||
function _getDaysInMonth(uint year, uint month) public pure returns (uint daysInMonth) { | ||
daysInMonth = BokkyPooBahsDateTimeLibrary._getDaysInMonth(year, month); | ||
} | ||
function getDayOfWeek(uint timestamp) public pure returns (uint dayOfWeek) { | ||
dayOfWeek = BokkyPooBahsDateTimeLibrary.getDayOfWeek(timestamp); | ||
} | ||
|
||
function getYear(uint timestamp) public pure returns (uint year) { | ||
year = BokkyPooBahsDateTimeLibrary.getYear(timestamp); | ||
} | ||
function getMonth(uint timestamp) public pure returns (uint month) { | ||
month = BokkyPooBahsDateTimeLibrary.getMonth(timestamp); | ||
} | ||
function getDay(uint timestamp) public pure returns (uint day) { | ||
day = BokkyPooBahsDateTimeLibrary.getDay(timestamp); | ||
} | ||
function getHour(uint timestamp) public pure returns (uint hour) { | ||
hour = BokkyPooBahsDateTimeLibrary.getHour(timestamp); | ||
} | ||
function getMinute(uint timestamp) public pure returns (uint minute) { | ||
minute = BokkyPooBahsDateTimeLibrary.getMinute(timestamp); | ||
} | ||
function getSecond(uint timestamp) public pure returns (uint second) { | ||
second = BokkyPooBahsDateTimeLibrary.getSecond(timestamp); | ||
} | ||
|
||
function addYears(uint timestamp, uint _years) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.addYears(timestamp, _years); | ||
} | ||
function addMonths(uint timestamp, uint _months) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.addMonths(timestamp, _months); | ||
} | ||
function addDays(uint timestamp, uint _days) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.addDays(timestamp, _days); | ||
} | ||
function addHours(uint timestamp, uint _hours) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.addHours(timestamp, _hours); | ||
} | ||
function addMinutes(uint timestamp, uint _minutes) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.addMinutes(timestamp, _minutes); | ||
} | ||
function addSeconds(uint timestamp, uint _seconds) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.addSeconds(timestamp, _seconds); | ||
} | ||
|
||
function subYears(uint timestamp, uint _years) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.subYears(timestamp, _years); | ||
} | ||
function subMonths(uint timestamp, uint _months) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.subMonths(timestamp, _months); | ||
} | ||
function subDays(uint timestamp, uint _days) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.subDays(timestamp, _days); | ||
} | ||
function subHours(uint timestamp, uint _hours) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.subHours(timestamp, _hours); | ||
} | ||
function subMinutes(uint timestamp, uint _minutes) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.subMinutes(timestamp, _minutes); | ||
} | ||
function subSeconds(uint timestamp, uint _seconds) public pure returns (uint newTimestamp) { | ||
newTimestamp = BokkyPooBahsDateTimeLibrary.subSeconds(timestamp, _seconds); | ||
} | ||
|
||
function diffYears(uint fromTimestamp, uint toTimestamp) public pure returns (uint _years) { | ||
_years = BokkyPooBahsDateTimeLibrary.diffYears(fromTimestamp, toTimestamp); | ||
} | ||
function diffMonths(uint fromTimestamp, uint toTimestamp) public pure returns (uint _months) { | ||
_months = BokkyPooBahsDateTimeLibrary.diffMonths(fromTimestamp, toTimestamp); | ||
} | ||
function diffDays(uint fromTimestamp, uint toTimestamp) public pure returns (uint _days) { | ||
_days = BokkyPooBahsDateTimeLibrary.diffDays(fromTimestamp, toTimestamp); | ||
} | ||
function diffHours(uint fromTimestamp, uint toTimestamp) public pure returns (uint _hours) { | ||
_hours = BokkyPooBahsDateTimeLibrary.diffHours(fromTimestamp, toTimestamp); | ||
} | ||
function diffMinutes(uint fromTimestamp, uint toTimestamp) public pure returns (uint _minutes) { | ||
_minutes = BokkyPooBahsDateTimeLibrary.diffMinutes(fromTimestamp, toTimestamp); | ||
} | ||
function diffSeconds(uint fromTimestamp, uint toTimestamp) public pure returns (uint _seconds) { | ||
_seconds = BokkyPooBahsDateTimeLibrary.diffSeconds(fromTimestamp, toTimestamp); | ||
} | ||
} |
Oops, something went wrong.