From the documentation :
block.timestamp (uint): current block timestamp as seconds since unix
epoch
So :
block.timestamp - userInfo[_owner][_index].stakeTime
Is the number of seconds between stakeTime
and block.timestamp
. Dividing by 86400 is dividing by the number of seconds in a day (60 seconds * 60 minutes * 24 hours = 86400)
return (block.timestamp - userInfo[_owner][_index].stakeTime) / 86400;
returns the number of whole days between stakeTime
and block.timstamp
this has nothing to do with 90 days here.
An alternative syntax could be :
return (block.timestamp - userInfo[_owner][_index].stakeTime) / 1 days;
how can I change that 90 days to any other value of my choice.
I found a contract with the same code here, that has the following unstake
function with a 1 day limit :
function unStake(uint256 _index) external {
address unStaker = msg.sender;
UserInfo storage userDetails = userInfo[unStaker][_index];
uint256 tokenId1 = userDetails.tokenId1;
uint256 timePassedSinceStaked = getTimePassedSinceStake(
unStaker,
_index
);
require(
timePassedSinceStaked >= 1,
"You can not unstake before 1 day"
);
userDetails = userInfo[unStaker][userInfo[unStaker].length - 1];
userInfo[unStaker].pop();
ERC721.safeTransferFrom(address(this), unStaker, tokenId1, "");
GemToken.claimByLuckyDragon(unStaker, 0);
emit UnStakedLuckyDragon(
unStaker,
tokenId1,
block.timestamp
);
}
Here it is limiting to 1 day of waiting time, by changing :
require(
timePassedSinceStaked >= 1,
"You can not unstake before 1 day"
);
to :
require(
timePassedSinceStaked >= 90,
"You can not unstake before 90 day"
);
It would require 90 days, of course you can set the value of your choice.
I hope that answers your question.