@RequiresSchemaVersion(major = 1, minor = 300)
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

DynamicDateFormat(pattern: String, timeZone: ZoneId)

Constructs a DynamicDateFormat.

Public functions

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

Formats the DynamicInstant into a date/time DynamicString.

Public properties

ZoneId

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
DynamicDateFormat(
    pattern: String,
    timeZone: ZoneId = ZoneId.systemDefault()
)

Constructs a DynamicDateFormat.

Parameters
pattern: String

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

timeZone: ZoneId = ZoneId.systemDefault()

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

Public functions

format

Added in 1.3.0-alpha04
@RequiresSchemaVersion(major = 1, minor = 300)
fun format(
    instant: DynamicBuilders.DynamicInstant = DynamicInstant.platformTimeWithSecondsPrecision()
): DynamicBuilders.DynamicString

Formats the DynamicInstant into a date/time DynamicString.

Parameters
instant: DynamicBuilders.DynamicInstant = DynamicInstant.platformTimeWithSecondsPrecision()

The DynamicInstant to format, defaults to DynamicInstant.platformTimeWithSecondsPrecision.

Public properties

timeZone

Added in 1.3.0-alpha04
var timeZoneZoneId

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