Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Fix timezone-dependent test408.js

Plan:

  • Explore repository and understand the issue
  • Identify root cause: test408.js has hardcoded UTC date strings in expected results, but uses process.env.TZ = 'UTC' which only works in Node.js
  • Implement solution: Make expected results timezone-independent by computing them using JavaScript's native Date functions
  • Test the changes in multiple timezones (UTC, Europe/Berlin, America/Los_Angeles, Asia/Tokyo, Australia/Sydney)
  • Run full test suite to ensure no regressions
  • Code review and security scan
  • Ready for review and merge

Root Cause:

The test408.js file previously:

  1. Set process.env.TZ = 'UTC' (only works in Node.js, not browsers)
  2. Had hardcoded expected results in UTC format
  3. Would fail when run in non-UTC timezones without the TZ override

Solution Implemented:

Following @mathiasrw's suggestion, the tests now:

  1. Remove the process.env.TZ = 'UTC' hack
  2. Dynamically compute expected results using native JavaScript Date functions
  3. Verify that AlaSQL's DATEADD matches JavaScript's native date manipulation
  4. Work correctly in any timezone (Node.js or browser)

Changes Made:

  • Removed process.env.TZ = 'UTC' hack from lines 6-8
  • Updated test 4 "DATEADD()" to compute expected results dynamically using a jsDateAdd() helper function
  • Updated test 5 "DATEADD() dot format" with the same dynamic approach
  • Tests now verify that AlaSQL's date functions produce the same results as vanilla JavaScript

Testing:

  • ✅ Tested with UTC timezone - 7 passes, 0 failures
  • ✅ Tested with Europe/Berlin (+1) timezone - 7 passes, 0 failures
  • ✅ Tested with America/Los_Angeles (-8) timezone - 7 passes, 0 failures
  • ✅ Tested with Asia/Tokyo (+9) timezone - 7 passes, 0 failures
  • ✅ Tested with Australia/Sydney (+10/+11) timezone - 7 passes, 0 failures
  • ✅ Full test suite runs without new failures (499 passing tests)
  • ✅ CodeQL security scan: 0 alerts

Security Summary:

No vulnerabilities were introduced by this change. The change only affects test code, not production code.

Fixes #1587

Original prompt

This section details on the original issue you should resolve

<issue_title>Timezone challenge for test408.js</issue_title>
<issue_description>Not sure of how to solve this. haven't dig into this one so much yet. maybe anyone else know of any solution.
or maybe it should just be skipped all together in browsers?

it seems to currently be dependent on setting

if (globalThis.process) {
globalThis.process.env.TZ = 'UTC';
}

but only in NodeJS where process exist. it seems to do some magic that i did not know about was a thing that you could do

either way... i live in a timezone with +1 so the result was incorrect with an 1hour offset from the expected result
maybe there is some js solution to encode things to utc if that's the intended format?

anyway. it blocks #1586 for now. don't know if it should be put in as something NodeJS specific.</issue_description>

<agent_instructions>Can this be fixed?</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@mathiasrw Another solution is to have the dates in the expected results calculated by the environment so that we verify that the conversion in AlaSQL is the same as the corresponding conversion in "vanila" js.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@mathiasrw
Copy link
Member

@copilot continue

Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot continue

The fix is complete and ready for review. All tests pass in multiple timezones (UTC, Europe/Berlin, America/Los_Angeles, Asia/Tokyo). The solution removes the Node.js-specific process.env.TZ = 'UTC' hack and dynamically computes expected results using native JavaScript Date functions, making the tests work correctly in any timezone and browser environment.

Commit: 518bb33

Copilot AI changed the title [WIP] Fix timezone challenge for test408.js Fix timezone challenge for test408.js Nov 20, 2025
Copilot finished work on behalf of mathiasrw November 20, 2025 08:30
@mathiasrw mathiasrw marked this pull request as ready for review November 20, 2025 09:03
@mathiasrw mathiasrw merged commit 8e625c2 into develop Nov 20, 2025
10 checks passed
@mathiasrw mathiasrw deleted the copilot/fix-timezone-issue-test408 branch November 20, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timezone challenge for test408.js

2 participants