From 2578ae80e1d4a436814e1323daa7dd03a587e716 Mon Sep 17 00:00:00 2001 From: Josh Betz Date: Mon, 4 Dec 2023 10:44:32 -0600 Subject: [PATCH] Fix: Add timezone support to accessonWeekdays Rule Sets a timezone for the accessonWeekdaysOnly rule instead of using UTC time. --- src/rules/access-on-weekdays-only-for-an-app.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rules/access-on-weekdays-only-for-an-app.js b/src/rules/access-on-weekdays-only-for-an-app.js index 6486b234..08b6be66 100644 --- a/src/rules/access-on-weekdays-only-for-an-app.js +++ b/src/rules/access-on-weekdays-only-for-an-app.js @@ -9,10 +9,11 @@ function accessOnWeekdaysOnly(user, context, callback) { if (context.clientName === 'TheAppToCheckAccessTo') { - const date = new Date(); - const d = date.getDay(); + // Get the current day in US Central Time + const day = new Date().toLocaleDateString('en-US', { timeZone: 'America/Chicago', weekday: 'long'}); - if (d === 0 || d === 6) { + // Don't allow access on the weekend + if (!['Saturday', 'Sunday'].includes(day)) { return callback( new UnauthorizedError('This app is available during the week') );