Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions backend/workers/closeCheckins.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ export default (cron, fetch) => {
async function sortAndFilterEvents() {
const events = await fetchEvents();

const now = Date.now();

// Get current time and set to date variable
const now = new Date();
const laNow = new Date(now.toLocaleString('en-US', { timeZone: 'America/Los_Angeles' }));
const laNowMs = laNow.getTime();
// Filter events if event date is after now but before thirty minutes from now
Comment on lines +44 to +48
if (events && events.length > 0) {
const sortedEvents = events.filter((event) => {
if (!event.date) {
return false;
}
const threeHoursFromStartTime = new Date(event.date).getTime() + 10800000;
if (Number.isNaN(threeHoursFromStartTime)) return false;
return now >= threeHoursFromStartTime && event.checkInReady === true;
return laNowMs >= threeHoursFromStartTime && event.checkInReady === true;
Comment on lines +48 to +58
});

return sortedEvents;
Expand Down
15 changes: 12 additions & 3 deletions backend/workers/openCheckins.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,26 @@ export default (cron, fetch) => {
async function sortAndFilterEvents() {
const events = await fetchEvents();

const now = Date.now();
const thirtyMinutesFromNow = now + 1800000;
// Get current time in LA and set to date variable
const now = new Date();
const laNow = new Date(now.toLocaleString('en-US', { timeZone: 'America/Los_Angeles' }));
const laNowMs = laNow.getTime();
// Calculate thirty minutes from now
const thirtyMinutesFromLaNow = laNowMs + 1800000;
Comment on lines +44 to +49

if (events && events.length > 0) {
const sortedEvents = events.filter((event) => {
if (!event.date) {
// handle if event date is null/undefined
// false meaning don't include in sortedEvents
console.log('Events exist but no date');
return false;
Comment on lines 53 to 57
}
const startMs = new Date(event.date).getTime();
if (Number.isNaN(startMs)) return false;
return startMs >= now && startMs <= thirtyMinutesFromNow && event.checkInReady === false;
return (
startMs >= laNowMs && startMs <= thirtyMinutesFromLaNow && event.checkInReady === false
);
});
return sortedEvents;
}
Expand Down
Loading