Skip to content

Instantly share code, notes, and snippets.

@readevalprint
Last active September 13, 2017 14:52
Show Gist options
  • Save readevalprint/481759cbc10200f8b94f553fe779a40f to your computer and use it in GitHub Desktop.
Save readevalprint/481759cbc10200f8b94f553fe779a40f to your computer and use it in GitHub Desktop.
pragma solidity 0.4.15;
contract SimpleCron {
/// @notice Will return the next timesamp after the speicifed units have passed `timestamp`
function next(uint s,uint m,uint h, uint d, uint w, uint timestamp) constant returns (uint){
return (timestamp * 1 seconds) + (s * 1 seconds) + (m * 1 minutes) + (h * 1 hours) + _days(d) + _weeks(w);
}
/// @notice Will return the next timesamp after the speicifed units have passed `now`
function next(uint s,uint m,uint h, uint d, uint w) constant returns (uint){
return block.timestamp + (s * 1 seconds) + (m * 1 minutes) + (h * 1 hours) + _days(d) + _weeks(w);
}
function _days(uint d) constant internal returns (uint){
return (d * 24 hours);
}
function _weeks(uint w) constant internal returns (uint) {
return w * _days(7);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment