Package io.deephaven.web.client.api.i18n
Class JsDateTimeFormat
java.lang.Object
io.deephaven.web.client.api.i18n.JsDateTimeFormat
Largely an exported wrapper for the GWT DateFormat, but also includes support for formatting nanoseconds as an
additional 6 decimal places after the rest of the number.
Other concerns that this handles includes accepting a js Date and ignoring the lack of nanos, accepting a js Number
and assuming it to be a lossy nano value, and parsing into a js Date.
Utility class to parse and format various date/time values, using the same format patterns as are supported by the
standard Java implementation used in the Deephaven server and swing client.
As Deephaven internally uses nanosecond precision to record dates, this API expects nanoseconds in most use cases,
with the one exception of the JS `Date` type, which is not capable of more precision than milliseconds. Note,
however, that when passing nanoseconds as a JS `Number` there is likely to be some loss of precision, though this is
still supported for easier interoperability with other JS code. The values returned by `parse()` will be an opaque
object wrapping the full precision of the specified date, However, this object supports `toString()` and `valueOf()`
to return a string representation of that value, as well as a `asNumber()` to return a JS `Number` value and a
`asDate()` to return a JS `Date` value.
Caveats:
- The `D` format (for "day of year") is not supported by this implementation at this time. - The `%t` format for
short timezone code is not supported by this implementation at this time, though `z` will work as expected in the
browser to emit the user's own timezone.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformat
(Object date, JsTimeZone timeZone) static String
format
(String pattern, jsinterop.base.Any date, JsTimeZone timeZone) Accepts a variety of input objects to interpret as a date, and formats them using the specified pattern.format
(jsinterop.base.Any date, JsTimeZone timeZone) Takes a variety of objects to interpret as a date, and formats them using this instance's pattern.static JsDateTimeFormat
static OptionalLong
longFromDate
(Object date) parse
(String text, JsTimeZone tz) Parses the given string using this instance's pattern, and returns a wrapped Java long value in nanoseconds.static DateWrapper
parse
(String pattern, String text, JsTimeZone tz) Parses the given input string using the provided pattern, and returns a wrapped Java `long` value in nanoseconds.elemental2.core.JsDate
parseAsDate
(String text) Parses the given string using this instance's pattern, and returns a JS Date object in milliseconds.static elemental2.core.JsDate
parseAsDate
(String pattern, String text) Parses the given input string using the provided pattern, and returns a JS `Date` object in milliseconds.long
parseWithTimezoneAsLong
(String dateTimeString, com.google.gwt.i18n.client.TimeZone timeZone, boolean needsAdjustment) toString()
-
Field Details
-
NANOS_PER_MILLI
public static final int NANOS_PER_MILLI- See Also:
-
-
Constructor Details
-
JsDateTimeFormat
Creates a new date/time format instance. This generally should be avoided in favor of the static `getFormat` function, which will create and cache an instance so that later calls share the same instance.- Parameters:
pattern
-
-
-
Method Details
-
getFormat
- Parameters:
pattern
-- Returns:
- a date format instance matching the specified format. If this format has not been specified before, a new instance will be created and stored for later reuse.
-
format
public static String format(String pattern, jsinterop.base.Any date, @JsOptional JsTimeZone timeZone) Accepts a variety of input objects to interpret as a date, and formats them using the specified pattern. A `TimeZone` object can optionally be provided to format this date as the current date/time in that timezone.See the instance method for more details on input objects.- Parameters:
pattern
-date
-timeZone
-- Returns:
-
parseAsDate
Parses the given input string using the provided pattern, and returns a JS `Date` object in milliseconds.- Parameters:
pattern
-text
-- Returns:
-
parse
Parses the given input string using the provided pattern, and returns a wrapped Java `long` value in nanoseconds. A `TimeZone` object can optionally be provided to parse to a desired timezone.- Parameters:
pattern
-text
-tz
-- Returns:
-
format
Takes a variety of objects to interpret as a date, and formats them using this instance's pattern. Inputs can include a String value of a number expressed in nanoseconds, a Number value expressed in nanoseconds, a JS Date object (necessarily in milliseconds), or a wrapped Java long value, expressed in nanoseconds. A TimeZone object can optionally be provided to format this date as the current date/time in that timezone.- Parameters:
date
-timeZone
-- Returns:
- String
-
format
-
longFromDate
-
parse
Parses the given string using this instance's pattern, and returns a wrapped Java long value in nanoseconds. A TimeZone object can optionally be provided to parse to a desired timezone.- Parameters:
text
-tz
-- Returns:
-
parseAsDate
Parses the given string using this instance's pattern, and returns a JS Date object in milliseconds.- Parameters:
text
-- Returns:
-
parseWithTimezoneAsLong
@JsIgnore public long parseWithTimezoneAsLong(String dateTimeString, com.google.gwt.i18n.client.TimeZone timeZone, boolean needsAdjustment) -
toString
-