Class Duration

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.core.Duration
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:29:55.030Z") @Stability(Stable) public class Duration extends software.amazon.jsii.JsiiObject
Represents a length of time.

The amount can be specified either as a literal value (e.g: 10) which cannot be negative, or as an unresolved number token.

When the amount is passed as a token, unit conversion is not possible.

Example:

 import software.amazon.awscdk.services.lambda.*;
 Function fn = Function.Builder.create(this, "MyFunc")
         .runtime(Runtime.NODEJS_14_X)
         .handler("index.handler")
         .code(Code.fromInline("exports.handler = handler.toString()"))
         .build();
 Rule rule = Rule.Builder.create(this, "rule")
         .eventPattern(EventPattern.builder()
                 .source(List.of("aws.ec2"))
                 .build())
         .build();
 Queue queue = new Queue(this, "Queue");
 rule.addTarget(LambdaFunction.Builder.create(fn)
         .deadLetterQueue(queue) // Optional: add a dead letter queue
         .maxEventAge(Duration.hours(2)) // Optional: set the maxEventAge retry policy
         .retryAttempts(2)
         .build());
 
  • Constructor Details

    • Duration

      protected Duration(software.amazon.jsii.JsiiObjectRef objRef)
    • Duration

      protected Duration(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
  • Method Details

    • days

      @Stability(Stable) @NotNull public static Duration days(@NotNull Number amount)
      Create a Duration representing an amount of days.

      Parameters:
      amount - the amount of Days the Duration will represent. This parameter is required.
      Returns:
      a new Duration representing amount Days.
    • hours

      @Stability(Stable) @NotNull public static Duration hours(@NotNull Number amount)
      Create a Duration representing an amount of hours.

      Parameters:
      amount - the amount of Hours the Duration will represent. This parameter is required.
      Returns:
      a new Duration representing amount Hours.
    • millis

      @Stability(Stable) @NotNull public static Duration millis(@NotNull Number amount)
      Create a Duration representing an amount of milliseconds.

      Parameters:
      amount - the amount of Milliseconds the Duration will represent. This parameter is required.
      Returns:
      a new Duration representing amount ms.
    • minutes

      @Stability(Stable) @NotNull public static Duration minutes(@NotNull Number amount)
      Create a Duration representing an amount of minutes.

      Parameters:
      amount - the amount of Minutes the Duration will represent. This parameter is required.
      Returns:
      a new Duration representing amount Minutes.
    • parse

      @Stability(Stable) @NotNull public static Duration parse(@NotNull String duration)
      Parse a period formatted according to the ISO 8601 standard.

      Parameters:
      duration - an ISO-formtted duration to be parsed. This parameter is required.
      Returns:
      the parsed Duration.
      See Also:
    • seconds

      @Stability(Stable) @NotNull public static Duration seconds(@NotNull Number amount)
      Create a Duration representing an amount of seconds.

      Parameters:
      amount - the amount of Seconds the Duration will represent. This parameter is required.
      Returns:
      a new Duration representing amount Seconds.
    • formatTokenToNumber

      @Stability(Stable) @NotNull public String formatTokenToNumber()
      Returns stringified number of duration.
    • isUnresolved

      @Stability(Stable) @NotNull public Boolean isUnresolved()
      Checks if duration is a token or a resolvable object.
    • minus

      @Stability(Stable) @NotNull public Duration minus(@NotNull Duration rhs)
      Substract two Durations together.

      Parameters:
      rhs - This parameter is required.
    • plus

      @Stability(Stable) @NotNull public Duration plus(@NotNull Duration rhs)
      Add two Durations together.

      Parameters:
      rhs - This parameter is required.
    • toDays

      @Stability(Stable) @NotNull public Number toDays(@Nullable TimeConversionOptions opts)
      Return the total number of days in this Duration.

      Parameters:
      opts -
      Returns:
      the value of this Duration expressed in Days.
    • toDays

      @Stability(Stable) @NotNull public Number toDays()
      Return the total number of days in this Duration.

      Returns:
      the value of this Duration expressed in Days.
    • toHours

      @Stability(Stable) @NotNull public Number toHours(@Nullable TimeConversionOptions opts)
      Return the total number of hours in this Duration.

      Parameters:
      opts -
      Returns:
      the value of this Duration expressed in Hours.
    • toHours

      @Stability(Stable) @NotNull public Number toHours()
      Return the total number of hours in this Duration.

      Returns:
      the value of this Duration expressed in Hours.
    • toHumanString

      @Stability(Stable) @NotNull public String toHumanString()
      Turn this duration into a human-readable string.
    • toIsoString

      @Stability(Stable) @NotNull public String toIsoString()
      Return an ISO 8601 representation of this period.

      Returns:
      a string starting with 'P' describing the period
      See Also:
    • toISOString

      @Stability(Deprecated) @Deprecated @NotNull public String toISOString()
      Deprecated.
      Use toIsoString() instead.
      (deprecated) Return an ISO 8601 representation of this period.

      Returns:
      a string starting with 'P' describing the period
      See Also:
    • toMilliseconds

      @Stability(Stable) @NotNull public Number toMilliseconds(@Nullable TimeConversionOptions opts)
      Return the total number of milliseconds in this Duration.

      Parameters:
      opts -
      Returns:
      the value of this Duration expressed in Milliseconds.
    • toMilliseconds

      @Stability(Stable) @NotNull public Number toMilliseconds()
      Return the total number of milliseconds in this Duration.

      Returns:
      the value of this Duration expressed in Milliseconds.
    • toMinutes

      @Stability(Stable) @NotNull public Number toMinutes(@Nullable TimeConversionOptions opts)
      Return the total number of minutes in this Duration.

      Parameters:
      opts -
      Returns:
      the value of this Duration expressed in Minutes.
    • toMinutes

      @Stability(Stable) @NotNull public Number toMinutes()
      Return the total number of minutes in this Duration.

      Returns:
      the value of this Duration expressed in Minutes.
    • toSeconds

      @Stability(Stable) @NotNull public Number toSeconds(@Nullable TimeConversionOptions opts)
      Return the total number of seconds in this Duration.

      Parameters:
      opts -
      Returns:
      the value of this Duration expressed in Seconds.
    • toSeconds

      @Stability(Stable) @NotNull public Number toSeconds()
      Return the total number of seconds in this Duration.

      Returns:
      the value of this Duration expressed in Seconds.
    • toString

      @Stability(Stable) @NotNull public String toString()
      Returns a string representation of this Duration.

      This is is never the right function to use when you want to use the Duration object in a template. Use toSeconds(), toMinutes(), toDays(), etc. instead.

      Overrides:
      toString in class Object
    • unitLabel

      @Stability(Stable) @NotNull public String unitLabel()
      Returns unit of the duration.