The 3:47 AM Wake-Up Call
Imagine this: It’s nearly 4 AM. I’m halfway through a dream involving dragons and discounted coffee beans when suddenly, my phone lights up like Times Square on New Year’s Eve.
Not a meme. Not a viral tweet. Nope—WhatsApp is blowing up with angry texts from night shift workers.
“Why am I getting a ‘missed clock-in’ alert? I’m at work. Right now.”
Spoiler: They were telling the truth. My ClockIn system just didn’t believe them.
The Crime: Night Shifts That Span Time and Space
Here’s where I screwed up: My notification system only checked for clock-ins that happened today. Night shift workers who started yesterday but were still working? They were invisible. Ghosts. Phantoms in the SQL WHERE clause.
The original logic was hilariously inadequate:
// OLD: Only checked current date
WHERE DATE(clock_in_time) = ?
This worked great for day shift employees. For night shifters? It was like checking your mail one day late and wondering why the package’s gone.
The Fix: Teaching the System About “Yesterday”
Time to teach my code some humility—and some history.
I updated the logic to check both today and yesterday for active clock-ins, especially for those brave souls working from 11 PM to 7 AM:
// NEW: Look across date boundaries
WHERE (DATE(clock_in_time) = ? OR DATE(clock_in_time) = ?)
AND status = 'clocked_in'
And for the notification logic:
if (user.is_night_shift) {
const nightShiftStart = moment(`${yesterday} ${user.start_time}`, 'YYYY-MM-DD HH:mm:ss');
const nightShiftEnd = moment(`${today} ${user.end_time}`, 'YYYY-MM-DD HH:mm:ss');
if (currentTime.isAfter(nightShiftStart.clone().add(30, 'minutes'))) {
// Send night shift notification
}
}
Now the system’s smart enough to know they’re working—even if the date has changed under their feet.
Notifications That Don’t Suck
The old WhatsApp message was vague at best:
“Employee missed clock-in.”
No context. No shift type. Just stress.
The new message tells a full story:
// Updated WhatsApp message
if (shiftInfo.is_night_shift) {
const startTime = moment(shiftInfo.start_time, 'HH:mm:ss').format('h:mm A');
const endTime = moment(shiftInfo.end_time, 'HH:mm:ss').format('h:mm A');
shiftDescription = `${startTime} (yesterday) - ${endTime} (today)`;
timeReference = `Night shift (${shiftInfo.shift_name || 'Unknown'})`;
}
Now it sounds like this:
🚨 Missed Clock-In Alert
Jane Smith – Security
Shift: Night shift (Night): 11:00 PM (yesterday) – 7:00 AM (today)
Current Time: 12:00 AM
That kind of clarity should be bottled and sold to every group chat ever.
Frontend? Yes, I Touched That Too
Even the admin panel now admits that night shift people exist:
<Typography variant="subtitle2" sx={{ fontWeight: 'bold', mb: 1, mt: 2 }}>
🌙 Night Shift Support:
</Typography>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 0.5 }}>
<Typography variant="body2">• Detects active night shift workers (yesterday to today)</Typography>
<Typography variant="body2">• Prevents false alarms for cross-day shifts</Typography>
</Box>
Admins now get a visual reminder that yes, night shifts are complicated, but the system gets it.
Cron Jobs, Now Night-Aware
Before the fix, cron jobs only checked during the day. So night shifts were basically left to fend for themselves.
Now, they run at:
-
🕖 7:30 AM, 8:30 AM (for night shift wrap-ups)
-
🌙 11:30 PM (for late starters)
The 11:30 PM check is my favorite. It’s like the system gently tapping your shoulder saying, “You okay, buddy? You were supposed to be here half an hour ago.”
Debug Logging, Narrator-Style
I added some verbose logs, because midnight bugs deserve midnight poetry:
Checking for missed clock-ins on 2025-06-08 (also checking yesterday for night shifts)
Night shift user Jane Smith did not clock in for their shift (Night: 23:00:00 yesterday – 07:00:00 today)
Now, even when things break, I know exactly why they’re breaking—without having to run 37 SQL queries manually.
The 20-Minute Panic Post-Deployment
No good story ends without at least one false victory.
After deploying, a guard messaged me again:
“Still getting alerts.”
Cue panic. Turns out the notification cache was still holding old entries. One quick restart later, problem solved. Classic fix: clear cache, chug coffee, look confident.
Conclusion: Night Shifts Are Real. And So Is My Sleep Deprivation.
This wasn’t just about fixing a bug—it was about respecting how real people work.
Now, the system:
-
✅ Recognizes night shift clock-ins from yesterday
-
✅ Sends context-aware notifications
-
✅ Stops harassing employees mid-shift
-
✅ Keeps my phone blessedly quiet after midnight
My only regret? Not doing this fix before building the original feature. But hey, better late than falsely flagged.
In case you missed my previous post where i began this system development: Building a Web-Based Clocking System: A 48-Hour Sprint (and a Latte or Two)
Lessons From the Night Shift Patch
-
Night shift logic isn’t optional—it’s critical.
-
Cross-day problems require cross-day solutions (duh, but seriously).
-
Notifications need context, or they’ll just cause panic.
-
Test your code like it’s 3 AM and your server’s haunted.
-
Logging is your late-night best friend.