Time Zone
The Time Zone feature provides comprehensive timezone management capabilities for the financial charting library. This system enables users to display chart data in different timezones while maintaining internal UTC consistency.
Key Features
- Timezone selection (IANA timezone database)
- Real-time timezone conversion
- Crosshair and axis label timezone formatting
- Exchange-specific timezone support
- Daylight Saving Time (DST) awareness
- Timezone offset calculation
- Popular timezone presets
- Region-based timezone grouping
Architecture / Behavior
The timezone system follows a layered architecture:
- Core Layer: TimezoneManager singleton handles all conversions
- API Layer: ChartApi methods for timezone control
- UI Layer: Timezone selector in toolbar and settings
- Rendering Layer: AxisRenderer and Tooltip use timezone formatting
The timezone flow: UI → ChartApi → ChartStore → TimezoneManager → Native Intl API → Rendering.
API Usage
Initialization
The timezone feature is enabled by default in the chart configuration:
const chart = Chart.create(document.getElementById('container'), {
// ... other options
timezone: 'America/New_York', // Set default timezone
});
Methods
ChartApi.setTimezone() - Set the chart timezone:
// Set to Eastern Time
chart.getApi().setTimezone('America/New_York');
// Set to Indian Standard Time
chart.getApi().setTimezone('Asia/Kolkata');
// Set to UTC
chart.getApi().setTimezone('Etc/UTC');
ChartApi.getTimezone() - Get the current chart timezone:
const currentTz = chart.getApi().getTimezone();
console.log(currentTz); // 'America/New_York'
ChartApi.getAvailableTimezones() - Get list of available timezones:
const timezones = chart.getApi().getAvailableTimezones();
console.log(timezones.length); // 50+ timezones
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
timezone | string | 'Etc/UTC' | Default timezone for the chart |
timezone_groups | boolean | true | Enable region-based timezone grouping |
popular_timezones | boolean | true | Show popular timezones first |
Events
timezone:changed- Fired when timezone changes- Payload:
{ old: string, new: string, timestamp?: number }
- Payload:
Customization
- UI styling can be customized via CSS classes
- Timezone formatting can be customized using format strings
- Popular timezones can be customized in TIMEZONE_GROUPS
- Custom timezone presets can be added to COMMON_TIMEZONES
Use Cases
- Displaying US market data in Asian timezone
- Comparing trading sessions across different regions
- Technical analysis during specific market hours
- Building multi-exchange trading platforms
- Creating timezone-aware alerts and notifications
Limitations
- Requires browser support for Intl.DateTimeFormat API
- Some older browsers may have limited timezone support
- Performance depends on timezone complexity
- DST transitions require careful handling
✅ Supported
- Timezone selection and switching
- Real-time timezone conversion
- Crosshair and axis label formatting
- Exchange-specific timezone support
- DST awareness
- Timezone offset calculation
- Popular timezone presets
- Region-based timezone grouping
❌ Not Supported
- Automatic timezone detection based on user location
- Custom timezone creation (non-IANA)
- Historical timezone data
- Timezone transition animations
⚠️ Partial / External
- Browser compatibility requires polyfill for older browsers
- Custom timezone formatting requires understanding of format tokens
Feature Classification
Core Feature - Fundamental functionality required for basic chart operation
Dependencies
- Requires backend? No
- Requires storage? No
- Requires real-time data? No
- Requires UI controls? Yes (timezone selector)
Missing Implementation Analysis
The timezone functionality is fully implemented and production-ready. All core timezone capabilities are present in the codebase with proper DST handling and performance optimizations.
Consistency Validation
The timezone API follows the same pattern as other API methods with consistent promise-based return values and error handling. Naming conventions are consistent with other features.
UI vs API Separation
- UI handles: Timezone selector dropdown, timezone display in toolbar
- API exposes:
setTimezone(),getTimezone(),getAvailableTimezones()methods - Must implement manually: Custom timezone formatting, custom timezone presets
User Flow
- User selects timezone from dropdown
- ChartApi validates timezone
- ChartStore updates timezone state
- TimezoneManager calculates offset
- AxisRenderer and Tooltip update formatting
- Chart displays data in selected timezone
Integration with Existing Docs
This feature should be linked from:
- Charting section → Top Toolbar
- API Reference → ChartApi
- Configuration → Chart Configuration
- Getting Started → Quick Start Guide