Class: ActionView::Helpers::DateTimeSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_time_select.rb

Instance Method Summary collapse

Instance Method Details

#select_hour_with_simple_time_selectObject



58
59
60
61
62
# File 'lib/simple_time_select.rb', line 58

def select_hour_with_simple_time_select
  return select_hour_without_simple_time_select unless @options[:simple_time_select].eql? true
  # Don't build the hour select
  #build_hidden(:hour, val)
end

#select_minute_with_simple_time_selectObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/simple_time_select.rb', line 3

def select_minute_with_simple_time_select
  return select_minute_without_simple_time_select unless @options[:simple_time_select].eql? true
  
  # Although this is a datetime select, we only care about the time.  Assume that the date will
  # be set by some other control, and the date represented here will be overriden
  
  val_minutes = @datetime.kind_of?(Time) ? @datetime.min + @datetime.hour*60 : @datetime
  
  @options[:time_separator] = ""
  
  # Default is 15 minute intervals
  minute_interval = 15
  if @options[:minute_interval] 
    minute_interval = @options[:minute_interval] 
  end

  start_minute = 0
  # @options[:start_hour] should be specified in military
  # i.e. 0-23
  if @options[:start_hour]
    start_minute = @options[:start_hour] * 60
  end
  
  end_minute = 1439
  # @options[:end_hour] should be specified in military
  # i.e. 0-23
  if @options[:end_hour]
    end_minute = ( @options[:end_hour] + 1 ) * 60 - 1  
  end
  
  if @options[:use_hidden] || @options[:discard_minute]
    build_hidden(:minute, val)
  else
    minute_options = []
    start_minute.upto(end_minute) do |minute|
      if minute%minute_interval == 0
        ampm = minute < 720 ? ' AM' : ' PM'
        hour = minute/60
        minute_padded = zero_pad_num(minute%60)
        hour_padded = zero_pad_num(hour)
        ampm_hour = ampm_hour(hour)
        
        val = "#{hour_padded}:#{minute_padded}:00"
        minute_options << ((val_minutes == minute) ? 
          %(<option value="#{val}" selected="selected">#{ampm_hour}:#{minute_padded}#{ampm}</option>\n) :
          %(<option value="#{val}">#{ampm_hour}:#{minute_padded}#{ampm}</option>\n)
        )
      end
    end
    build_select(:minute, minute_options)
  end
end

#select_second_with_simple_time_selectObject



65
66
67
68
69
# File 'lib/simple_time_select.rb', line 65

def select_second_with_simple_time_select
  return select_second_without_simple_time_select unless @options[:simple_time_select].eql? true
  # Don't build the seconds select
  #build_hidden(:second, val)
end