Show / Hide Table of Contents

Class Duration

Represents a length of time.

Inheritance
object
Duration
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Duration : DeputyBase
Syntax (vb)
Public Class Duration Inherits DeputyBase
Remarks

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.

ExampleMetadata: infused

Examples
Role myRole;

             new AwsCustomResource(this, "Customized", new AwsCustomResourceProps {
                 Role = myRole,  // must be assumable by the `lambda.amazonaws.com` service principal
                 Timeout = Duration.Minutes(10),  // defaults to 2 minutes
                 MemorySize = 1025,  // defaults to 512 if installLatestAwsSdk is true
                 LogGroup = new LogGroup(this, "AwsCustomResourceLogs", new LogGroupProps {
                     Retention = RetentionDays.ONE_DAY
                 }),
                 FunctionName = "my-custom-name",  // defaults to a CloudFormation generated name
                 RemovalPolicy = RemovalPolicy.RETAIN,  // defaults to `RemovalPolicy.DESTROY`
                 Policy = AwsCustomResourcePolicy.FromSdkCalls(new SdkCallsPolicyOptions {
                     Resources = AwsCustomResourcePolicy.ANY_RESOURCE
                 })
             });

Synopsis

Methods

Days(double)

Create a Duration representing an amount of days.

FormatTokenToNumber()

Returns stringified number of duration.

Hours(double)

Create a Duration representing an amount of hours.

IsUnresolved()

Checks if duration is a token or a resolvable object.

Millis(double)

Create a Duration representing an amount of milliseconds.

Minus(Duration)

Substract two Durations together.

Minutes(double)

Create a Duration representing an amount of minutes.

Parse(string)

Parse a period formatted according to the ISO 8601 standard.

Plus(Duration)

Add two Durations together.

Seconds(double)

Create a Duration representing an amount of seconds.

ToDays(ITimeConversionOptions?)

Return the total number of days in this Duration.

ToHours(ITimeConversionOptions?)

Return the total number of hours in this Duration.

ToHumanString()

Turn this duration into a human-readable string.

ToIsoString()

Return an ISO 8601 representation of this period.

ToMilliseconds(ITimeConversionOptions?)

Return the total number of milliseconds in this Duration.

ToMinutes(ITimeConversionOptions?)

Return the total number of minutes in this Duration.

ToSeconds(ITimeConversionOptions?)

Return the total number of seconds in this Duration.

ToString()

Returns a string representation of this Duration.

UnitLabel()

Returns unit of the duration.

Methods

Days(double)

Create a Duration representing an amount of days.

public static Duration Days(double amount)
Parameters
amount double

the amount of Days the Duration will represent.

Returns

Duration

a new Duration representing amount Days.

Remarks

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.

ExampleMetadata: infused

FormatTokenToNumber()

Returns stringified number of duration.

public virtual string FormatTokenToNumber()
Returns

string

Remarks

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.

ExampleMetadata: infused

Hours(double)

Create a Duration representing an amount of hours.

public static Duration Hours(double amount)
Parameters
amount double

the amount of Hours the Duration will represent.

Returns

Duration

a new Duration representing amount Hours.

Remarks

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.

ExampleMetadata: infused

IsUnresolved()

Checks if duration is a token or a resolvable object.

public virtual bool IsUnresolved()
Returns

bool

Remarks

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.

ExampleMetadata: infused

Millis(double)

Create a Duration representing an amount of milliseconds.

public static Duration Millis(double amount)
Parameters
amount double

the amount of Milliseconds the Duration will represent.

Returns

Duration

a new Duration representing amount ms.

Remarks

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.

ExampleMetadata: infused

Minus(Duration)

Substract two Durations together.

public virtual Duration Minus(Duration rhs)
Parameters
rhs Duration
Returns

Duration

Remarks

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.

ExampleMetadata: infused

Minutes(double)

Create a Duration representing an amount of minutes.

public static Duration Minutes(double amount)
Parameters
amount double

the amount of Minutes the Duration will represent.

Returns

Duration

a new Duration representing amount Minutes.

Remarks

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.

ExampleMetadata: infused

Parse(string)

Parse a period formatted according to the ISO 8601 standard.

public static Duration Parse(string duration)
Parameters
duration string

an ISO-formatted duration to be parsed.

Returns

Duration

the parsed Duration.

Remarks

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

See: https://www.iso.org/standard/70907.html

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

Plus(Duration)

Add two Durations together.

public virtual Duration Plus(Duration rhs)
Parameters
rhs Duration
Returns

Duration

Remarks

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.

ExampleMetadata: infused

Seconds(double)

Create a Duration representing an amount of seconds.

public static Duration Seconds(double amount)
Parameters
amount double

the amount of Seconds the Duration will represent.

Returns

Duration

a new Duration representing amount Seconds.

Remarks

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.

ExampleMetadata: infused

ToDays(ITimeConversionOptions?)

Return the total number of days in this Duration.

public virtual double ToDays(ITimeConversionOptions? opts = null)
Parameters
opts ITimeConversionOptions
Returns

double

the value of this Duration expressed in Days.

Remarks

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.

ExampleMetadata: infused

ToHours(ITimeConversionOptions?)

Return the total number of hours in this Duration.

public virtual double ToHours(ITimeConversionOptions? opts = null)
Parameters
opts ITimeConversionOptions
Returns

double

the value of this Duration expressed in Hours.

Remarks

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.

ExampleMetadata: infused

ToHumanString()

Turn this duration into a human-readable string.

public virtual string ToHumanString()
Returns

string

Remarks

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.

ExampleMetadata: infused

ToIsoString()

Return an ISO 8601 representation of this period.

public virtual string ToIsoString()
Returns

string

a string starting with 'P' describing the period

Remarks

See: https://www.iso.org/standard/70907.html

ToMilliseconds(ITimeConversionOptions?)

Return the total number of milliseconds in this Duration.

public virtual double ToMilliseconds(ITimeConversionOptions? opts = null)
Parameters
opts ITimeConversionOptions
Returns

double

the value of this Duration expressed in Milliseconds.

Remarks

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.

ExampleMetadata: infused

ToMinutes(ITimeConversionOptions?)

Return the total number of minutes in this Duration.

public virtual double ToMinutes(ITimeConversionOptions? opts = null)
Parameters
opts ITimeConversionOptions
Returns

double

the value of this Duration expressed in Minutes.

Remarks

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.

ExampleMetadata: infused

ToSeconds(ITimeConversionOptions?)

Return the total number of seconds in this Duration.

public virtual double ToSeconds(ITimeConversionOptions? opts = null)
Parameters
opts ITimeConversionOptions
Returns

double

the value of this Duration expressed in Seconds.

Remarks

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.

ExampleMetadata: infused

ToString()

Returns a string representation of this Duration.

public override string ToString()
Returns

string

Remarks

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()

Returns unit of the duration.

public virtual string UnitLabel()
Returns

string

Remarks

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.

ExampleMetadata: infused

Back to top Generated by DocFX