Skip to content

Conversation

@johnnyee
Copy link

Summary

This PR adds two new environment variables for timezone and date handling configuration:

  • MYSQL_TIMEZONE: Set the timezone for date/time values

    • Accepts formats like +08:00 (UTC+8), -05:00 (UTC-5), Z (UTC), or local (system timezone)
    • Useful for ensuring consistent date/time handling across different server locations
  • MYSQL_DATE_STRINGS: When set to "true", returns date/datetime values as strings instead of JavaScript Date objects

    • Preserves exact database values without any timezone conversion
    • Particularly useful for cross-timezone operations and avoiding JavaScript Date quirks

Use Cases

  1. Cross-timezone database operations: Ensuring consistent date/time handling when server and database are in different timezones
  2. Precise date formatting: Applications that need exact control over date values
  3. Avoiding JavaScript Date issues: Preventing automatic timezone conversion by JavaScript Date objects

Changes

  • src/config/index.ts: Added timezone and dateStrings configuration options to MySQL connection
  • .env.dist: Added documentation and examples for new environment variables
  • README.md: Added "Timezone and Date Configuration" section under Environment Variables

Example Configuration

# Set timezone to UTC+8 (e.g., Beijing, Singapore)
MYSQL_TIMEZONE=+08:00

# Return date values as strings
MYSQL_DATE_STRINGS=true

Test Plan

  • TypeScript compiles without errors
  • Configuration options are correctly passed to mysql2 connection
  • Manual testing with different timezone settings

Add support for timezone and date string formatting configuration:

- MYSQL_TIMEZONE: Set timezone for date/time values (e.g., "+08:00", "Z", "local")
- MYSQL_DATE_STRINGS: Return date values as strings instead of Date objects

This is useful for:
- Cross-timezone database operations
- Preserving exact database date values
- Applications needing precise date formatting control
@johnnyee
Copy link
Author

Hi @benborla 👋

Just a friendly ping - would you have time to review this PR when convenient?

This adds timezone and date string configuration options (MYSQL_TIMEZONE and MYSQL_DATE_STRINGS) which are quite useful for cross-timezone database operations.

Happy to make any changes if needed. Thanks!

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.

1 participant