fix: 1999 calendar not working properly #777

Merged
Sainan merged 2 commits from 1999-calendar into main 2025-01-12 19:17:06 -08:00
Owner
No description provided.
coderabbitai[bot] commented 2025-01-12 18:40:10 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The pull request introduces modifications to the worldStateController in the time calculation logic. The changes center around introducing a new constant EPOCH, set to Monday, December 16, 2024, which serves as a reference point for calculating days and weeks. The method of computing day and week has been restructured, with the week calculation now directly derived from the day count without a previous offset.

A new property YearIteration has been added to the KnownCalendarSeasons structure, which is calculated by integer division of the week count by 4. This modification provides a mechanism to track yearly iterations based on the week progression. The changes aim to refine the time-tracking mechanism within the world state calculation system, potentially offering a more precise method of tracking temporal progression in the application's context.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The pull request introduces modifications to the `worldStateController` in the time calculation logic. The changes center around introducing a new constant `EPOCH`, set to Monday, December 16, 2024, which serves as a reference point for calculating days and weeks. The method of computing `day` and `week` has been restructured, with the week calculation now directly derived from the day count without a previous offset. A new property `YearIteration` has been added to the `KnownCalendarSeasons` structure, which is calculated by integer division of the week count by 4. This modification provides a mechanism to track yearly iterations based on the week progression. The changes aim to refine the time-tracking mechanism within the world state calculation system, potentially offering a more precise method of tracking temporal progression in the application's context. <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjHYmgDZkeAM0QAPHgEYAnO+YZrWehgFZCfGgAd0IqAGtELBI+KkJeakt5YAA5XFYhah4AdlzgAFVkLOgAZV0sbGNDE0gYCkZCWzwiUgpVOkYWdk4efkFRcUkZOUUWFRp1TR09atMYBHR0bGbickoaDqVurG5oGmDoZHTWP0UFJXG1DW1dfQgjGrNgZComAHoWHbjLaypkN/o8gqrEQ71CVEs9BK+FoZAAwoQvoQftQtPhkFxgAAiHHAADEeOgAEEAJKtdawxhHdinQRNJjwbDkZDmeBkZiM6KyNA4fBs6AAA3BkOhsIRSJRVAF0FsuCwEkQiJ5UmRMkOiBIWEQ9iY2CCrGU2tBtEVWFQRGgfPZussTFwlhNSsalsQHAgVDIDs2Uj8iDU1mQWjg/LCGqiXk8tvtjpwzoFvnk0uwjCFZDI4WljLkaZwXjoHsYFqi+Di9FwTHZGGglAOn2QMJ2ABpBQBRAAKAHk4QAJAXN4JIBl7Mj8WScVBV5AJJhGpjQXx0aAACgAsoiE82ACLiaDOABszYATAAGQ8AFgAlEGEOz4xhE2hUAFa147V6GNAhBgig1efz6NqtjUBQFYynErCWkgqACu2Xa9s2yaQbewRphmj7ztQ0gfgBHoSEkYFsEhgoJtKwSaPAhAEERGD0ABkiIhGjS2EUQTOgAzEG4pFAAjrgnBJM2VqCih6ailQ+DSugz6Rm+lKfooNEAdEREwZ2PbShaQldLwBAfiJ4TQD6lh8dArD2pIvCWIgH7nEJZYbKadKYCEqE8qZiA/Cg4jroGxhErRmiml4AnOTWsTxNQ+DyM2AoAJpkH4JL5jGfbQFmn45pgtEfpp/ICgA0s+WBwl49R+CUCXIIiyDSvWVDlvguAev2g7wOhNqyZs35EcWZDkAIAFSCgjlxvp0rnGe15QRyTLssWpbltyVZhQBHBmo5uXWqVPh+NAliECQoIIT8hBkcpthhM58gJRCiiaO0jlfj+gh/uy+lKHK2istabBreiblaco7KMmqXhVRlFDQLgvALjlhDDrY1gSEhRQzVyyDNlO4izsFigBJIylCYpgVOk0QlxTdSUPYi0pkDIVCKBdTUuemvn4oSRKWMl9Fmpa8N2eIDoOdVTlkA4vBhJsl06UIVlzpwgWyFU0BtnECTiQp2X0DwFOJdzpo8Fg6SZFKbm9VQtgYKBAokiV3i+FQFXfjTbkCi87yfCWyK/P8gLAqCbzClCMJ0OKXuSmiNXYriwDVKAtTQPUTkYAQqxtBsH5dH9PD7Icxy0ucYyqJMNwzPc8dQFsIL4AA+og9DIDXHpDWQKH0DX9Z+EEcdzPOriHrYrh7hWtjOIeACsbEYGerjjwAHOPTDOEIrhnkwthT8ebH0GxZDj3u49CHPzjOHcDy91nmh1w3Td09Zbc10nhhAA --> <!-- internal state end --> <!-- finishing_touch_checkbox_start --> ## Finishing Touches - [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings (Beta) <!-- finishing_touch_checkbox_end --> <!-- tips_start --> --- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit <commit_id>, please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-12 18:42:27 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/controllers/dynamic/worldStateController.ts (1)

