@RequiresSchemaVersion(major = 1, minor = 300)
public final class DynamicDateFormat


Equivalent to android.icu.text.SimpleDateFormat, but generates a DynamicString based on a DynamicInstant.

See android.icu.text.SimpleDateFormat documentation for the pattern syntax.

Literal patterns are fully supported, including quotes (') or non-letters (e.g. :).

Currently this implementation only supports hour (HKhk), minute (m), and AM/PM (a) patterns. Every other letter will throw IllegalArgumentException.

NOTE: DynamicDateFormat uses Locale.getDefault(Locale.Category.FORMAT) at the time of calling format for AM/PM markers. This can change on the remote side, which would cause a mismatch between the locally-formatted AM/PM and the remotely-formatted numbers, unless the provider sends a newly formatted DynamicString (using a new invocation of format).

Example usage:

// This statement:
DynamicDateFormat(pattern = "HH:mm", timeZone = zone).format(dynamicInstant)
// Generates an equivalent of:
dynamicInstant
.getHour(zone)
.format(DynamicInt32.IntFormatter.Builder().setMinIntegerDigits(2).build())
.concat(DynamicString.constant(":"))
.concat(
dynamicInstant.getMinute(zone)
.format(DynamicInt32.IntFormatter.Builder().setMinIntegerDigits(2).build())
)

Summary

Public constructors

Constructs a DynamicDateFormat.

Public methods

final @NonNull DynamicBuilders.DynamicString
@RequiresSchemaVersion(major = 1, minor = 300)
format(@NonNull DynamicBuilders.DynamicInstant instant)

Formats the DynamicInstant into a date/time DynamicString.

final @NonNull ZoneId

The time zone used when extracting time parts from the DynamicInstant provided to format, defaults to ZoneId.systemDefault.

final void

The time zone used when extracting time parts from the DynamicInstant provided to format, defaults to ZoneId.systemDefault.

Public constructors

DynamicDateFormat

Added in 1.3.0-alpha04
public DynamicDateFormat(@NonNull String pattern, @NonNull ZoneId timeZone)

Constructs a DynamicDateFormat.

Parameters
@NonNull String pattern

The pattern to use when calling format, see android.icu.text.SimpleDateFormat for general syntax and DynamicDateFormat for the supported subset of features.

@NonNull ZoneId timeZone

The time zone used when extracting time parts from the DynamicInstant provided to format, defaults to ZoneId.systemDefault.

Public methods

format

Added in 1.3.0-alpha04
@RequiresSchemaVersion(major = 1, minor = 300)
public final @NonNull DynamicBuilders.DynamicString format(@NonNull DynamicBuilders.DynamicInstant instant)

Formats the DynamicInstant into a date/time DynamicString.

getTimeZone

Added in 1.3.0-alpha04
public final @NonNull ZoneId getTimeZone()

The time zone used when extracting time parts from the DynamicInstant provided to format, defaults to ZoneId.systemDefault.

setTimeZone

Added in 1.3.0-alpha04
public final void setTimeZone(@NonNull ZoneId timeZone)

The time zone used when extracting time parts from the DynamicInstant provided to format, defaults to ZoneId.systemDefault.