Module: CombinedTimeSelect::DateTimeSelectorWithSimpleTimeSelect

Defined in:
lib/combined_time_select.rb

Instance Method Summary collapse

Instance Method Details

#select_dayObject



83
84
85
86
87
# File 'lib/combined_time_select.rb', line 83

def select_day
  return super unless @options[:combined].eql? true
  # Don't build the day select
  #build_hidden(:day, val)
end

#select_hourObject



59
60
61
62
63
# File 'lib/combined_time_select.rb', line 59

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

#select_minuteObject



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
55
56
57
# File 'lib/combined_time_select.rb', line 5

def select_minute
  return super unless @options[:combined].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 = @options.fetch(:minute_interval, 15)

  start_minute = 0
  end_minute   = 1439

  # @options[:start_hour] should be specified in military
  # i.e. 0-23
  if @options[:start_hour]
    start_minute =  @options[:start_hour] * 60
    start_minute += @options.fetch(:start_minute, 0)
  end

  # @options[:end_hour] should be specified in military
  # i.e. 0-23
  if @options[:end_hour]
    end_minute = (@options[:end_hour] * 60) + @options.fetch(:end_minute, 59)
  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"

        option_text = @options[:ampm] ? "#{ampm_hour}:#{minute_padded}#{ampm}" : "#{hour_padded}:#{minute_padded}"
        minute_options << ((val_minutes == minute) ?
          %(<option value="#{val}" selected="selected">#{option_text}</option>\n) :
          %(<option value="#{val}">#{option_text}</option>\n)
        )
      end
    end
    build_select(:minute, minute_options.join(' '))
  end
end

#select_monthObject



77
78
79
80
81
# File 'lib/combined_time_select.rb', line 77

def select_month
  return super unless @options[:combined].eql? true
  # Don't build the month select
  #build_hidden(:month, val)
end

#select_secondObject



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

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

#select_yearObject



71
72
73
74
75
# File 'lib/combined_time_select.rb', line 71

def select_year
  return super unless @options[:combined].eql? true
  # Don't build the year select
  #build_hidden(:year, val)
end