-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathTestDateTime.sol
142 lines (129 loc) · 7.09 KB
/
TestDateTime.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
import "BokkyPooBahsDateTimeLibrary.sol";
// ----------------------------------------------------------------------------
// Testing BokkyPooBah's DateTime Library
//
// https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary
//
// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018-2019. The MIT Licence.
// ----------------------------------------------------------------------------
contract TestDateTime {
using BokkyPooBahsDateTimeLibrary for uint;
uint public nextYear;
function test() public {
uint today = now;
nextYear = today.addYears(1);
}
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 isValidDate(uint year, uint month, uint day) public pure returns (bool valid) {
valid = BokkyPooBahsDateTimeLibrary.isValidDate(year, month, day);
}
function isValidDateTime(uint year, uint month, uint day, uint hour, uint minute, uint second) public pure returns (bool valid) {
valid = BokkyPooBahsDateTimeLibrary.isValidDateTime(year, month, day, hour, minute, second);
}
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);
}
}