-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bugfix-795] Fix date comparison edge case (#816)
* Fix updatedAt and markedStaleOn date comparison * Delete accidental file * Refactor * Cleanup * cleanup
- Loading branch information
1 parent
e200968
commit c750aa3
Showing
4 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
/// returns false if the dates are equal within the `equalityToleranceInSeconds` number of seconds | ||
/// otherwise returns true if `comparedDate` is after `date` | ||
|
||
export function isDateMoreRecentThan( | ||
date: Readonly<Date>, | ||
comparedDate: Readonly<Date> | ||
comparedDate: Readonly<Date>, | ||
equalityToleranceInSeconds = 0 | ||
): boolean { | ||
if (equalityToleranceInSeconds > 0) { | ||
const areDatesEqual = isDateEqualTo( | ||
date, | ||
comparedDate, | ||
equalityToleranceInSeconds | ||
); | ||
|
||
return !areDatesEqual && date > comparedDate; | ||
} | ||
|
||
return date > comparedDate; | ||
} | ||
|
||
export function isDateEqualTo( | ||
date: Date, | ||
otherDate: Date, | ||
toleranceInSeconds: number | ||
): boolean { | ||
const timestamp = date.getTime(); | ||
const otherTimestamp = otherDate.getTime(); | ||
const deltaInSeconds = Math.abs(timestamp - otherTimestamp) / 1000; | ||
return deltaInSeconds <= toleranceInSeconds; | ||
} |