Class: AWSCDK::Duration

Inherits:
Jsii::Object
  • Object
show all
Defined in:
duration.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Duration

Returns a new instance of Duration.

Raises:

  • (NoMethodError)


13
14
15
# File 'duration.rb', line 13

def initialize(*args)
  raise NoMethodError, "aws-cdk-lib.Duration does not have a visible constructor; use the provided factory methods"
end

Class Method Details

.days(amount) ⇒ AWSCDK::Duration

Create a Duration representing an amount of days.

Parameters:

  • amount (Numeric)

    the amount of Days the Duration will represent.

Returns:

  • (AWSCDK::Duration)

    a new Duration representing amount Days.



39
40
41
42
# File 'duration.rb', line 39

def self.days(amount)
  Jsii::Type.check_type(amount, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "amount")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.Duration", "days", [amount])
end

.hours(amount) ⇒ AWSCDK::Duration

Create a Duration representing an amount of hours.

Parameters:

  • amount (Numeric)

    the amount of Hours the Duration will represent.

Returns:

  • (AWSCDK::Duration)

    a new Duration representing amount Hours.



48
49
50
51
# File 'duration.rb', line 48

def self.hours(amount)
  Jsii::Type.check_type(amount, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "amount")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.Duration", "hours", [amount])
end

.jsii_overridable_methodsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'duration.rb', line 17

def self.jsii_overridable_methods
  {
    :format_token_to_number => { kind: :method, name: "formatTokenToNumber", is_optional: false },
    :is_unresolved => { kind: :method, name: "isUnresolved", is_optional: false },
    :minus => { kind: :method, name: "minus", is_optional: false },
    :plus => { kind: :method, name: "plus", is_optional: false },
    :to_days => { kind: :method, name: "toDays", is_optional: false },
    :to_hours => { kind: :method, name: "toHours", is_optional: false },
    :to_human_string => { kind: :method, name: "toHumanString", is_optional: false },
    :to_iso_string => { kind: :method, name: "toIsoString", is_optional: false },
    :to_milliseconds => { kind: :method, name: "toMilliseconds", is_optional: false },
    :to_minutes => { kind: :method, name: "toMinutes", is_optional: false },
    :to_seconds => { kind: :method, name: "toSeconds", is_optional: false },
    :to_string => { kind: :method, name: "toString", is_optional: false },
    :unit_label => { kind: :method, name: "unitLabel", is_optional: false },
  }
end

.millis(amount) ⇒ AWSCDK::Duration

Create a Duration representing an amount of milliseconds.

Parameters:

  • amount (Numeric)

    the amount of Milliseconds the Duration will represent.

Returns:

  • (AWSCDK::Duration)

    a new Duration representing amount ms.



57
58
59
60
# File 'duration.rb', line 57

def self.millis(amount)
  Jsii::Type.check_type(amount, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "amount")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.Duration", "millis", [amount])
end

.minutes(amount) ⇒ AWSCDK::Duration

Create a Duration representing an amount of minutes.

Parameters:

  • amount (Numeric)

    the amount of Minutes the Duration will represent.

Returns:

  • (AWSCDK::Duration)

    a new Duration representing amount Minutes.



66
67
68
69
# File 'duration.rb', line 66

def self.minutes(amount)
  Jsii::Type.check_type(amount, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "amount")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.Duration", "minutes", [amount])
end

.parse(duration) ⇒ AWSCDK::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.

Examples:

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

Parameters:

  • duration (String)

    an ISO-formatted duration to be parsed.

Returns:

  • (AWSCDK::Duration)

    the parsed Duration.

See Also:



82
83
84
85
# File 'duration.rb', line 82

def self.parse(duration)
  Jsii::Type.check_type(duration, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "duration")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.Duration", "parse", [duration])
end

.seconds(amount) ⇒ AWSCDK::Duration

Create a Duration representing an amount of seconds.

Parameters:

  • amount (Numeric)

    the amount of Seconds the Duration will represent.

Returns:

  • (AWSCDK::Duration)

    a new Duration representing amount Seconds.



91
92
93
94
# File 'duration.rb', line 91

def self.seconds(amount)
  Jsii::Type.check_type(amount, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "amount")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.Duration", "seconds", [amount])
end

Instance Method Details

#format_token_to_numberString

Returns stringified number of duration.

Returns:

  • (String)


99
100
101
# File 'duration.rb', line 99

def format_token_to_number()
  jsii_call_method("formatTokenToNumber", [])
end

#is_unresolvedBoolean

Checks if duration is a token or a resolvable object.

Returns:

  • (Boolean)


106
107
108
# File 'duration.rb', line 106

def is_unresolved()
  jsii_call_method("isUnresolved", [])
end

#minus(rhs) ⇒ AWSCDK::Duration

Substract two Durations together.

Parameters:

  • rhs (AWSCDK::Duration)

Returns:

  • (AWSCDK::Duration)


