Class Duration

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

@Generated(value="jsii-pacmak/1.95.0 (build f1ff514)", date="2024-03-26T18:09:18.462Z") @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:

 Role myRole;
 AwsCustomResource.Builder.create(this, "Customized")
         .role(myRole) // must be assumable by the `lambda.amazonaws.com` service principal
         .timeout(Duration.minutes(10)) // defaults to 2 minutes
         .logGroup(LogGroup.Builder.create(this, "AwsCustomResourceLogs")
                 .retention(RetentionDays.ONE_DAY)
                 .build())
         .functionName("my-custom-name") // defaults to a CloudFormation generated name
         .removalPolicy(RemovalPolicy.RETAIN) // defaults to `RemovalPolicy.DESTROY`
         .policy(AwsCustomResourcePolicy.fromSdkCalls(SdkCallsPolicyOptions.builder()
                 .resources(AwsCustomResourcePolicy.ANY_RESOURCE)
                 .build()))
         .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.

      Days are the largest ISO duration supported, i.e., weeks, months, and years are not supported.

      Example:

       // This represents 1 day, 2 hours, 3 minutes, 4 seconds, and 567 milliseconds.
       "P1DT2H3M4.567S";
       

      Parameters:
      duration - an ISO-formatted 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:
    • 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.