Home Reference Source

Function

Static Public Summary
public

convert(temporal: LocalDate | LocalDateTime | ZonedDateTime, zone: ZoneId): ToNativeJsConverter

converts a LocalDate, LocalDateTime or ZonedDateTime to a native Javascript Date.

public

Returns an array of locale strings that have been registered via registerLocaleData().

public

nativeJs(date: string, zone: ZoneId): ZonedDateTime

Creates ZonedDateTime from a javascript Date or a moment instance.

public

registerLocaleData(path: string, data: Object)

Registers CLDR JSON data into the shared cldrjs instance.

Static Public

public convert(temporal: LocalDate | LocalDateTime | ZonedDateTime, zone: ZoneId): ToNativeJsConverter source

converts a LocalDate, LocalDateTime or ZonedDateTime to a native Javascript Date.

In a first step the temporal is converted to an Instant by adding implicit values.

A LocalDate is implicit set to a LocalDateTime at start of day. A LocalDateTime is implicit set to a ZonedDateTime with the passed zone or if null, with the system default time zone. A ZonedDateTime is converted to an Instant, if a zone is specified the zonedDateTime is adjusted to this zone, keeping the same Instant.

In a second step the instant is converted to a native Javascript Date

default zone for LocalDate and LocalDateTime is ZoneId.systemDefault().

Params:

NameTypeAttributeDescription
temporal LocalDate | LocalDateTime | ZonedDateTime
  • nullable: false

a joda temporal instance

zone ZoneId
  • optional

the zone of the temporal

Return:

ToNativeJsConverter

Example:

convert(localDate).toDate() // returns a javascript Date
convert(localDate).toEpochMilli()   // returns the epochMillis

public getRegisteredLocales() source

Returns an array of locale strings that have been registered via registerLocaleData().

public nativeJs(date: string, zone: ZoneId): ZonedDateTime source

Creates ZonedDateTime from a javascript Date or a moment instance.

Params:

NameTypeAttributeDescription
date string

a javascript Date or a moment instance

zone ZoneId
  • optional
  • default: ZoneId.systemDefault()

the zone of the returned ZonedDateTime, defaults to ZoneId.systemDefault()

Return:

ZonedDateTime

public registerLocaleData(path: string, data: Object) source

Registers CLDR JSON data into the shared cldrjs instance. The path is used as a unique key to skip already-loaded data.

Params:

NameTypeAttributeDescription
path string

The CLDR data path (e.g. 'supplemental/likelySubtags.json')

data Object

A CLDR JSON object