Class: TimePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb,
lib/glimmer-dsl-web/samples/hello/hello_input_date_time_data_binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTimePresenter

Returns a new instance of TimePresenter.



7
8
9
# File 'lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb', line 7

def initialize
  @date_time = Time.now
end

Instance Attribute Details

#date_timeObject

Returns the value of attribute date_time.



5
6
7
# File 'lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb', line 5

def date_time
  @date_time
end

#week_stringObject

Returns the value of attribute week_string.



5
6
7
# File 'lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb', line 5

def week_string
  @week_string
end

Instance Method Details

#date_time_stringObject



18
19
20
# File 'lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb', line 18

def date_time_string
  @date_time&.strftime('%Y-%m-%dT%H:%M')
end

#date_time_string=(value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/glimmer-dsl-web/samples/hello/hello_input_date_time.rb', line 22

def date_time_string=(value)
  if value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/)
    date_time_parts = value.split('T')
    date_parts = date_time_parts.first.split('-')
    time_parts = date_time_parts.last.split(':')
    self.date_time = Time.new(*date_parts, *time_parts)
  elsif value.strip.empty?
    self.date_time = nil
  end
end