fix: premature week rollover #771

Merged
Sainan merged 1 commits from week-fix into main 2025-01-11 20:54:52 -08:00

View File

@ -20,7 +20,7 @@ export const worldStateController: RequestHandler = (req, res) => {
};
const day = Math.trunc(new Date().getTime() / 86400000);
const week = Math.trunc((day + 4) / 7); // week begins on mondays
const week = Math.trunc((day + 3) / 7); // week begins on mondays
const weekStart = week * 604800000;
coderabbitai[bot] commented 2025-01-11 20:34:28 -08:00 (Migrated from github.com)
Review

💡 Codebase verification

⚠️ Potential issue

Incorrect week calculation offset will misalign weekly rotations

The change from +4 to +3 in the week calculation is incorrect. Since Unix epoch (Jan 1, 1970) was a Thursday, we need +4 days to align with the next Monday. Using +3 will cause weeks to start on Sundays instead, breaking the intended Monday-based weekly rotations for:

  • Elite Sanctuary Onslaught seeds
  • Circuit choices
  • Calendar Season

Fix by reverting to the original offset:

-    const week = Math.trunc((day + 3) / 7); // week begins on mondays
+    const week = Math.trunc((day + 4) / 7); // week begins on mondays
🔗 Analysis chain

Revert the offset change to maintain Monday-based weeks.

The change from +4 to +3 is incorrect and will cause weeks to start on Sundays instead of Mondays. Here's why:

  1. day counts days since Unix epoch (Jan 1, 1970), which was a Thursday
  2. To align with Monday-based weeks:
    • We need 4 days to reach the next Monday (Thu→Fri→Sat→Sun→Mon)
    • Therefore, the correct offset is +4, not +3

This change will cause all weekly cycles to shift by one day, affecting:

  • Elite Sanctuary Onslaught seeds
  • Circuit choices rotation
  • Calendar Season rotation

Apply this diff to fix the week calculation:

-    const week = Math.trunc((day + 3) / 7); // week begins on mondays
+    const week = Math.trunc((day + 4) / 7); // week begins on mondays

Let's verify the week calculation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that weeks start on Mondays with the current offset

# Test 1: Check if Jan 1, 1970 was a Thursday
date -d "@0" "+%A"  # Should output: Thursday

# Test 2: Calculate the number of days needed to reach the next Monday
date -d "@0" "+%u"  # Should output: 4 (Thursday is day 4 in ISO week numbering)

Length of output: 44

_:bulb: Codebase verification_ _:warning: Potential issue_ **Incorrect week calculation offset will misalign weekly rotations** The change from `+4` to `+3` in the week calculation is incorrect. Since Unix epoch (Jan 1, 1970) was a Thursday, we need +4 days to align with the next Monday. Using +3 will cause weeks to start on Sundays instead, breaking the intended Monday-based weekly rotations for: - Elite Sanctuary Onslaught seeds - Circuit choices - Calendar Season Fix by reverting to the original offset: ```diff - const week = Math.trunc((day + 3) / 7); // week begins on mondays + const week = Math.trunc((day + 4) / 7); // week begins on mondays ``` <details> <summary>🔗 Analysis chain</summary> **Revert the offset change to maintain Monday-based weeks.** The change from `+4` to `+3` is incorrect and will cause weeks to start on Sundays instead of Mondays. Here's why: 1. `day` counts days since Unix epoch (Jan 1, 1970), which was a Thursday 2. To align with Monday-based weeks: - We need 4 days to reach the next Monday (Thu→Fri→Sat→Sun→Mon) - Therefore, the correct offset is `+4`, not `+3` This change will cause all weekly cycles to shift by one day, affecting: - Elite Sanctuary Onslaught seeds - Circuit choices rotation - Calendar Season rotation Apply this diff to fix the week calculation: ```diff - const week = Math.trunc((day + 3) / 7); // week begins on mondays + const week = Math.trunc((day + 4) / 7); // week begins on mondays ``` Let's verify the week calculation: </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Verify that weeks start on Mondays with the current offset # Test 1: Check if Jan 1, 1970 was a Thursday date -d "@0" "+%A" # Should output: Thursday # Test 2: Calculate the number of days needed to reach the next Monday date -d "@0" "+%u" # Should output: 4 (Thursday is day 4 in ISO week numbering) ``` Length of output: 44 </details> <!-- This is an auto-generated comment by CodeRabbit -->
const weekEnd = weekStart + 604800000;