Package org.springframework.format.annotation

# Enum Class DurationFormat.Unit

java.lang.Object
java.lang.Enum<DurationFormat.Unit>
org.springframework.format.annotation.DurationFormat.Unit

All Implemented Interfaces:
  `Serializable`, `Comparable<DurationFormat.Unit>`, `Constable`

Enclosing class:
  DurationFormat

public static enum DurationFormat.Unit extends Enum<DurationFormat.Unit>
`Duration` format unit, which mirrors a subset of `ChronoUnit` and allows conversion to and from a supported `ChronoUnit` as well as conversion from durations to longs.

The enum includes its corresponding suffix in the `SIMPLE` `Duration` format style.

## Nested Class Summary

## Nested classes/interfaces inherited from class java.lang.Enum

`Enum.EnumDesc<E extends Enum<E>>`

## Enum Constant Summary

Enum Constants
Enum Constant
Description
`DAYS`
Days (`"d"`).
`HOURS`
Hours (`"h"`).
`MICROS`
Microseconds (`"us"`).
`MILLIS`
Milliseconds (`"ms"`).
`MINUTES`
Minutes (`"m"`).
`NANOS`
Nanoseconds (`"ns"`).
`SECONDS`
Seconds (`"s"`).

## Method Summary

Modifier and Type
Method
Description
`ChronoUnit`
`asChronoUnit()`
Convert this `Unit` to its `ChronoUnit` equivalent.
`String`
`asSuffix()`
Convert this `Unit` to a simple `String` suffix, suitable for the `SIMPLE` style.
`static DurationFormat.Unit`
`fromChronoUnit(ChronoUnit chronoUnit)`
Get the `DurationFormat.Unit` corresponding to the given `ChronoUnit`.
`static DurationFormat.Unit`
`fromSuffix(String suffix)`
Get the `DurationFormat.Unit` corresponding to the given `String` suffix.
`long`
`longValue(Duration value)`
Convert the given `Duration` to a long value in the resolution of this unit.
`Duration`
`parse(String value)`
Parse a `long` from the given `String` and interpret it to be a `Duration` in the current unit.
`String`
`print(Duration value)`
Print the given `Duration` as a `String`, converting it to a long value using this unit's precision via `longValue(Duration)` and appending this unit's simple `suffix`.
`static DurationFormat.Unit`
`valueOf(String name)`
Returns the enum constant of this class with the specified name.
`static DurationFormat.Unit[]`
`values()`
Returns an array containing the constants of this enum class, in the order they are declared.

### Methods inherited from class java.lang.Enum

`clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

## Enum Constant Details

### NANOS

public static final DurationFormat.Unit NANOS
Nanoseconds (`"ns"`).

### MICROS

public static final DurationFormat.Unit MICROS
Microseconds (`"us"`).

### MILLIS

public static final DurationFormat.Unit MILLIS
Milliseconds (`"ms"`).

### SECONDS

public static final DurationFormat.Unit SECONDS
Seconds (`"s"`).

### MINUTES

public static final DurationFormat.Unit MINUTES
Minutes (`"m"`).

### HOURS

public static final DurationFormat.Unit HOURS
Hours (`"h"`).

### DAYS

public static final DurationFormat.Unit DAYS
Days (`"d"`).

## Method Details

### values

public static DurationFormat.Unit[] values()
Returns an array containing the constants of this enum class, in the order they are declared.

Returns:
  an array containing the constants of this enum class, in the order they are declared

### valueOf

public static DurationFormat.Unit valueOf(String name)
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)

Parameters:
  `name` - the name of the enum constant to be returned.
Returns:
  the enum constant with the specified name
Throws:
  `IllegalArgumentException` - if this enum class has no constant with the specified name
  `NullPointerException` - if the argument is null

### asChronoUnit

public ChronoUnit asChronoUnit()
Convert this `Unit` to its `ChronoUnit` equivalent.

### asSuffix

public String asSuffix()
Convert this `Unit` to a simple `String` suffix, suitable for the `SIMPLE` style.

### parse

public Duration parse(String value)
Parse a `long` from the given `String` and interpret it to be a `Duration` in the current unit.

Parameters:
  `value` - the `String` representation of the long
Returns:
  the corresponding `Duration`

### print

public String print(Duration value)
Print the given `Duration` as a `String`, converting it to a long value using this unit's precision via `longValue(Duration)` and appending this unit's simple `suffix`.

Parameters:
  `value` - the `Duration` to convert to a `String`
Returns:
  the `String` representation of the `Duration` in the `SIMPLE` style

### longValue

public long longValue(Duration value)
Convert the given `Duration` to a long value in the resolution of this unit.

Note that this can be lossy if the current unit is bigger than the actual resolution of the duration. For example, `Duration.ofMillis(5).plusNanos(1234)` would get truncated to `5` for unit `MILLIS`.

Parameters:
  `value` - the `Duration` to convert to a long
Returns:
  the long value for the `Duration` in this `Unit`

### fromChronoUnit

public static DurationFormat.Unit fromChronoUnit(@Nullable ChronoUnit chronoUnit)
Get the `DurationFormat.Unit` corresponding to the given `ChronoUnit`.

Throws:
  `IllegalArgumentException` - if the given `ChronoUnit` is not supported

### fromSuffix

public static DurationFormat.Unit fromSuffix(String suffix)
Get the `DurationFormat.Unit` corresponding to the given `String` suffix.

Throws:
  `IllegalArgumentException` - if the given suffix is not supported