class Duration
Language | Type name |
---|---|
![]() | Amazon.CDK.Duration |
![]() | github.com/aws/aws-cdk-go/awscdk/v2#Duration |
![]() | software.amazon.awscdk.Duration |
![]() | aws_cdk.Duration |
![]() | aws-cdk-lib » Duration |
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 * as ecs from 'aws-cdk-lib/aws-ecs';
declare const cluster: ecs.ICluster;
declare const taskDefinition: ecs.TaskDefinition;
const rule = new events.Rule(this, 'Rule', {
schedule: events.Schedule.rate(cdk.Duration.hours(1)),
});
rule.addTarget(new targets.EcsTask({
cluster,
taskDefinition,
taskCount: 1,
containerOverrides: [{
containerName: 'TheContainer',
command: ['echo', events.EventField.fromPath('$.detail.event')],
}],
enableExecuteCommand: true,
}));
Methods
Name | Description |
---|---|
format | Returns stringified number of duration. |
is | Checks if duration is a token or a resolvable object. |
minus(rhs) | Substract two Durations together. |
plus(rhs) | Add two Durations together. |
to | Return the total number of days in this Duration. |
to | Return the total number of hours in this Duration. |
to | Turn this duration into a human-readable string. |
to | Return an ISO 8601 representation of this period. |
to | Return the total number of milliseconds in this Duration. |
to | Return the total number of minutes in this Duration. |
to | Return the total number of seconds in this Duration. |
to | Returns a string representation of this Duration . |
unit | Returns unit of the duration. |
static days(amount) | Create a Duration representing an amount of days. |
static hours(amount) | Create a Duration representing an amount of hours. |
static millis(amount) | Create a Duration representing an amount of milliseconds. |
static minutes(amount) | Create a Duration representing an amount of minutes. |
static parse(duration) | Parse a period formatted according to the ISO 8601 standard. |
static seconds(amount) | Create a Duration representing an amount of seconds. |
formatTokenToNumber()
public formatTokenToNumber(): string
Returns
string
Returns stringified number of duration.
isUnresolved()
public isUnresolved(): boolean
Returns
boolean
Checks if duration is a token or a resolvable object.
minus(rhs)
public minus(rhs: Duration): Duration
Parameters
- rhs
Duration
Returns
Substract two Durations together.
plus(rhs)
public plus(rhs: Duration): Duration
Parameters
- rhs
Duration
Returns
Add two Durations together.
toDays(opts?)
public toDays(opts?: TimeConversionOptions): number
Parameters
Returns
number
Return the total number of days in this Duration.
toHours(opts?)
public toHours(opts?: TimeConversionOptions): number
Parameters
Returns
number
Return the total number of hours in this Duration.
toHumanString()
public toHumanString(): string
Returns
string
Turn this duration into a human-readable string.
toIsoString()
public toIsoString(): string
Returns
string
Return an ISO 8601 representation of this period.
See also: https://www.iso.org/standard/70907.html
toMilliseconds(opts?)
public toMilliseconds(opts?: TimeConversionOptions): number
Parameters
Returns
number
Return the total number of milliseconds in this Duration.
toMinutes(opts?)
public toMinutes(opts?: TimeConversionOptions): number
Parameters
Returns
number
Return the total number of minutes in this Duration.
toSeconds(opts?)
public toSeconds(opts?: TimeConversionOptions): number
Parameters
Returns
number
Return the total number of seconds in this Duration.
toString()
public toString(): string
Returns
string
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.
unitLabel()
public unitLabel(): string
Returns
string
Returns unit of the duration.
static days(amount)
public static days(amount: number): Duration
Parameters
- amount
number
— the amount of Days theDuration
will represent.
Returns
Create a Duration representing an amount of days.
static hours(amount)
public static hours(amount: number): Duration
Parameters
- amount
number
— the amount of Hours theDuration
will represent.
Returns
Create a Duration representing an amount of hours.
static millis(amount)
public static millis(amount: number): Duration
Parameters
- amount
number
— the amount of Milliseconds theDuration
will represent.
Returns
Create a Duration representing an amount of milliseconds.
static minutes(amount)
public static minutes(amount: number): Duration
Parameters
- amount
number
— the amount of Minutes theDuration
will represent.
Returns
Create a Duration representing an amount of minutes.
static parse(duration)
public static parse(duration: string): Duration
Parameters
- duration
string
— an ISO-formatted duration to be parsed.
Returns
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.
See also: https://www.iso.org/standard/70907.html Example
// This represents 1 day, 2 hours, 3 minutes, 4 seconds, and 567 milliseconds.
'P1DT2H3M4.567S'
static seconds(amount)
public static seconds(amount: number): Duration
Parameters
- amount
number
— the amount of Seconds theDuration
will represent.
Returns
Create a Duration representing an amount of seconds.