Class Duration
Represents a length of time.
public class Duration : DeputyBase
- Inheritance
-
Duration
Examples
using Amazon.CDK.AWS.Lambda;
var fn = new Function(this, "MyFunc", new FunctionProps {
Runtime = Runtime.NODEJS_14_X,
Handler = "index.handler",
Code = Code.FromInline("exports.handler = handler.toString()")
});
var rule = new Rule(this, "rule", new RuleProps {
EventPattern = new EventPattern {
Source = new [] { "aws.ec2" }
}
});
var queue = new Queue(this, "Queue");
rule.AddTarget(new LambdaFunction(fn, new LambdaFunctionProps {
DeadLetterQueue = queue, // Optional: add a dead letter queue
MaxEventAge = Duration.Hours(2), // Optional: set the maxEventAge retry policy
RetryAttempts = 2
}));
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
Methods
Days(double)
Create a Duration representing an amount of days.
public static Duration Days(double amount)
Parameters
amount
doublethe amount of Days the
Duration
will represent.
Returns
- Duration
a new
Duration
representingamount
Days.
FormatTokenToNumber()
Returns stringified number of duration.
public virtual string FormatTokenToNumber()
Returns
Hours(double)
Create a Duration representing an amount of hours.
public static Duration Hours(double amount)
Parameters
amount
doublethe amount of Hours the
Duration
will represent.
Returns
- Duration
a new
Duration
representingamount
Hours.
IsUnresolved()
Checks if duration is a token or a resolvable object.
public virtual bool IsUnresolved()
Returns
Millis(double)
Create a Duration representing an amount of milliseconds.
public static Duration Millis(double amount)
Parameters
amount
doublethe amount of Milliseconds the
Duration
will represent.
Returns
- Duration
a new
Duration
representingamount
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
doublethe amount of Minutes the
Duration
will represent.
Returns
- Duration
a new
Duration
representingamount
Minutes.
Parse(string)
Parse a period formatted according to the ISO 8601 standard.
public static Duration Parse(string duration)
Parameters
duration
stringan ISO-formtted duration to be parsed.
Returns
- Duration
the parsed
Duration
.
Remarks
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
doublethe amount of Seconds the
Duration
will represent.
Returns
- Duration
a new
Duration
representingamount
Seconds.
ToDays(ITimeConversionOptions?)
Return the total number of days in this Duration.
public virtual double ToDays(ITimeConversionOptions? opts = null)
Parameters
Returns
- 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
- double
the value of this
Duration
expressed in Hours.
ToHumanString()
Turn this duration into a human-readable string.
public virtual string ToHumanString()
Returns
ToISOString()
(deprecated) Return an ISO 8601 representation of this period.
[Obsolete("Use `toIsoString()` instead.")]
public virtual string ToISOString()
Returns
- string
a string starting with 'P' describing the period
Remarks
Stability: Deprecated
ToIsoString()
Return an ISO 8601 representation of this period.
public virtual string ToIsoString()
Returns
- 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
- 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
- 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
- double
the value of this
Duration
expressed in Seconds.
ToString()
Returns a string representation of this Duration
.
public override string ToString()
Returns
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()