@Generated(value="jsii-pacmak/1.67.0 (build 2c027f5)", date="2022-09-19T20:26:35.892Z") @Stability(value=Stable) public class Duration extends software.amazon.jsii.JsiiObject
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());
| Modifier | Constructor and Description |
|---|---|
protected |
Duration(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) |
protected |
Duration(software.amazon.jsii.JsiiObjectRef objRef) |
| Modifier and Type | Method and Description |
|---|---|
static Duration |
days(Number amount)
Create a Duration representing an amount of days.
|
String |
formatTokenToNumber()
Returns stringified number of duration.
|
static Duration |
hours(Number amount)
Create a Duration representing an amount of hours.
|
Boolean |
isUnresolved()
Checks if duration is a token or a resolvable object.
|
static Duration |
millis(Number amount)
Create a Duration representing an amount of milliseconds.
|
Duration |
minus(Duration rhs)
Substract two Durations together.
|
static Duration |
minutes(Number amount)
Create a Duration representing an amount of minutes.
|
static Duration |
parse(String duration)
Parse a period formatted according to the ISO 8601 standard.
|
Duration |
plus(Duration rhs)
Add two Durations together.
|
static Duration |
seconds(Number amount)
Create a Duration representing an amount of seconds.
|
Number |
toDays()
Return the total number of days in this Duration.
|
Number |
toDays(TimeConversionOptions opts)
Return the total number of days in this Duration.
|
Number |
toHours()
Return the total number of hours in this Duration.
|
Number |
toHours(TimeConversionOptions opts)
Return the total number of hours in this Duration.
|
String |
toHumanString()
Turn this duration into a human-readable string.
|
String |
toIsoString()
Return an ISO 8601 representation of this period.
|
Number |
toMilliseconds()
Return the total number of milliseconds in this Duration.
|
Number |
toMilliseconds(TimeConversionOptions opts)
Return the total number of milliseconds in this Duration.
|
Number |
toMinutes()
Return the total number of minutes in this Duration.
|
Number |
toMinutes(TimeConversionOptions opts)
Return the total number of minutes in this Duration.
|
Number |
toSeconds()
Return the total number of seconds in this Duration.
|
Number |
toSeconds(TimeConversionOptions opts)
Return the total number of seconds in this Duration.
|
String |
toString()
Returns a string representation of this `Duration`.
|
String |
unitLabel()
Returns unit of the duration.
|
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetprotected Duration(software.amazon.jsii.JsiiObjectRef objRef)
protected Duration(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
@Stability(value=Stable) @NotNull public static Duration days(@NotNull Number amount)
amount - the amount of Days the `Duration` will represent. This parameter is required.@Stability(value=Stable) @NotNull public static Duration hours(@NotNull Number amount)
amount - the amount of Hours the `Duration` will represent. This parameter is required.@Stability(value=Stable) @NotNull public static Duration millis(@NotNull Number amount)
amount - the amount of Milliseconds the `Duration` will represent. This parameter is required.@Stability(value=Stable) @NotNull public static Duration minutes(@NotNull Number amount)
amount - the amount of Minutes the `Duration` will represent. This parameter is required.@Stability(value=Stable) @NotNull public static Duration parse(@NotNull String duration)
duration - an ISO-formtted duration to be parsed. This parameter is required.@Stability(value=Stable) @NotNull public static Duration seconds(@NotNull Number amount)
amount - the amount of Seconds the `Duration` will represent. This parameter is required.@Stability(value=Stable) @NotNull public String formatTokenToNumber()
@Stability(value=Stable) @NotNull public Boolean isUnresolved()
@Stability(value=Stable) @NotNull public Duration minus(@NotNull Duration rhs)
rhs - This parameter is required.@Stability(value=Stable) @NotNull public Duration plus(@NotNull Duration rhs)
rhs - This parameter is required.@Stability(value=Stable) @NotNull public Number toDays(@Nullable TimeConversionOptions opts)
opts - @Stability(value=Stable) @NotNull public Number toDays()
@Stability(value=Stable) @NotNull public Number toHours(@Nullable TimeConversionOptions opts)
opts - @Stability(value=Stable) @NotNull public Number toHours()
@Stability(value=Stable) @NotNull public String toHumanString()
@Stability(value=Stable) @NotNull public String toIsoString()
@Stability(value=Stable) @NotNull public Number toMilliseconds(@Nullable TimeConversionOptions opts)
opts - @Stability(value=Stable) @NotNull public Number toMilliseconds()
@Stability(value=Stable) @NotNull public Number toMinutes(@Nullable TimeConversionOptions opts)
opts - @Stability(value=Stable) @NotNull public Number toMinutes()
@Stability(value=Stable) @NotNull public Number toSeconds(@Nullable TimeConversionOptions opts)
opts - @Stability(value=Stable) @NotNull public Number toSeconds()
@Stability(value=Stable) @NotNull public String toString()
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.
@Stability(value=Stable) @NotNull public String unitLabel()
Copyright © 2022. All rights reserved.