DynamicDateFormat
@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 |
|---|
DynamicDateFormat(@NonNull String pattern, @NonNull ZoneId timeZone)Constructs a |
Public methods |
|
|---|---|
final @NonNull DynamicBuilders.DynamicString |
@RequiresSchemaVersion(major = 1, minor = 300)Formats the |
final @NonNull ZoneId |
The time zone used when extracting time parts from the |
final void |
setTimeZone(@NonNull ZoneId value)The time zone used when extracting time parts from the |
Public constructors
DynamicDateFormat
public DynamicDateFormat(@NonNull String pattern, @NonNull ZoneId timeZone)
Constructs a DynamicDateFormat.
| Parameters | |
|---|---|
@NonNull String pattern |
The pattern to use when calling |
@NonNull ZoneId timeZone |
The time zone used when extracting time parts from the |
Public methods
format
@RequiresSchemaVersion(major = 1, minor = 300)
public final @NonNull DynamicBuilders.DynamicString format(@NonNull DynamicBuilders.DynamicInstant instant)
Formats the DynamicInstant into a date/time DynamicString.
| Parameters | |
|---|---|
@NonNull DynamicBuilders.DynamicInstant instant |
The |
getTimeZone
public final @NonNull ZoneId getTimeZone()
The time zone used when extracting time parts from the DynamicInstant provided to format, defaults to ZoneId.systemDefault.
setTimeZone
public final void setTimeZone(@NonNull ZoneId value)
The time zone used when extracting time parts from the DynamicInstant provided to format, defaults to ZoneId.systemDefault.