Created
July 11, 2019 00:30
-
-
Save Gustavo-Kuze/2f664b8ebdd301d1f168c9aa0632efe4 to your computer and use it in GitHub Desktop.
Métodos para comparação de datas, ignorando as horas
This file contains hidden or 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 _compareDates = (date1, date2) => { | |
date2.setHours(date1.getHours()); | |
date2.setMinutes(date1.getMinutes()); | |
date2.setSeconds(date1.getSeconds()); | |
date2.setMilliseconds(date1.getMilliseconds()); | |
return date2 - date1; | |
}; | |
const isDatePast = (now, date) => _compareDates(now, date) < 0; | |
const isDateFuture = (now, date) => _compareDates(now, date) > 0; | |
const areDatesEqual = (now, date) => _compareDates(now, date) === 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment