I have written the following code (and accompanying unit tests) and it works fine from what I can tell. However I'd like to use Date-fns to do this as my project is using this for most date-related code and I'd rather avoid maintaining extra code.
However I can't find out how to do time of date comparisons in the Date-fns documentation.
How can I check a date is before a given time of day using Date-fns?
const isBeforeTimeOfDay = (date, hours, minutes) => {
const dateHours = date.getUTCHours();
const dateMinutes = date.getUTCMinutes();
if (dateHours < hours) {
return true;
}
if (dateHours === hours) {
if (dateMinutes < minutes) {
return true;
}
}
return false;
};