combined_time_select 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a59ca05dd103f66077ca5ee159ac848c1894ba33
4
- data.tar.gz: dda8d36fb1d46b1170f2f15a287271216b13473d
3
+ metadata.gz: 5df1e72bff11080a5c031e5f4fb0517ab42834be
4
+ data.tar.gz: 14f8139529a2c494321c5b6ab3ae825f4569f291
5
5
  SHA512:
6
- metadata.gz: dcf0ce0f2c2a7d8b291847550c2e4501c5ecad7856f9acdbc3eb829b14fd81d7116645b9bb01b2692df88328511fc0c36234fb981381d3a9dc10492f0f68663c
7
- data.tar.gz: cb5b09666cc7ee7b3fa01c22cc2cf5dd27fb507e63effd4e26fd3eb4806dd23e6162050dfc354df5dcc75485cd846a255253a04720c9ee889de662c1ba085102
6
+ metadata.gz: 6e1eea77be8282504e903895de1ac18e81118dc588589ff61963debd08e8a58bcef6a9ec18683b8e45dcc483a8aba1e1d88032eaadbc496d19afc71291e194c1
7
+ data.tar.gz: f713604c08235aa016fef23176055842433aa917c391986f94cde57b828d1bd3c6cb473f39a0135bb7416c3b9e13e585b7a90f71c588e46e017af7135ad3c598
@@ -1,3 +1,7 @@
1
+ ## v2.0.0
2
+
3
+ * Updated for Rails 5.x compatibility, older versions of Rails are not supported.
4
+
1
5
  ## v0.0.1
2
6
 
3
7
  * initial release
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  Combined Time Select
2
2
  ====================
3
3
 