Line range hint 91-101: Critical: Calendar progression is unrealistic

The current implementation has several issues:

  1. Each season lasts only 1 week, making a complete year cycle in 4 weeks
  2. YearIteration incrementing every 4 weeks makes years too short
  3. No validation for season data arrays
  4. Potential array bounds issues with negative week values

Consider these improvements:

+    // Constants for calendar calculations
+    const WEEKS_PER_SEASON = 13; // ~3 months
+    const SEASONS_PER_YEAR = 4;
+    const WEEKS_PER_YEAR = WEEKS_PER_SEASON * SEASONS_PER_YEAR;
+
+    // Validate season data
+    const seasonData = [
+        static1999WinterDays,
+        static1999SpringDays,
+        static1999SummerDays,
+        static1999FallDays
+    ];
+    if (seasonData.some(data => !Array.isArray(data))) {
+        throw new Error('Invalid season data format');
+    }
+
     worldState.KnownCalendarSeasons[0].Activation = { $date: { $numberLong: weekStart.toString() } };
     worldState.KnownCalendarSeasons[0].Expiry = { $date: { $numberLong: weekEnd.toString() } };
-    worldState.KnownCalendarSeasons[0].Season = ["CST_WINTER", "CST_SPRING", "CST_SUMMER", "CST_FALL"][week % 4];
-    worldState.KnownCalendarSeasons[0].Days = [
-        static1999WinterDays,
-        static1999SpringDays,
-        static1999SummerDays,
-        static1999FallDays
-    ][week % 4];
-    worldState.KnownCalendarSeasons[0].YearIteration = Math.trunc(week / 4);
+    const seasonIndex = Math.floor((week % WEEKS_PER_YEAR) / WEEKS_PER_SEASON);
+    worldState.KnownCalendarSeasons[0].Season = ["CST_WINTER", "CST_SPRING", "CST_SUMMER", "CST_FALL"][seasonIndex];
+    worldState.KnownCalendarSeasons[0].Days = seasonData[seasonIndex];
+    worldState.KnownCalendarSeasons[0].YearIteration = Math.floor(week / WEEKS_PER_YEAR);
🧹 Nitpick comments (1)
src/controllers/dynamic/worldStateController.ts (1)

179-179: Add documentation and type constraints for YearIteration

The new field lacks documentation and type constraints.

-    YearIteration: number;
+    /**
+     * Represents the current iteration/cycle of the year, starting from 0 for 1999.
+     * @example 0 = 1999, 1 = 2000, etc.
+     */
+    YearIteration: number & { __brand: 'NonNegativeInteger' };

Also consider adding runtime validation:

