I wan't to get how long user has staked nft token in days. I recorded
staking time_stamp while staking and
un_staking time_stamp while un_staking. Now I wan't to calculate how many days user has staked for reward distribution based on days. How to do that?
Below is the general calculation for finding the days.
// Calculate the time difference between unstaking and staking timestamps. let time_difference = unstaking_timestamp .checked_sub(staking_timestamp) .ok_or(DispatchError::from("Timestamp overflow"))?; // Modify error accordingly // Convert the time difference to the number of days. let days_staked: u64 = time_difference .as_secs() .checked_div(86400) // T::SECONDS_PER_DAY = 86400 .unwrap_or(0);