Created
May 28, 2019 09:27
-
-
Save A/67683ba065271ae47cc5890f5e61fb21 to your computer and use it in GitHub Desktop.
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 toMs = (h, m) => { | |
let ms = 0; | |
ms += h * 60 * 60 * 1000; | |
ms += m * 60 * 1000; | |
return ms; | |
} | |
export const isInTimeRange = (from, to, date = new Date()) => { | |
const d = toMs(date.getUTCHours(), date.getUTCMinutes()); | |
const start = toMs(from.hours, from.mins); | |
const end = toMs(to.hours, to.mins); | |
return start < end | |
? d >= start && d <= end | |
: d >= start || d <= end | |
} |
@alexeyten да в общем-то без разницы с ms или с min)
Для результата нет, но зачем считать больше? =)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
А
ms
-то зачем? Хватило бы(h, m) => h * 60 + m;