KMP_Timezone

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

Parameters:
NameTypeDescription
formHTMLFormElement

Form element

timezonestring

Timezone to use for conversion (default: detected)

(static) detectTimezone() → {string}

Detect user's timezone from browser using Intl.DateTimeFormat

Returns:

IANA timezone identifier (e.g., "America/Chicago")

Type: 
string

(static) formatDate(utcDateTime, timezone, options) → {string}

Format date only (no time)

Parameters:
NameTypeDescription
utcDateTimestring | Date

UTC datetime string or Date object

timezonestring

Target timezone (default: detected)

optionsobject

Intl.DateTimeFormat options

Returns:

Formatted date string

Type: 
string

(static) formatDateTime(utcDateTime, timezone, options) → {string}

Convert UTC datetime to user's timezone for display

Parameters:
NameTypeDescription
utcDateTimestring | Date

UTC datetime string or Date object

timezonestring

Target timezone (default: detected)

optionsobject

Intl.DateTimeFormat options

Returns:

Formatted datetime string in local timezone

Type: 
string

(static) formatTime(utcDateTime, timezone, options) → {string}

Format time only (no date)

Parameters:
NameTypeDescription
utcDateTimestring | Date

UTC datetime string or Date object

timezonestring

Target timezone (default: detected)

optionsobject

Intl.DateTimeFormat options

Returns:

Formatted time string

Type: 
string

(static) getAbbreviation(timezone, date) → {string}

Get timezone abbreviation (e.g., CDT, EST, PST)

Parameters:
NameTypeDescription
timezonestring

IANA timezone identifier

dateDate

Date for DST calculation (default: now)

Returns:

Timezone abbreviation

Type: 
string

(static) getTimezone(element) → {string}

Get timezone from element data attribute or detect from browser

Parameters:
NameTypeDescription
elementHTMLElement

Element with optional data-timezone attribute

Returns:

Timezone identifier

Type: 
string

(static) getTimezoneOffset(timezone, date) → {number}

Get timezone offset in minutes for a specific timezone and date

Parameters:
NameTypeDescription
timezonestring

IANA timezone identifier

dateDate

Date to calculate offset for (handles DST)

Returns:

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

Parameters:
NameTypeDescription
containerHTMLElement

Container to search in (default: document)

(static) toLocalInput(utcDateTime, timezone) → {string}

Convert UTC datetime to HTML5 datetime-local format in user's timezone

Parameters:
NameTypeDescription
utcDateTimestring | Date

UTC datetime

timezonestring

Target timezone (default: detected)

Returns:

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

Parameters:
NameTypeDescription
localDateTimestring

Datetime in YYYY-MM-DDTHH:mm or YYYY-MM-DD HH:mm:ss format

timezonestring

Source timezone (default: detected)

Returns:

ISO 8601 UTC datetime string

Type: 
string