Class Duration
Represents a length of time.
Inheritance
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
Constructors
Duration(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Duration(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
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 |
UnitLabel() | Returns unit of the duration. |
Constructors
Duration(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Duration(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Duration(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Duration(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
Days(Double)
Create a Duration representing an amount of days.
public static Duration Days(double amount)
Parameters
- amount System.Double
the amount of Days the
Duration
will represent.
Returns
a new Duration
representing amount
Days.
FormatTokenToNumber()
Returns stringified number of duration.
public virtual string FormatTokenToNumber()
Returns
System.String
Hours(Double)
Create a Duration representing an amount of hours.
public static Duration Hours(double amount)
Parameters
- amount System.Double
the amount of Hours the
Duration
will represent.
Returns
a new Duration
representing amount
Hours.
IsUnresolved()
Checks if duration is a token or a resolvable object.
public virtual bool IsUnresolved()
Returns
System.Boolean
Millis(Double)
Create a Duration representing an amount of milliseconds.
public static Duration Millis(double amount)
Parameters
- amount System.Double
the amount of Milliseconds the
Duration
will represent.
Returns
a new Duration
representing amount
ms.
Minus(Duration)
Substract two Durations together.
public virtual Duration Minus(Duration rhs)
Parameters
- rhs Duration
Returns
Minutes(Double)
Create a Duration representing an amount of minutes.
public static Duration Minutes(double amount)
Parameters
- amount System.Double
the amount of Minutes the
Duration
will represent.
Returns
a new Duration
representing amount
Minutes.
Parse(String)
Parse a period formatted according to the ISO 8601 standard.
public static Duration Parse(string duration)
Parameters
- duration System.String
an ISO-formatted duration to be parsed.
Returns
the parsed Duration
.
Remarks
Days are the largest ISO duration supported, i.e., weeks, months, and years are not supported.
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
Seconds(Double)
Create a Duration representing an amount of seconds.
public static Duration Seconds(double amount)
Parameters
- amount System.Double
the amount of Seconds the
Duration
will represent.
Returns
a new Duration
representing amount
Seconds.
ToDays(ITimeConversionOptions)
Return the total number of days in this Duration.
public virtual double ToDays(ITimeConversionOptions opts = null)
Parameters
Returns
System.Double
the value of this Duration
expressed in Days.
ToHours(ITimeConversionOptions)
Return the total number of hours in this Duration.
public virtual double ToHours(ITimeConversionOptions opts = null)
Parameters
Returns
System.Double
the value of this Duration
expressed in Hours.
ToHumanString()
Turn this duration into a human-readable string.
public virtual string ToHumanString()
Returns
System.String
ToIsoString()
Return an ISO 8601 representation of this period.
public virtual string ToIsoString()
Returns
System.String
a string starting with 'P' describing the period
Remarks
ToMilliseconds(ITimeConversionOptions)
Return the total number of milliseconds in this Duration.
public virtual double ToMilliseconds(ITimeConversionOptions opts = null)
Parameters
Returns
System.Double
the value of this Duration
expressed in Milliseconds.
ToMinutes(ITimeConversionOptions)
Return the total number of minutes in this Duration.
public virtual double ToMinutes(ITimeConversionOptions opts = null)
Parameters
Returns
System.Double
the value of this Duration
expressed in Minutes.
ToSeconds(ITimeConversionOptions)
Return the total number of seconds in this Duration.
public virtual double ToSeconds(ITimeConversionOptions opts = null)
Parameters
Returns
System.Double
the value of this Duration
expressed in Seconds.
ToString()
Returns a string representation of this Duration
.
public override string ToString()
Returns
System.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
System.String