Class: Seahorse::Model::Shapes::Timestamp

Inherits:
Shape
  • Object
show all
Defined in:
lib/seahorse/model/shapes.rb

Instance Attribute Summary collapse

Attributes inherited from Shape

#definition, #documentation, #location, #location_name, #name, #shape_map, #type

Instance Method Summary collapse

Methods inherited from Shape

#inspect, #metadata, new, #with

Constructor Details

#initialize(definition, options = {}) ⇒ Timestamp

Returns a new instance of Timestamp.



382
383
384
385
# File 'lib/seahorse/model/shapes.rb', line 382

def initialize(definition, options = {})
  @format = definition['timestampFormat']
  super
end

Instance Attribute Details

#formatString (readonly)

Returns:



388
389
390
# File 'lib/seahorse/model/shapes.rb', line 388

def format
  @format
end

Instance Method Details

#format_time(time, default_format) ⇒ String

Parameters:

  • time (Time)
  • default_format (String)

    The format to default to when #format is not set on this timestamp shape.

Returns:



394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/seahorse/model/shapes.rb', line 394

def format_time(time, default_format)
  format = @format || default_format
  case format
  when 'iso8601'       then time.utc.iso8601
  when 'rfc822'        then time.utc.rfc822
  when 'httpdate'      then time.httpdate
  when 'unixTimestamp' then time.utc.to_i
  else
    msg = "invalid timestamp format #{format.inspect}"
    raise ArgumentError, msg
  end
end