Skip to content

Commit

Permalink
Fix: Add timezone support to accessonWeekdays Rule
Browse files Browse the repository at this point in the history
Sets a timezone for the accessonWeekdaysOnly rule instead of using UTC time.
  • Loading branch information
joshbetz authored Dec 4, 2023
1 parent 6111b60 commit 2578ae8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rules/access-on-weekdays-only-for-an-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
Expand Down

0 comments on commit 2578ae8

Please sign in to comment.