-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetTime.sol
More file actions
41 lines (36 loc) · 1.04 KB
/
Copy pathGetTime.sol
File metadata and controls
41 lines (36 loc) · 1.04 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract GetTime{
uint256 public campaignEnd;
constructor(uint256 _campaignEnd) {
require(_campaignEnd > block.timestamp, "End time must be in the future");
campaignEnd = _campaignEnd;
}
function getCurrentTimestamp() public view returns (uint256) {
return block.timestamp;
}
function timeLeft() public view returns (uint256) {
if (block.timestamp >= campaignEnd) {
return 0;
}
return campaignEnd - block.timestamp;
}
function timeLeftDetailed()
public
view
returns (
uint256 daysLeft,
uint256 hoursLeft,
uint256 minutesLeft,
uint256 secondsLeft
)
{
uint256 remaining = timeLeft();
daysLeft = remaining / 1 days;
remaining %= 1 days;
hoursLeft = remaining / 1 hours;
remaining %= 1 hours;
minutesLeft = remaining / 1 minutes;
secondsLeft = remaining % 1 minutes;
}
}