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
JsDate 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 JsDate 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 JsDate 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 Stringformat(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 JsDateTimeFormatstatic OptionalLonglongFromDate(Object date) parse(String text, JsTimeZone tz) Parses the given string using this instance's pattern, and returns a wrapped Javalongvalue in nanoseconds.static DateWrapperparse(String pattern, String text, JsTimeZone tz) Parses the given input string using the provided pattern, and returns a wrapped Javalongvalue in nanoseconds.elemental2.core.JsDateparseAsDate(String text) Parses the given string using this instance's pattern, and returns aJsDateobject in milliseconds.static elemental2.core.JsDateparseAsDate(String pattern, String text) Parses the given input string using the provided pattern, and returns a JSDateobject in milliseconds.longparseWithTimezoneAsLong(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 staticgetFormat(String)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. AJsTimeZoneobject 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 JSDateobject in milliseconds.- Parameters:
pattern-text-- Returns:
-
parse
Parses the given input string using the provided pattern, and returns a wrapped Javalongvalue in nanoseconds. AJsTimeZoneobject 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 aStringvalue of a number expressed in nanoseconds, aNumbervalue expressed in nanoseconds, a JSDateobject (necessarily in milliseconds), or a wrapped Javalongvalue, expressed in nanoseconds. AJsTimeZoneobject 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 Javalongvalue in nanoseconds. AJsTimeZoneobject 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 aJsDateobject in milliseconds.- Parameters:
text-- Returns:
-
parseWithTimezoneAsLong
@JsIgnore public long parseWithTimezoneAsLong(String dateTimeString, com.google.gwt.i18n.client.TimeZone timeZone, boolean needsAdjustment) -
toString
-