KMP Timezone Utilities
Client-side timezone handling for the KMP application. Provides utilities for detecting user timezone, formatting dates/times, and converting between timezones for datetime inputs and displays.
See /docs/10.3.1-timezone-utils-api.md for complete API documentation and usage examples.
Methods
(static) convertFormDatetimesToUTC(form, timezone)
Convert all datetime-local inputs to UTC before form submission Creates hidden inputs with UTC values, disables originals
| Name | Type | Description |
|---|---|---|
form | HTMLFormElement | Form element |
timezone | string | Timezone to use for conversion (default: detected) |
(static) detectTimezone() → {string}
Detect user's timezone from browser using Intl.DateTimeFormat
IANA timezone identifier (e.g., "America/Chicago")
- Type:
- string
(static) formatDate(utcDateTime, timezone, options) → {string}
Format date only (no time)
| Name | Type | Description |
|---|---|---|
utcDateTime | string | | UTC datetime string or Date object |
timezone | string | Target timezone (default: detected) |
options | object | Intl.DateTimeFormat options |
Formatted date string
- Type:
- string
(static) formatDateTime(utcDateTime, timezone, options) → {string}
Convert UTC datetime to user's timezone for display
| Name | Type | Description |
|---|---|---|
utcDateTime | string | | UTC datetime string or Date object |
timezone | string | Target timezone (default: detected) |
options | object | Intl.DateTimeFormat options |
Formatted datetime string in local timezone
- Type:
- string
(static) formatTime(utcDateTime, timezone, options) → {string}
Format time only (no date)
| Name | Type | Description |
|---|---|---|
utcDateTime | string | | UTC datetime string or Date object |
timezone | string | Target timezone (default: detected) |
options | object | Intl.DateTimeFormat options |
Formatted time string
- Type:
- string
(static) getAbbreviation(timezone, date) → {string}
Get timezone abbreviation (e.g., CDT, EST, PST)
| Name | Type | Description |
|---|---|---|
timezone | string | IANA timezone identifier |
date | Date | Date for DST calculation (default: now) |
Timezone abbreviation
- Type:
- string
(static) getTimezone(element) → {string}
Get timezone from element data attribute or detect from browser
| Name | Type | Description |
|---|---|---|
element | HTMLElement | Element with optional data-timezone attribute |
Timezone identifier
- Type:
- string
(static) getTimezoneOffset(timezone, date) → {number}
Get timezone offset in minutes for a specific timezone and date
| Name | Type | Description |
|---|---|---|
timezone | string | IANA timezone identifier |
date | Date | Date to calculate offset for (handles DST) |
Offset in minutes
- Type:
- number
(static) initializeDatetimeInputs(container)
Initialize timezone conversion for all datetime inputs on page Finds inputs with data-utc-value and converts to local time
| Name | Type | Description |
|---|---|---|
container | HTMLElement | Container to search in (default: document) |
(static) toLocalInput(utcDateTime, timezone) → {string}
Convert UTC datetime to HTML5 datetime-local format in user's timezone
| Name | Type | Description |
|---|---|---|
utcDateTime | string | | UTC datetime |
timezone | string | Target timezone (default: detected) |
Datetime in YYYY-MM-DDTHH:mm format (local time)
- Type:
- string
(static) toUTC(localDateTime, timezone) → {string}
Convert datetime-local input value (local time) to UTC for storage
| Name | Type | Description |
|---|---|---|
localDateTime | string | Datetime in YYYY-MM-DDTHH:mm or YYYY-MM-DD HH:mm:ss format |
timezone | string | Source timezone (default: detected) |
ISO 8601 UTC datetime string
- Type:
- string