java.lang.Object
software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute.DurationAttributeConverter
All Implemented Interfaces:
AttributeConverter<Duration>

@ThreadSafe @Immutable public final class DurationAttributeConverter extends Object implements AttributeConverter<Duration>
A converter between Duration and AttributeValue.

This stores and reads values in DynamoDB as a number, so that they can be sorted numerically as part of a sort key.

Durations are stored in the format "[-]X[.YYYYYYYYY]", where X is the number of seconds in the duration, and Y is the number of nanoseconds in the duration, left padded with zeroes to a length of 9. The Y and decimal point may be excluded for durations that are of whole seconds. The duration may be preceded by a - to indicate a negative duration.

Examples:

  • Duration.ofDays(1) is stored as ItemAttributeValueMapper.fromNumber("86400")
  • Duration.ofSeconds(9) is stored as ItemAttributeValueMapper.fromNumber("9")
  • Duration.ofSeconds(-9) is stored as ItemAttributeValueMapper.fromNumber("-9")
  • Duration.ofNanos(1_234_567_890) is stored as ItemAttributeValueMapper.fromNumber("1.234567890")
  • Duration.ofMillis(1) is stored as ItemAttributeValueMapper.fromNumber("0.001000000")
  • Duration.ofNanos(1) is stored as ItemAttributeValueMapper.fromNumber("0.000000001")
  • Duration.ofNanos(-1) is stored as ItemAttributeValueMapper.fromNumber("-0.000000001")

This can be created via create().