4
+ Compatible with Rails 5+
5
+
4
6
  Written by [Chris Oliver](http://excid3.com) [@excid3](https://twitter.com/excid3).
5
7
 
6
8
  This is a small gem for creating Google Calendar style 12 hour AM/PM
7
- time_select fields for Rails 3. It's based off of [simple_time_select](https://github.com/tamoyal/simple_time_select) by tamoyal.
9
+ time_select fields for Rails. It's based off of [simple_time_select](https://github.com/tamoyal/simple_time_select) by tamoyal.
8
10
 
9
11
  ![combined_time_select](http://f.cl.ly/items/1945331M3W1h0f1K3I2v/Screen%20Shot%202011-12-23%20at%2012.08.37%20AM.png)
10
12
 
@@ -15,7 +17,7 @@ Installation
15
17
 
16
18
  Just add this into your Gemfile followed by a bundle install:
17
19
 
18
- gem "combined_time_select", "~> 1.0.1"
20
+ gem "combined_time_select", "~> 2.0.0"
19
21
 
20
22
  Usage
21
23
  -----
@@ -45,6 +47,8 @@ This will create a combined time select starting at 10:30 AM and going till
45
47
  value for the start_time attribute on the object this form was created
46
48
  for.
47
49
 
50
+ Because `combined_time_select` overrides the time_select method to provide you the combined time fields, there is no need to designate a method when using libraries such as Formtastic. You will, however, need to disable the built in hour and minute labels by indicating `:labels => false` (though you can still give your individual field a label with `:label => "Label Name"`) and to add in the am/pm designation for a 12 hour clock by indicating `:ampm => true`.
51
+
48
52
  On the controller side, we need to parse this attribute before we create
49
53
  a new object. combined_time_select provides a nice method for this
50
54
  called parse_time_select!. You can use this in your create action just
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
22
22
 
23
23
  # specify any dependencies here; for example:
24
24
  # s.add_development_dependency "rspec"
25
- # s.add_runtime_dependency "rest-client"
25
+ s.add_runtime_dependency "rails", ">= 5.0.0"
26
26
  end
@@ -1,114 +1,102 @@
1
1
  require "combined_time_select/version"
2
2
 
3
3
  module CombinedTimeSelect
4
- # Your code goes here...
5
- end
6
-
4
+ module DateTimeSelectorWithSimpleTimeSelect
5
+ def select_minute
6
+ return super unless @options[:combined].eql? true
7
7
 
8
- module ActiveSupport
9
- class HashWithIndifferentAccess < Hash
10
- def parse_time_select!(attribute)
11
- self[attribute] = Time.zone.parse("#{self["#{attribute}(1i)"]}-#{self["#{attribute}(2i)"]}-#{self["#{attribute}(3i)"]} #{self["#{attribute}(5i)"]}")
12
- (1..5).each { |i| self.delete "#{attribute}(#{i}i)" }
13
- self
14
- end
15
- end
16
- end
8
+ # Although this is a datetime select, we only care about the time. Assume that the date will
9
+ # be set by some other control, and the date represented here will be overriden
17
10
 
11
+ val_minutes = @datetime.kind_of?(Time) ? @datetime.min + @datetime.hour*60 : @datetime
18
12
 
19
- module ActionView::Helpers
20
- class DateTimeSelector
21
- def select_minute_with_simple_time_select
22
- return select_minute_without_simple_time_select unless @options[:combined].eql? true
13
+ @options[:time_separator] = ""
23
14
 
24
- # Although this is a datetime select, we only care about the time. Assume that the date will
25
- # be set by some other control, and the date represented here will be overriden
15
+ # Default is 15 minute intervals
16
+ minute_interval = @options.fetch(:minute_interval, 15)
26
17
 
27
- val_minutes = @datetime.kind_of?(Time) ? @datetime.min + @datetime.hour*60 : @datetime
18
+ start_minute = 0
19
+ end_minute = 1439
28
20
 
29
- @options[:time_separator] = ""
30
-
31
- # Default is 15 minute intervals
32
- minute_interval = @options.fetch(:minute_interval, 15)
33
-
34
- start_minute = 0
35
- end_minute = 1439
36
-
37
- # @options[:start_hour] should be specified in military
38
- # i.e. 0-23
39
- if @options[:start_hour]
40
- start_minute = @options[:start_hour] * 60
41
- start_minute += @options.fetch(:start_minute, 0)
42
- end
21
+ # @options[:start_hour] should be specified in military
22
+ # i.e. 0-23
23
+ if @options[:start_hour]
24
+ start_minute = @options[:start_hour] * 60
25
+ start_minute += @options.fetch(:start_minute, 0)
26
+ end
43
27
 
44
- # @options[:end_hour] should be specified in military
45
- # i.e. 0-23
46
- if @options[:end_hour]
47
- end_minute = (@options[:end_hour] * 60) + @options.fetch(:end_minute, 59)
48
- end
28
+ # @options[:end_hour] should be specified in military
29
+ # i.e. 0-23
30
+ if @options[:end_hour]
31
+ end_minute = (@options[:end_hour] * 60) + @options.fetch(:end_minute, 59)
32
+ end
49
33
 
50
- if @options[:use_hidden] || @options[:discard_minute]
51
- build_hidden(:minute, val)
52
- else
53
- minute_options = []
54
- start_minute.upto(end_minute) do |minute|
55
- if minute%minute_interval == 0
56
- ampm = minute < 720 ? ' AM' : ' PM'
57
- hour = minute/60
58
- minute_padded = zero_pad_num(minute%60)
59
- hour_padded = zero_pad_num(hour)
60
- ampm_hour = ampm_hour(hour)
61
-
62
- val = "#{hour_padded}:#{minute_padded}:00"
63
-
64
- option_text = @options[:ampm] ? "#{ampm_hour}:#{minute_padded}#{ampm}" : "#{hour_padded}:#{minute_padded}"
65
- minute_options << ((val_minutes == minute) ?
66
- %(<option value="#{val}" selected="selected">#{option_text}</option>\n) :
67
- %(<option value="#{val}">#{option_text}</option>\n)
68
- )
69
- end
34
+ if @options[:use_hidden] || @options[:discard_minute]
35
+ build_hidden(:minute, val)
36
+ else
37
+ minute_options = []
38
+ start_minute.upto(end_minute) do |minute|
39
+ if minute%minute_interval == 0
40
+ ampm = minute < 720 ? ' AM' : ' PM'
41
+ hour = minute/60
42
+ minute_padded = zero_pad_num(minute%60)
43
+ hour_padded = zero_pad_num(hour)
44
+ ampm_hour = ampm_hour(hour)
45
+
46
+ val = "#{hour_padded}:#{minute_padded}:00"
47
+
48
+ option_text = @options[:ampm] ? "#{ampm_hour}:#{minute_padded}#{ampm}" : "#{hour_padded}:#{minute_padded}"
49
+ minute_options << ((val_minutes == minute) ?
50
+ %(<option value="#{val}" selected="selected">#{option_text}</option>\n) :
51
+ %(<option value="#{val}">#{option_text}</option>\n)
52
+ )
70
53
  end
71
- build_select(:minute, minute_options.join(' '))
72
54
  end
55
+ build_select(:minute, minute_options.join(' '))
73
56
  end
74
- alias_method_chain :select_minute, :simple_time_select
57
+ end
75
58
 
59
+ def select_hour
60
+ return super unless @options[:combined].eql? true
61
+ # Don't build the hour select
62
+ #build_hidden(:hour, val)
63
+ end
76
64
 
77
- def select_hour_with_simple_time_select
78
- return select_hour_without_simple_time_select unless @options[:combined].eql? true
79
- # Don't build the hour select
80
- #build_hidden(:hour, val)
81
- end
82
- alias_method_chain :select_hour, :simple_time_select
65
+ def select_second
66
+ return super unless @options[:combined].eql? true
67
+ # Don't build the seconds select
68
+ #build_hidden(:second, val)
69
+ end
83
70
 
84
- def select_second_with_simple_time_select
85
- return select_second_without_simple_time_select unless @options[:combined].eql? true
86
- # Don't build the seconds select
87
- #build_hidden(:second, val)
88
- end
89
- alias_method_chain :select_second, :simple_time_select
71
+ def select_year
72
+ return super unless @options[:combined].eql? true
73
+ # Don't build the year select
74
+ #build_hidden(:year, val)
75
+ end
90
76
 
91
- def select_year_with_simple_time_select
92
- return select_year_without_simple_time_select unless @options[:combined].eql? true
93
- # Don't build the year select
94
- #build_hidden(:year, val)
95
- end
96
- alias_method_chain :select_year, :simple_time_select
77
+ def select_month
78
+ return super unless @options[:combined].eql? true
79
+ # Don't build the month select
80
+ #build_hidden(:month, val)
81
+ end
97
82
 
98
- def select_month_with_simple_time_select
99
- return select_month_without_simple_time_select unless @options[:combined].eql? true
100
- # Don't build the month select
101
- #build_hidden(:month, val)
102
- end
103
- alias_method_chain :select_month, :simple_time_select
83
+ def select_day
84
+ return super unless @options[:combined].eql? true
85
+ # Don't build the day select
86
+ #build_hidden(:day, val)
87
+ end
88
+ end
89
+ end
104
90
 
105
- def select_day_with_simple_time_select
106
- return select_day_without_simple_time_select unless @options[:combined].eql? true
107
- # Don't build the day select
108
- #build_hidden(:day, val)
109
- end
110
- alias_method_chain :select_day, :simple_time_select
91
+ ActionView::Helpers::DateTimeSelector.send(:prepend, CombinedTimeSelect::DateTimeSelectorWithSimpleTimeSelect)
111
92
 
93
+ module ActionController
94
+ class Parameters
95
+ def parse_time_select!(attribute)
96
+ self[attribute] = Time.zone.parse("#{self["#{attribute}(1i)"]}-#{self["#{attribute}(2i)"]}-#{self["#{attribute}(3i)"]} #{self["#{attribute}(5i)"]}")
97
+ (1..5).each { |i| self.delete "#{attribute}(#{i}i)" }
98
+ self
99
+ end
112
100
  end
113
101
  end
114
102
 
@@ -1,3 +1,3 @@
1
1
  module CombinedTimeSelect
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combined_time_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-22 00:00:00.000000000 Z
11
+ date: 2017-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 5.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 5.0.0
27
41
  description: Generates a time_select field like Google calendar.
28
42
  email:
29
43
  - excid3@gmail.com
@@ -31,7 +45,7 @@ executables: []
31
45
  extensions: []
32
46
  extra_rdoc_files: []
33
47
  files:
34
- - .gitignore
48
+ - ".gitignore"
35
49
  - CHANGELOG.md
36
50
  - Gemfile
37
51
  - LICENSE
@@ -49,17 +63,17 @@ require_paths:
49
63
  - lib
50
64
  required_ruby_version: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  required_rubygems_version: !ruby/object:Gem::Requirement
56
70
  requirements:
57
- - - '>='
71
+ - - ">="
58
72
  - !ruby/object:Gem::Version
59
73
  version: '0'
60
74
  requirements: []
61
75
  rubyforge_project: combined_time_select
62
- rubygems_version: 2.0.3
76
+ rubygems_version: 2.6.11
63
77
  signing_key:
64
78
  specification_version: 4
65
79
  summary: A Rails time_select like Google Calendar with combined hour and minute time_select