Skip to main content
Glama
pshempel

MCP Time Server Node

by pshempel
system-timezone-detection.md1.88 kB
# System Timezone Detection (Verified 2025-07-19) **Key Findings**: 1. **Intl.DateTimeFormat() Method**: - `Intl.DateTimeFormat().resolvedOptions().timeZone` returns system timezone - Returns valid IANA timezone string (e.g., "America/Indianapolis") - Always available in Node.js 14+ (our minimum version) - Performance: ~0.24ms per call (should cache) 2. **TZ Environment Variable**: - TZ affects `Intl.DateTimeFormat().resolvedOptions().timeZone` directly - `TZ=UTC` → system timezone becomes "UTC" - `TZ=""` → system timezone becomes "Etc/Unknown" - `TZ=Invalid/Zone` → system timezone becomes "undefined" (string) - Standard Unix way to set timezone, should be respected 3. **Environment Variable Behavior**: - `process.env.VAR` is `undefined` when not set - `process.env.VAR` is empty string `""` when set to empty - Can distinguish between unset and empty 4. **Timezone Validation**: - Empty string `""` is valid timezone (defaults to UTC in date-fns-tz) - String `"undefined"` is valid timezone (weird but true) - String `"null"` is valid timezone (also weird but true) - Use `getTimezoneOffset()` returns NaN for truly invalid timezones 5. **Recommended Precedence**: ``` 1. Parameter (if provided and not empty string) 2. DEFAULT_TIMEZONE env var (if valid) 3. System timezone via Intl.DateTimeFormat() 4. UTC (final fallback) ``` Note: TZ env var is automatically respected because it affects Intl.DateTimeFormat() 6. **Backward Compatibility**: - Empty string parameter `""` must continue to mean UTC - This is different from undefined parameter - Critical for maintaining API compatibility 7. **Performance Considerations**: - `Intl.DateTimeFormat().resolvedOptions().timeZone` is slow (~0.24ms) - Should be called once and cached - Config module should handle caching

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pshempel/mcp-time-server-node'

If you have feedback or need assistance with the MCP directory API, please join our Discord server