Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit f80a9cc

Browse files
authoredJan 14, 2021
Add nextCastTime() to DssExec (#37)
1 parent d8d3aec commit f80a9cc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
 

‎src/DssExec.sol

+27
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ contract DssExec {
5353
return SpellAction(action).officeHours();
5454
}
5555

56+
function nextCastTime() external view returns (uint256 castTime) {
57+
require(eta != 0, "DssExec/spell-not-scheduled");
58+
castTime = block.timestamp > eta ? block.timestamp : eta; // Any day at XX:YY
59+
60+
if (SpellAction(action).officeHours()) {
61+
uint256 day = (castTime / 1 days + 3) % 7;
62+
uint256 hour = castTime / 1 hours % 24;
63+
uint256 minute = castTime / 1 minutes % 60;
64+
uint256 second = castTime % 60;
65+
66+
if (day >= 5) {
67+
castTime += (6 - day) * 1 days; // Go to Sunday XX:YY
68+
castTime += (24 - hour + 14) * 1 hours; // Go to 14:YY UTC Monday
69+
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
70+
} else {
71+
if (hour >= 21) {
72+
if (day == 4) castTime += 2 days; // If Friday, fast forward to Sunday XX:YY
73+
castTime += (24 - hour + 14) * 1 hours; // Go to 14:YY UTC next day
74+
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
75+
} else if (hour < 14) {
76+
castTime += (14 - hour) * 1 hours; // Go to 14:YY UTC same day
77+
castTime -= minute * 1 minutes + second; // Go to 14:00 UTC
78+
}
79+
}
80+
}
81+
}
82+
5683
// @param _description A string description of the spell
5784
// @param _expiration The timestamp this spell will expire. (Ex. now + 30 days)
5885
// @param _spellAction The address of the spell action

0 commit comments

Comments
 (0)
This repository has been archived.