Created
July 28, 2023 14:13
-
-
Save 8ctopotamus/167b46427d55c3a7019ebc7f592e294f to your computer and use it in GitHub Desktop.
Detecting if data is stale after a certain time period.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const savedTimestamp = 1690509844000 // saved over 12 hours ago in localStorage | |
const savedTimestamp = 1690553044000 // saved under 12 hours ago in localStorage | |
const twelveHoursDifference = 43200000 // 12 hours in milliseconds | |
const now = new Date().getTime() // current timestamp | |
const isDataStale = (now, timestamp, difference) => now > timestamp + difference | |
const shouldRefresh = isDataStale(now, savedTimestamp, twelveHoursDifference) | |
console.log(shouldRefresh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment