150 lines
4.0 KiB
Bash
Executable File
150 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
||
# Test UTC timestamp handling in Display Manager
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||
EVENT_FILE="$PROJECT_ROOT/src/current_event.json"
|
||
|
||
echo "🕐 UTC Timestamp Test for Display Manager"
|
||
echo "=========================================="
|
||
echo ""
|
||
|
||
# Get current UTC and local times
|
||
UTC_NOW=$(date -u '+%Y-%m-%d %H:%M:%S')
|
||
LOCAL_NOW=$(date '+%Y-%m-%d %H:%M:%S')
|
||
TIMEZONE=$(date +%Z)
|
||
UTC_OFFSET=$(date +%z)
|
||
|
||
echo "📅 Current Time Information:"
|
||
echo " UTC Time: $UTC_NOW"
|
||
echo " Local Time: $LOCAL_NOW"
|
||
echo " Timezone: $TIMEZONE (UTC$UTC_OFFSET)"
|
||
echo ""
|
||
|
||
# Calculate timestamps for testing
|
||
# Start: 1 minute ago (UTC)
|
||
START_TIME=$(date -u -d '1 minute ago' '+%Y-%m-%d %H:%M:%S')
|
||
# End: 10 minutes from now (UTC)
|
||
END_TIME=$(date -u -d '10 minutes' '+%Y-%m-%d %H:%M:%S')
|
||
|
||
echo "🧪 Test Scenarios:"
|
||
echo ""
|
||
echo "1️⃣ Test Active Event (should display NOW)"
|
||
echo " Create event with:"
|
||
echo " - Start: $START_TIME UTC (1 minute ago)"
|
||
echo " - End: $END_TIME UTC (in 10 minutes)"
|
||
echo ""
|
||
|
||
read -p "Press Enter to create test event..."
|
||
|
||
cat > "$EVENT_FILE" <<EOF
|
||
{
|
||
"id": 998,
|
||
"title": "UTC Test - Active Event",
|
||
"start": "$START_TIME",
|
||
"end": "$END_TIME",
|
||
"web": {
|
||
"url": "https://www.timeanddate.com/worldclock/timezone/utc"
|
||
}
|
||
}
|
||
EOF
|
||
|
||
echo "✅ Created test event:"
|
||
cat "$EVENT_FILE" | jq .
|
||
echo ""
|
||
echo "⏱️ Display Manager should detect this as ACTIVE and start displaying"
|
||
echo " Check the logs with: tail -f logs/display_manager.log"
|
||
echo ""
|
||
|
||
read -p "Press Enter to continue to next test..."
|
||
echo ""
|
||
|
||
# Test 2: Event in the future
|
||
FUTURE_START=$(date -u -d '5 minutes' '+%Y-%m-%d %H:%M:%S')
|
||
FUTURE_END=$(date -u -d '15 minutes' '+%Y-%m-%d %H:%M:%S')
|
||
|
||
echo "2️⃣ Test Future Event (should NOT display yet)"
|
||
echo " Create event with:"
|
||
echo " - Start: $FUTURE_START UTC (in 5 minutes)"
|
||
echo " - End: $FUTURE_END UTC (in 15 minutes)"
|
||
echo ""
|
||
|
||
read -p "Press Enter to create future event..."
|
||
|
||
cat > "$EVENT_FILE" <<EOF
|
||
{
|
||
"id": 997,
|
||
"title": "UTC Test - Future Event",
|
||
"start": "$FUTURE_START",
|
||
"end": "$FUTURE_END",
|
||
"web": {
|
||
"url": "https://www.timeanddate.com/worldclock/timezone/utc"
|
||
}
|
||
}
|
||
EOF
|
||
|
||
echo "✅ Created future event:"
|
||
cat "$EVENT_FILE" | jq .
|
||
echo ""
|
||
echo "⏱️ Display Manager should detect this as NOT ACTIVE YET"
|
||
echo " It should stop any current display"
|
||
echo " Check logs: tail -f logs/display_manager.log"
|
||
echo ""
|
||
|
||
read -p "Press Enter to continue to next test..."
|
||
echo ""
|
||
|
||
# Test 3: Event in the past
|
||
PAST_START=$(date -u -d '30 minutes ago' '+%Y-%m-%d %H:%M:%S')
|
||
PAST_END=$(date -u -d '20 minutes ago' '+%Y-%m-%d %H:%M:%S')
|
||
|
||
echo "3️⃣ Test Past Event (should NOT display - already ended)"
|
||
echo " Create event with:"
|
||
echo " - Start: $PAST_START UTC (30 minutes ago)"
|
||
echo " - End: $PAST_END UTC (20 minutes ago)"
|
||
echo ""
|
||
|
||
read -p "Press Enter to create past event..."
|
||
|
||
cat > "$EVENT_FILE" <<EOF
|
||
{
|
||
"id": 996,
|
||
"title": "UTC Test - Past Event",
|
||
"start": "$PAST_START",
|
||
"end": "$PAST_END",
|
||
"web": {
|
||
"url": "https://www.timeanddate.com/worldclock/timezone/utc"
|
||
}
|
||
}
|
||
EOF
|
||
|
||
echo "✅ Created past event:"
|
||
cat "$EVENT_FILE" | jq .
|
||
echo ""
|
||
echo "⏱️ Display Manager should detect this as ALREADY ENDED"
|
||
echo " It should stop any current display"
|
||
echo " Check logs: tail -f logs/display_manager.log"
|
||
echo ""
|
||
|
||
read -p "Press Enter to clean up..."
|
||
|
||
# Clean up
|
||
rm -f "$EVENT_FILE"
|
||
echo ""
|
||
echo "🧹 Cleaned up test event file"
|
||
echo ""
|
||
echo "📊 Summary:"
|
||
echo "==========="
|
||
echo ""
|
||
echo "✅ Test 1: Active event (past start, future end) → Should DISPLAY"
|
||
echo "✅ Test 2: Future event (future start, future end) → Should NOT display yet"
|
||
echo "✅ Test 3: Past event (past start, past end) → Should NOT display"
|
||
echo ""
|
||
echo "📝 The Display Manager should now correctly handle UTC timestamps!"
|
||
echo ""
|
||
echo "💡 Tips for debugging:"
|
||
echo " • Watch logs: tail -f logs/display_manager.log"
|
||
echo " • Check timezone: date; date -u"
|
||
echo " • The Display Manager logs show both UTC and comparison times"
|
||
echo ""
|