# ComplicationTextFormatting

Artifact: [androidx.wear.watchface:watchface-complications-data](https://developer.android.com/jetpack/androidx/releases/wear-watchface) [View Source](https://cs.android.com/search?q=file:androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting.kt+class:androidx.wear.watchface.complications.data.formatting.ComplicationTextFormatting) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

*** ** * ** ***

<br />

```
class ComplicationTextFormatting
```

<br />

*** ** * ** ***

A utility for finding optimal, locale-aware date and time format patterns that are guaranteed to fit within the strict character limits of a `ComplicationType.SHORT_TEXT` field.

The primary challenge in formatting text for complications is that the length of formatted date/time strings can vary (e.g., "May" vs. "September"). This class solves this by systematically testing a set of preferred format skeletons against a range of date and time values. It determines the "worst-case" (longest) output for a given pattern and locale, ensuring the chosen pattern is always safe to use.

It also includes hardcoded overrides for specific locales where standard patterns are known to be too long.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#ComplicationTextFormatting(java.util.Locale)(locale: https://developer.android.com/reference/java/util/Locale.html)` Creates a new instance of `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting` for the given locale. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#getBestShortTextDateFormat(kotlin.Array,kotlin.String)(skeletons: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>, fallback: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Finds the best date format pattern from a prioritized list of skeletons that consistently produces strings short enough for `SHORT_TEXT` fields. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#getFormattedDayOfWeekForShortText(kotlin.Long,android.icu.util.TimeZone)(timeInMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, timeZone: https://developer.android.com/reference/android/icu/util/TimeZone.html?)` Applies the short day-of-week formatting logic to a specific time. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#getFormattedTimeForShortText(kotlin.Long,android.icu.util.TimeZone,kotlin.Boolean)( timeInMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, timeZone: https://developer.android.com/reference/android/icu/util/TimeZone.html?, use24Hour: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Applies the short text time formatting logic to a specific time. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#fullTextDayOfWeekFormat()` Returns a date format pattern for the full day-of-week name (e.g., "Tuesday"). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextDayMonthFormat()` Returns a date format pattern for a short day-and-month representation (e.g., "Dec 25"). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextDayOfMonthFormat()` Returns a date format pattern for the day of the month (e.g., "25"). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextDayOfWeekFormat()` Returns a date format pattern for a short day-of-week representation (e.g., "Tue"). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextMonthFormat()` Returns a date format pattern for a short month representation (e.g., "Dec"). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextTimeFormat12Hour()` Returns a 12-hour time format pattern suitable for a short text field (e.g., "1:37"). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextTimeFormat12HourWithoutAmPmShortening()` Returns a 12-hour time format pattern suitable for a short text field (e.g., "1:37 a.m."). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextTimeFormat24Hour()` Returns a 24-hour time format pattern suitable for a short text field (e.g., "13:37"). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextTimeFormat24HourWithoutAmPmShortening()` Returns a 24-hour time format pattern suitable for a short text field (e.g., "13:37"). |

## Public constructors

### ComplicationTextFormatting

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
ComplicationTextFormatting(locale: Locale)
```

Creates a new instance of `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting` for the given locale.

| Parameters |
|---|---|
| `locale: https://developer.android.com/reference/java/util/Locale.html` | The `https://developer.android.com/reference/java/util/Locale.html` that defines the formatting conventions. |

## Public functions

### getBestShortTextDateFormat

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
fun getBestShortTextDateFormat(skeletons: Array<String>, fallback: String?): String?
```

Finds the best date format pattern from a prioritized list of skeletons that consistently produces strings short enough for `SHORT_TEXT` fields.

It iterates through the provided `skeletons` in order. The first skeleton that passes the length-check across multiple date/time samples is selected. If no skeletons in the list produce a sufficiently short result, the `fallback` pattern is returned.

| Parameters |
|---|---|
| `skeletons: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | An array of date format skeletons to test, in order of preference. For example, `["MMMd", "MMd"]` would try a three-letter month first before a two-digit month. |
| `fallback: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The non-validated pattern to return if no skeleton in `skeletons` is suitable. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The best-fitting date pattern string, or the `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#getBestShortTextDateFormat(kotlin.Array,kotlin.String)`. |

### getFormattedDayOfWeekForShortText

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
fun getFormattedDayOfWeekForShortText(timeInMillis: Long, timeZone: TimeZone?): String?
```

Applies the short day-of-week formatting logic to a specific time.

| Parameters |
|---|---|
| `timeInMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The UTC time to format, in milliseconds since the epoch. |
| `timeZone: https://developer.android.com/reference/android/icu/util/TimeZone.html?` | The target `https://developer.android.com/reference/android/icu/util/TimeZone.html` for the output string. `null` uses the system default. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The final, formatted day-of-week string, ready for display. |

### getFormattedTimeForShortText

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
fun getFormattedTimeForShortText(
    timeInMillis: Long,
    timeZone: TimeZone?,
    use24Hour: Boolean
): String?
```

Applies the short text time formatting logic to a specific time.

| Parameters |
|---|---|
| `timeInMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The UTC time to format, in milliseconds since the epoch. |
| `timeZone: https://developer.android.com/reference/android/icu/util/TimeZone.html?` | The target `https://developer.android.com/reference/android/icu/util/TimeZone.html` for the output string. `null` uses the system default. |
| `use24Hour: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | If `true`, formats in 24-hour time; otherwise, 12-hour. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The final, formatted time string, ready for display. |

## Public properties

### fullTextDayOfWeekFormat

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val fullTextDayOfWeekFormat: String
```

Returns a date format pattern for the full day-of-week name (e.g., "Tuesday"). This is intended for `LONG_TEXT` fields and is not length-checked.

### shortTextDayMonthFormat

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextDayMonthFormat: String?
```

Returns a date format pattern for a short day-and-month representation (e.g., "Dec 25"). Tries skeletons in the order of `MMMd`, `MMd`, and `Md`. Falls back to `d/MM`.

### shortTextDayOfMonthFormat

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextDayOfMonthFormat: String?
```

Returns a date format pattern for the day of the month (e.g., "25"). Tries skeletons `dd` and `d`. Falls back to `dd`.

### shortTextDayOfWeekFormat

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextDayOfWeekFormat: String?
```

Returns a date format pattern for a short day-of-week representation (e.g., "Tue"). Tries skeletons `EEE` (abbreviation), `EEEEEE` (2-letter), and `EEEEE` (1-letter). Falls back to `EEEEE`.

### shortTextMonthFormat

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextMonthFormat: String?
```

Returns a date format pattern for a short month representation (e.g., "Dec"). Tries skeletons in the order of `MMM`, `MM`, and `M`. Falls back to `MM`.

### shortTextTimeFormat12Hour

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextTimeFormat12Hour: String?
```

Returns a 12-hour time format pattern suitable for a short text field (e.g., "1:37"). This version may shorten the AM/PM marker (e.g., from "a.m." to "am") to meet length constraints.

### shortTextTimeFormat12HourWithoutAmPmShortening

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextTimeFormat12HourWithoutAmPmShortening: String?
```

Returns a 12-hour time format pattern suitable for a short text field (e.g., "1:37 a.m.").

This version preserves the full, locale-specific AM/PM marker (e.g., "a.m." with periods) and does not attempt to shorten it to save space.

### shortTextTimeFormat24Hour

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextTimeFormat24Hour: String?
```

Returns a 24-hour time format pattern suitable for a short text field (e.g., "13:37").

### shortTextTimeFormat24HourWithoutAmPmShortening

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.3.0)

```
val shortTextTimeFormat24HourWithoutAmPmShortening: String?
```

Returns a 24-hour time format pattern suitable for a short text field (e.g., "13:37").

Note: This is functionally identical to `https://developer.android.com/reference/kotlin/androidx/wear/watchface/complications/data/formatting/ComplicationTextFormatting#shortTextTimeFormat24Hour()`, as AM/PM shortening is not applicable to 24-hour formats.