Skip to content

Instantly share code, notes, and snippets.

@A
Created May 28, 2019 09:27
Show Gist options
  • Save A/67683ba065271ae47cc5890f5e61fb21 to your computer and use it in GitHub Desktop.
Save A/67683ba065271ae47cc5890f5e61fb21 to your computer and use it in GitHub Desktop.
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
}
@A
Copy link
Author

A commented Jun 25, 2019

@alexeyten да в общем-то без разницы с ms или с min)

@alexeyten
Copy link

Для результата нет, но зачем считать больше? =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment