Duration

class aws_cdk.Duration(*args: Any, **kwargs)

Bases: object

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.

ExampleMetadata:

infused

Example:

# application: appconfig.Application
# bucket: s3.Bucket


appconfig.SourcedConfiguration(self, "MySourcedConfiguration",
    application=application,
    location=appconfig.ConfigurationSource.from_bucket(bucket, "path/to/file.json"),
    deployment_strategy=appconfig.DeploymentStrategy(self, "MyDeploymentStrategy",
        rollout_strategy=appconfig.RolloutStrategy.linear(
            growth_factor=15,
            deployment_duration=Duration.minutes(30),
            final_bake_time=Duration.minutes(15)
        )
    )
)

Methods

format_token_to_number()

Returns stringified number of duration.

Return type:

str

is_unresolved()

Checks if duration is a token or a resolvable object.

Return type:

bool

minus(rhs)

Substract two Durations together.

Parameters:

rhs (Duration) –

Return type:

Duration

plus(rhs)

Add two Durations together.

Parameters:

rhs (Duration) –

Return type:

Duration

to_days(*, integral=None)

Return the total number of days in this Duration.

Parameters:

integral (Optional[bool]) – If true, conversions into a larger time unit (e.g. Seconds to Minutes) will fail if the result is not an integer. Default: true

Return type:

Union[int, float]

Returns:

the value of this Duration expressed in Days.

to_hours(*, integral=None)

Return the total number of hours in this Duration.

Parameters:

integral (Optional[bool]) – If true, conversions into a larger time unit (e.g. Seconds to Minutes) will fail if the result is not an integer. Default: true

Return type:

Union[int, float]

Returns:

the value of this Duration expressed in Hours.

to_human_string()

Turn this duration into a human-readable string.

Return type:

str

to_iso_string()

Return an ISO 8601 representation of this period.

Return type:

str

Returns:

a string starting with ‘P’ describing the period

See:

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

to_milliseconds(*, integral=None)

Return the total number of milliseconds in this Duration.

Parameters:

integral (Optional[bool]) – If true, conversions into a larger time unit (e.g. Seconds to Minutes) will fail if the result is not an integer. Default: true

Return type:

Union[int, float]

Returns:

the value of this Duration expressed in Milliseconds.

to_minutes(*, integral=None)

Return the total number of minutes in this Duration.

Parameters:

integral (Optional[bool]) – If true, conversions into a larger time unit (e.g. Seconds to Minutes) will fail if the result is not an integer. Default: true

Return type:

Union[int, float]

Returns:

the value of this Duration expressed in Minutes.

to_seconds(*, integral=None)

Return the total number of seconds in this Duration.

Parameters:

integral (Optional[bool]) – If true, conversions into a larger time unit (e.g. Seconds to Minutes) will fail if the result is not an integer. Default: true

Return type:

Union[int, float]

Returns:

the value of this Duration expressed in Seconds.

to_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.

Return type:

str

unit_label()

Returns unit of the duration.

Return type:

str

Static Methods

classmethod days(amount)

Create a Duration representing an amount of days.

Parameters:

amount (Union[int, float]) – the amount of Days the Duration will represent.

Return type:

Duration

Returns:

a new Duration representing amount Days.

classmethod hours(amount)

Create a Duration representing an amount of hours.

Parameters:

amount (Union[int, float]) – the amount of Hours the Duration will represent.

Return type:

Duration

Returns:

a new Duration representing amount Hours.

classmethod millis(amount)

Create a Duration representing an amount of milliseconds.

Parameters:

amount (Union[int, float]) – the amount of Milliseconds the Duration will represent.

Return type:

Duration

Returns:

a new Duration representing amount ms.

classmethod minutes(amount)

Create a Duration representing an amount of minutes.

Parameters:

amount (Union[int, float]) – the amount of Minutes the Duration will represent.

Return type:

Duration

Returns:

a new Duration representing amount Minutes.

classmethod parse(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.

Parameters:

duration (str) – an ISO-formatted duration to be parsed.

Return type:

Duration

Returns:

the parsed Duration.

See:

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

Example:

# This represents 1 day, 2 hours, 3 minutes, 4 seconds, and 567 milliseconds.
"P1DT2H3M4.567S"
classmethod seconds(amount)

Create a Duration representing an amount of seconds.

Parameters:

amount (Union[int, float]) – the amount of Seconds the Duration will represent.

Return type:

Duration

Returns:

a new Duration representing amount Seconds.