KMP_Timezone
- Description:
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.
- Source:
Methods
(static) convertFormDatetimesToUTC(form, timezone)
- Description:
Convert all datetime-local inputs to UTC before form submission Creates hidden inputs with UTC values, disables originals
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
form |
HTMLFormElement | Form element |
timezone |
string | Timezone to use for conversion (default: detected) |
(static) detectTimezone() → {string}
- Description:
Detect user's timezone from browser using Intl.DateTimeFormat
- Source:
Returns:
IANA timezone identifier (e.g., "America/Chicago")
- Type
- string
(static) formatDate(utcDateTime, timezone, options) → {string}
- Description:
Format date only (no time)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
utcDateTime |
string | Date | UTC datetime string or Date object |
timezone |
string | Target timezone (default: detected) |
options |
object | Intl.DateTimeFormat options |
Returns:
Formatted date string
- Type
- string
(static) formatDateTime(utcDateTime, timezone, options) → {string}
- Description:
Convert UTC datetime to user's timezone for display
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
utcDateTime |
string | Date | UTC datetime string or Date object |
timezone |
string | Target timezone (default: detected) |
options |
object | Intl.DateTimeFormat options |
Returns:
Formatted datetime string in local timezone
- Type
- string
(static) formatTime(utcDateTime, timezone, options) → {string}
- Description:
Format time only (no date)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
utcDateTime |
string | Date | UTC datetime string or Date object |
timezone |
string | Target timezone (default: detected) |
options |
object | Intl.DateTimeFormat options |
Returns:
Formatted time string
- Type
- string
(static) getAbbreviation(timezone, date) → {string}
- Description:
Get timezone abbreviation (e.g., CDT, EST, PST)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
timezone |
string | IANA timezone identifier |
date |
Date | Date for DST calculation (default: now) |
Returns:
Timezone abbreviation
- Type
- string
(static) getTimezone(element) → {string}
- Description:
Get timezone from element data attribute or detect from browser
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
element |
HTMLElement | Element with optional data-timezone attribute |
Returns:
Timezone identifier
- Type
- string
(static) getTimezoneOffset(timezone, date) → {number}
- Description:
Get timezone offset in minutes for a specific timezone and date
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
timezone |
string | IANA timezone identifier |
date |
Date | Date to calculate offset for (handles DST) |
Returns:
Offset in minutes
- Type
- number
(static) initializeDatetimeInputs(container)
- Description:
Initialize timezone conversion for all datetime inputs on page Finds inputs with data-utc-value and converts to local time
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
container |
HTMLElement | Container to search in (default: document) |
(static) toLocalInput(utcDateTime, timezone) → {string}
- Description:
Convert UTC datetime to HTML5 datetime-local format in user's timezone
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
utcDateTime |
string | Date | UTC datetime |
timezone |
string | Target timezone (default: detected) |
Returns:
Datetime in YYYY-MM-DDTHH:mm format (local time)
- Type
- string
(static) toUTC(localDateTime, timezone) → {string}
- Description:
Convert datetime-local input value (local time) to UTC for storage
- Source:
Parameters:
| 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) |
Returns:
ISO 8601 UTC datetime string
- Type
- string