if (yearIteration < 0) {
    throw new Error('YearIteration cannot be negative');
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e201279eee and d92f96cef1.

📒 Files selected for processing (1)
  • src/controllers/dynamic/worldStateController.ts (4 hunks)
🔇 Additional comments (1)
src/controllers/dynamic/worldStateController.ts (1)

Line range hint 22-101: Verify calendar system usage and test coverage

Let's verify the calendar system implementation and its test coverage.

Verification successful

Calendar system implementation verified

The calendar system implementation is correct and well-structured:

  • Proper season cycling using week-based calculations
  • Non-overlapping day ranges across seasons (Winter: 6-87, Spring: 100-176, Summer: 186-270, Fall: 276-364)
  • Consistent event distribution including challenges, rewards, upgrades, and character events
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for calendar system usage and tests

# Look for tests related to the calendar system
echo "Checking for calendar-related tests..."
rg -l "test.*calendar|test.*season" --type ts

# Look for other uses of KnownCalendarSeasons
echo -e "\nChecking for KnownCalendarSeasons usage..."
rg "KnownCalendarSeasons" --type ts -C 2

# Look for date/time constants or utilities
echo -e "\nChecking for date/time utilities..."
rg "const.*(\bday\b|\bweek\b|\bEPOCH\b)" --type ts -C 2

Length of output: 2819


Script:

#!/bin/bash
# Check calendar-related implementations

# Look for static day arrays and their implementation
echo "Checking static day arrays..."
rg "static1999.*Days" --type ts -C 3

# Look for calendar interfaces
echo -e "\nChecking calendar interfaces..."
ast-grep --pattern 'interface ICalendarSeason {
  $$$
}'

# Look for any calendar-related configuration
echo -e "\nChecking for calendar config files..."
fd -e json -e ts -e js -x rg -l "CST_WINTER|CST_SPRING|CST_SUMMER|CST_FALL" {}

Length of output: 3308


Script:

#!/bin/bash
# Examine calendar JSON files

echo "Checking worldState.json default values..."
cat static/fixed_responses/worldState/worldState.json | jq '.KnownCalendarSeasons'

echo -e "\nChecking season day definitions..."
for season in winter spring summer fall; do
  echo -e "\n=== 1999_${season}_days.json ==="
  cat "static/fixed_responses/worldState/1999_${season}_days.json" | jq '.'
done

Length of output: 24575

