# DurationSpan

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/DurationSpan.java+class:androidx.car.app.model.DurationSpan) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
@CarProtocol
class DurationSpan : CarSpan
```

<br />

|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) ||||
| ↳ | [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) |||
|   | ↳ | [androidx.car.app.model.CarSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan) ||
|   |   | ↳ | [androidx.car.app.model.DurationSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan) |

*** ** * ** ***

A span that replaces the text it is attached to with a localized duration string.

For example, the following code creates a string that shows the duration as the first text in the string before the interpunct:

```kotlin
String interpunct = "\\u00b7";
SpannableString string = new SpannableString("  " + interpunct + " Point-of-Interest 1");
string.setSpan(DurationSpan.create(300), 0, 1, SPAN_INCLUSIVE_INCLUSIVE);
```

The span flags (e.g. SPAN_EXCLUSIVE_EXCLUSIVE) will be ignored.

This span will be ignored if it overlaps with any span that replaces text, such as another `https://developer.android.com/reference/kotlin/androidx/car/app/model/DistanceSpan`, `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan`, or `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarIconSpan`. However, it is possible to \* apply styling to the text, such as changing colors:

```kotlin
String interpunct = "\\u00b7";
SpannableString string = new SpannableString("  " + interpunct + " Point-of-Interest 1");
string.setSpan(DurationSpan.create(300), 0, 1, SPAN_INCLUSIVE_INCLUSIVE);
string.setSpan(ForegroundCarColorSpan.create(CarColor.BLUE), 0, 1, SPAN_EXCLUSIVE_EXCLUSIVE);
```

## Summary

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan#create(java.time.Duration)(duration: https://developer.android.com/reference/java/time/Duration.html)` Creates a `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan` with the given duration. |
| `java-static https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan#create(long)(durationSeconds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Creates a `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan` with the given duration. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan#equals(java.lang.Object)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan#getDurationSeconds()()` Returns the time duration associated with this span, in seconds. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan#toString()()` |

### Inherited functions

From [androidx.car.app.model.CarSpan](https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/car/app/model/CarSpan#updateDrawState(android.text.TextPaint)(tp: https://developer.android.com/reference/android/text/TextPaint.html)` From [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) `https://developer.android.com/reference/android/text/style/CharacterStyle.html!` `https://developer.android.com/reference/android/text/style/CharacterStyle.html#getUnderlying()()` `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/text/style/CharacterStyle.html#updateDrawState(android.text.TextPaint)(p: https://developer.android.com/reference/android/text/TextPaint.html!)` `java-static https://developer.android.com/reference/android/text/style/CharacterStyle.html!` `https://developer.android.com/reference/android/text/style/CharacterStyle.html#wrap(android.text.style.CharacterStyle)(cs: https://developer.android.com/reference/android/text/style/CharacterStyle.html!)`

## Public functions

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
@RequiresApi(value = 26)
java-static fun create(duration: Duration): DurationSpan
```

Creates a `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan` with the given duration.

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
java-static fun create(durationSeconds: Long): DurationSpan
```

Creates a `https://developer.android.com/reference/kotlin/androidx/car/app/model/DurationSpan` with the given duration.

### equals

```
fun equals(other: Any?): Boolean
```

### getDurationSeconds

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun getDurationSeconds(): Long
```

Returns the time duration associated with this span, in seconds.

### hashCode

```
fun hashCode(): Int
```

### toString

```
fun toString(): String
```