114
115
116
117
# File 'duration.rb', line 114

def minus(rhs)
  Jsii::Type.check_type(rhs, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5EdXJhdGlvbiJ9")), "rhs")
  jsii_call_method("minus", [rhs])
end

#plus(rhs) ⇒ AWSCDK::Duration

Add two Durations together.

Parameters:

  • rhs (AWSCDK::Duration)

Returns:

  • (AWSCDK::Duration)


123
124
125
126
# File 'duration.rb', line 123

def plus(rhs)
  Jsii::Type.check_type(rhs, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5EdXJhdGlvbiJ9")), "rhs")
  jsii_call_method("plus", [rhs])
end

#to_days(opts = nil) ⇒ Numeric

Return the total number of days in this Duration.

Parameters:

Returns:

  • (Numeric)

    the value of this Duration expressed in Days.



132
133
134
135
136
# File 'duration.rb', line 132

def to_days(opts = nil)
  opts = opts.is_a?(Hash) ? ::AWSCDK::TimeConversionOptions.new(**opts.transform_keys(&:to_sym)) : opts
  Jsii::Type.check_type(opts, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5UaW1lQ29udmVyc2lvbk9wdGlvbnMifQ==")), "opts") unless opts.nil?
  jsii_call_method("toDays", [opts])
end

#to_hours(opts = nil) ⇒ Numeric

Return the total number of hours in this Duration.

Parameters:

Returns:

  • (Numeric)

    the value of this Duration expressed in Hours.



142
143
144
145
146
# File 'duration.rb', line 142

def to_hours(opts = nil)
  opts = opts.is_a?(Hash) ? ::AWSCDK::TimeConversionOptions.new(**opts.transform_keys(&:to_sym)) : opts
  Jsii::Type.check_type(opts, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5UaW1lQ29udmVyc2lvbk9wdGlvbnMifQ==")), "opts") unless opts.nil?
  jsii_call_method("toHours", [opts])
end

#to_human_stringString

Turn this duration into a human-readable string.

Returns:

  • (String)


151
152
153
# File 'duration.rb', line 151

def to_human_string()
  jsii_call_method("toHumanString", [])
end

#to_iso_stringString

Return an ISO 8601 representation of this period.

Returns:

  • (String)

    a string starting with 'P' describing the period

See Also:



159
160
161
# File 'duration.rb', line 159

def to_iso_string()
  jsii_call_method("toIsoString", [])
end

#to_milliseconds(opts = nil) ⇒ Numeric

Return the total number of milliseconds in this Duration.

Parameters:

Returns:

  • (Numeric)

    the value of this Duration expressed in Milliseconds.



167
168
169
170
171
# File 'duration.rb', line 167

def to_milliseconds(opts = nil)
  opts = opts.is_a?(Hash) ? ::AWSCDK::TimeConversionOptions.new(**opts.transform_keys(&:to_sym)) : opts
  Jsii::Type.check_type(opts, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5UaW1lQ29udmVyc2lvbk9wdGlvbnMifQ==")), "opts") unless opts.nil?
  jsii_call_method("toMilliseconds", [opts])
end

#to_minutes(opts = nil) ⇒ Numeric

Return the total number of minutes in this Duration.

Parameters:

Returns:

  • (Numeric)

    the value of this Duration expressed in Minutes.



177
178
179
180
181
# File 'duration.rb', line 177

def to_minutes(opts = nil)
  opts = opts.is_a?(Hash) ? ::AWSCDK::TimeConversionOptions.new(**opts.transform_keys(&:to_sym)) : opts
  Jsii::Type.check_type(opts, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5UaW1lQ29udmVyc2lvbk9wdGlvbnMifQ==")), "opts") unless opts.nil?
  jsii_call_method("toMinutes", [opts])
end

#to_seconds(opts = nil) ⇒ Numeric

Return the total number of seconds in this Duration.

Parameters:

Returns:

  • (Numeric)

    the value of this Duration expressed in Seconds.



187
188
189
190
191
# File 'duration.rb', line 187

def to_seconds(opts = nil)
  opts = opts.is_a?(Hash) ? ::AWSCDK::TimeConversionOptions.new(**opts.transform_keys(&:to_sym)) : opts
  Jsii::Type.check_type(opts, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5UaW1lQ29udmVyc2lvbk9wdGlvbnMifQ==")), "opts") unless opts.nil?
  jsii_call_method("toSeconds", [opts])
end

#to_stringString

Returns a string representation of this Duration.

This is never the right function to use when you want to use the Duration object in a template. Use to_seconds(), to_minutes(), to_days(), etc. instead.

Returns:

  • (String)


199
200
201
# File 'duration.rb', line 199

def to_string()
  jsii_call_method("toString", [])
end

#unit_labelString

Returns unit of the duration.

Returns:

  • (String)


206
207
208
# File 'duration.rb', line 206

def unit_label()
  jsii_call_method("unitLabel", [])
end