**Actionable comments posted: 1** <details> <summary>🔭 Outside diff range comments (1)</summary><blockquote> <details> <summary>src/controllers/dynamic/worldStateController.ts (1)</summary><blockquote> Line range hint `91-101`: **Critical: Calendar progression is unrealistic** The current implementation has several issues: 1. Each season lasts only 1 week, making a complete year cycle in 4 weeks 2. YearIteration incrementing every 4 weeks makes years too short 3. No validation for season data arrays 4. Potential array bounds issues with negative week values Consider these improvements: ```diff + // Constants for calendar calculations + const WEEKS_PER_SEASON = 13; // ~3 months + const SEASONS_PER_YEAR = 4; + const WEEKS_PER_YEAR = WEEKS_PER_SEASON * SEASONS_PER_YEAR; + + // Validate season data + const seasonData = [ + static1999WinterDays, + static1999SpringDays, + static1999SummerDays, + static1999FallDays + ]; + if (seasonData.some(data => !Array.isArray(data))) { + throw new Error('Invalid season data format'); + } + worldState.KnownCalendarSeasons[0].Activation = { $date: { $numberLong: weekStart.toString() } }; worldState.KnownCalendarSeasons[0].Expiry = { $date: { $numberLong: weekEnd.toString() } }; - worldState.KnownCalendarSeasons[0].Season = ["CST_WINTER", "CST_SPRING", "CST_SUMMER", "CST_FALL"][week % 4]; - worldState.KnownCalendarSeasons[0].Days = [ - static1999WinterDays, - static1999SpringDays, - static1999SummerDays, - static1999FallDays - ][week % 4]; - worldState.KnownCalendarSeasons[0].YearIteration = Math.trunc(week / 4); + const seasonIndex = Math.floor((week % WEEKS_PER_YEAR) / WEEKS_PER_SEASON); + worldState.KnownCalendarSeasons[0].Season = ["CST_WINTER", "CST_SPRING", "CST_SUMMER", "CST_FALL"][seasonIndex]; + worldState.KnownCalendarSeasons[0].Days = seasonData[seasonIndex]; + worldState.KnownCalendarSeasons[0].YearIteration = Math.floor(week / WEEKS_PER_YEAR); ``` </blockquote></details> </blockquote></details> <details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>src/controllers/dynamic/worldStateController.ts (1)</summary><blockquote> `179-179`: **Add documentation and type constraints for YearIteration** The new field lacks documentation and type constraints. ```diff - YearIteration: number; + /** + * Represents the current iteration/cycle of the year, starting from 0 for 1999. + * @example 0 = 1999, 1 = 2000, etc. + */ + YearIteration: number & { __brand: 'NonNegativeInteger' }; ``` Also consider adding runtime validation: ```typescript if (yearIteration < 0) { throw new Error('YearIteration cannot be negative'); } ``` </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e201279eeef2d81ea486bb3abfd57976a36a2203 and d92f96cef1253a49585c1b94cf3a03d3e565b811. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/controllers/dynamic/worldStateController.ts` (4 hunks) </details> <details> <summary>🔇 Additional comments (1)</summary><blockquote> <details> <summary>src/controllers/dynamic/worldStateController.ts (1)</summary> Line range hint `22-101`: **Verify calendar system usage and test coverage** Let's verify the calendar system implementation and its test coverage. <details> <summary>✅ Verification successful</summary> <!-- [monologue] [task verify_calendar_final/2] [observations] 1. Calendar system is well-structured with: - Base configuration in worldState.json - Separate JSON files for each season's events - Consistent event types: CET_CHALLENGE, CET_REWARD, CET_UPGRADE, CET_PLOT 2. Each season has: - Unique day numbers (no overlap) - Winter: days 6-87 - Spring: days 100-176 - Summer: days 186-270 - Fall: days 276-364 3. Implementation details: - EPOCH set to Dec 16, 2024 - Week-based calculations for season cycling - YearIteration increments every 4 weeks - Each season has character birthday events (CET_PLOT) [analysis] 1. The implementation is complete and well-structured 2. Day ranges are properly separated between seasons 3. Event distribution is balanced across seasons 4. No overlapping or conflicting dates found [actions] Generate final verification response confirming the implementation is correct --> **Calendar system implementation verified** The calendar system implementation is correct and well-structured: - Proper season cycling using week-based calculations - Non-overlapping day ranges across seasons (Winter: 6-87, Spring: 100-176, Summer: 186-270, Fall: 276-364) - Consistent event distribution including challenges, rewards, upgrades, and character events </details> <details> <summary>🏁 Scripts executed</summary> The following scripts were executed for the analysis: Script: ```shell #!/bin/bash # Description: Check for calendar system usage and tests # Look for tests related to the calendar system echo "Checking for calendar-related tests..." rg -l "test.*calendar|test.*season" --type ts # Look for other uses of KnownCalendarSeasons echo -e "\nChecking for KnownCalendarSeasons usage..." rg "KnownCalendarSeasons" --type ts -C 2 # Look for date/time constants or utilities echo -e "\nChecking for date/time utilities..." rg "const.*(\bday\b|\bweek\b|\bEPOCH\b)" --type ts -C 2 ``` Length of output: 2819 --- Script: ```shell #!/bin/bash # Check calendar-related implementations # Look for static day arrays and their implementation echo "Checking static day arrays..." rg "static1999.*Days" --type ts -C 3 # Look for calendar interfaces echo -e "\nChecking calendar interfaces..." ast-grep --pattern 'interface ICalendarSeason { $$$ }' # Look for any calendar-related configuration echo -e "\nChecking for calendar config files..." fd -e json -e ts -e js -x rg -l "CST_WINTER|CST_SPRING|CST_SUMMER|CST_FALL" {} ``` Length of output: 3308 --- Script: ```shell #!/bin/bash # Examine calendar JSON files echo "Checking worldState.json default values..." cat static/fixed_responses/worldState/worldState.json | jq '.KnownCalendarSeasons' echo -e "\nChecking season day definitions..." for season in winter spring summer fall; do echo -e "\n=== 1999_${season}_days.json ===" cat "static/fixed_responses/worldState/1999_${season}_days.json" | jq '.' done ``` Length of output: 24575 </details> </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -25,3 +25,4 @@
const weekStart = EPOCH + week * 604800000;
const weekEnd = weekStart + 604800000;
// Elite Sanctuary Onslaught cycling every week
coderabbitai[bot] (Migrated from github.com) commented 2025-01-12 18:42:26 -08:00
Author
Owner

