-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-window.js
More file actions
91 lines (74 loc) · 3.17 KB
/
debug-window.js
File metadata and controls
91 lines (74 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
/**
* Debug script to check current IRL window state
* Run this to see what's happening with the current window
*/
import mongoose from 'mongoose';
import moment from 'moment-timezone';
import IrlWindow from './model/irl-window.model.js';
// Connect to MongoDB (adjust connection string as needed)
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/irl';
async function debugWindow() {
try {
await mongoose.connect(MONGODB_URI);
console.log('Connected to MongoDB');
const nowUtc = moment.utc();
console.log('Current UTC time:', nowUtc.toISOString());
// Get the most recent window that has started
const currentWindow = await IrlWindow.findOne({
startAt: { $lte: nowUtc.toDate() }
}).sort({ startAt: -1 });
if (!currentWindow) {
console.log('❌ No window found that has started');
return;
}
console.log('\n📅 Current Window Details:');
console.log('Window ID:', currentWindow._id);
console.log('Start At:', currentWindow.startAt);
console.log('End At:', currentWindow.endAt);
console.log('Late Cutoff At:', currentWindow.lateCutoffAt);
console.log('On Time Deadline:', currentWindow.onTimeDeadline);
const windowStart = moment(currentWindow.startAt);
const windowEnd = moment(currentWindow.endAt);
const lateCutoff = currentWindow.lateCutoffAt ? moment(currentWindow.lateCutoffAt) : null;
console.log('\n⏰ Time Analysis:');
console.log('Hours since start:', nowUtc.diff(windowStart, 'hours', true).toFixed(2));
console.log('Hours since end:', nowUtc.diff(windowEnd, 'hours', true).toFixed(2));
if (lateCutoff) {
console.log('Hours since late cutoff:', nowUtc.diff(lateCutoff, 'hours', true).toFixed(2));
}
// Test the posting logic
let cutoffReason = '';
let lateCutoffTime;
if (currentWindow.lateCutoffAt && moment(currentWindow.lateCutoffAt).isAfter(windowStart)) {
lateCutoffTime = moment(currentWindow.lateCutoffAt);
cutoffReason = 'lateCutoffAt';
} else if (!currentWindow.lateCutoffAt) {
lateCutoffTime = windowStart.clone().add(24, 'hours');
cutoffReason = '24h-late-posting';
} else if (moment(currentWindow.endAt).isAfter(windowStart)) {
lateCutoffTime = moment(currentWindow.endAt);
cutoffReason = 'endAt';
} else {
lateCutoffTime = windowStart.clone().add(24, 'hours');
cutoffReason = '24h-fallback';
}
const canPost = nowUtc.isBetween(windowStart, lateCutoffTime, null, '[]');
console.log('\n🎯 Posting Logic:');
console.log('Cutoff reason:', cutoffReason);
console.log('Late cutoff time:', lateCutoffTime.toISOString());
console.log('Can post:', canPost);
console.log('Hours until cutoff:', lateCutoffTime.diff(nowUtc, 'hours', true).toFixed(2));
if (!canPost) {
console.log('❌ POSTING BLOCKED: Outside posting window');
} else {
console.log('✅ POSTING ALLOWED: Within posting window');
}
} catch (error) {
console.error('Error:', error);
} finally {
await mongoose.disconnect();
console.log('\nDisconnected from MongoDB');
}
}
debugWindow();