⚠️ Potential issue

Critical: EPOCH set in future will cause negative values

Setting EPOCH to December 2024 is problematic as it will cause negative day/week values for all dates before then, potentially breaking the 1999 calendar functionality.

Consider these changes:

  1. Set EPOCH to a date in or before 1999 to ensure positive day/week values
  2. Add validation for dates before EPOCH
  3. Extract magic numbers into named constants
-    const EPOCH = 1734307200 * 1000; // Monday, Dec 16, 2024 @ 00:00 UTC+0; should logically be winter in 1999 iteration 0
+    const MS_PER_DAY = 86400000;
+    const MS_PER_WEEK = 604800000;
+    const EPOCH = 915148800 * 1000; // January 1, 1999 @ 00:00 UTC+0
+    const currentTime = new Date().getTime();
+    if (currentTime < EPOCH) {
+        throw new Error('Current time cannot be before EPOCH');
+    }
-    const day = Math.trunc((new Date().getTime() - EPOCH) / 86400000);
-    const week = Math.trunc(day / 7);
-    const weekStart = EPOCH + week * 604800000;
-    const weekEnd = weekStart + 604800000;
+    const day = Math.trunc((currentTime - EPOCH) / MS_PER_DAY);
+    const week = Math.trunc(day / 7);
+    const weekStart = EPOCH + week * MS_PER_WEEK;
+    const weekEnd = weekStart + MS_PER_WEEK;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    const MS_PER_DAY = 86400000;
    const MS_PER_WEEK = 604800000;
    const EPOCH = 915148800 * 1000; // January 1, 1999 @ 00:00 UTC+0
    const currentTime = new Date().getTime();
    if (currentTime < EPOCH) {
        throw new Error('Current time cannot be before EPOCH');
    }
    const day = Math.trunc((currentTime - EPOCH) / MS_PER_DAY);
    const week = Math.trunc(day / 7);
    const weekStart = EPOCH + week * MS_PER_WEEK;
    const weekEnd = weekStart + MS_PER_WEEK;
_:warning: Potential issue_ **Critical: EPOCH set in future will cause negative values** Setting EPOCH to December 2024 is problematic as it will cause negative day/week values for all dates before then, potentially breaking the 1999 calendar functionality. Consider these changes: 1. Set EPOCH to a date in or before 1999 to ensure positive day/week values 2. Add validation for dates before EPOCH 3. Extract magic numbers into named constants ```diff - const EPOCH = 1734307200 * 1000; // Monday, Dec 16, 2024 @ 00:00 UTC+0; should logically be winter in 1999 iteration 0 + const MS_PER_DAY = 86400000; + const MS_PER_WEEK = 604800000; + const EPOCH = 915148800 * 1000; // January 1, 1999 @ 00:00 UTC+0 + const currentTime = new Date().getTime(); + if (currentTime < EPOCH) { + throw new Error('Current time cannot be before EPOCH'); + } - const day = Math.trunc((new Date().getTime() - EPOCH) / 86400000); - const week = Math.trunc(day / 7); - const weekStart = EPOCH + week * 604800000; - const weekEnd = weekStart + 604800000; + const day = Math.trunc((currentTime - EPOCH) / MS_PER_DAY); + const week = Math.trunc(day / 7); + const weekStart = EPOCH + week * MS_PER_WEEK; + const weekEnd = weekStart + MS_PER_WEEK; ``` <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. `````suggestion const MS_PER_DAY = 86400000; const MS_PER_WEEK = 604800000; const EPOCH = 915148800 * 1000; // January 1, 1999 @ 00:00 UTC+0 const currentTime = new Date().getTime(); if (currentTime < EPOCH) { throw new Error('Current time cannot be before EPOCH'); } const day = Math.trunc((currentTime - EPOCH) / MS_PER_DAY); const week = Math.trunc(day / 7); const weekStart = EPOCH + week * MS_PER_WEEK; const weekEnd = weekStart + MS_PER_WEEK; ````` </details> <!-- suggestion_end --> <!-- This is an auto-generated comment by CodeRabbit -->
Sign in to join this conversation.
No description provided.