time_segment 0.0.1

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.
Files changed (43) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +35 -0
  4. data/lib/tasks/time_segment_tasks.rake +4 -0
  5. data/lib/time_segment/core_ext.rb +12 -0
  6. data/lib/time_segment/version.rb +3 -0
  7. data/lib/time_segment.rb +88 -0
  8. data/test/dummy/README.rdoc +261 -0
  9. data/test/dummy/Rakefile +7 -0
  10. data/test/dummy/app/assets/javascripts/application.js +15 -0
  11. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  12. data/test/dummy/app/controllers/application_controller.rb +3 -0
  13. data/test/dummy/app/helpers/application_helper.rb +2 -0
  14. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  15. data/test/dummy/config/application.rb +59 -0
  16. data/test/dummy/config/boot.rb +10 -0
  17. data/test/dummy/config/database.yml +25 -0
  18. data/test/dummy/config/environment.rb +5 -0
  19. data/test/dummy/config/environments/development.rb +37 -0
  20. data/test/dummy/config/environments/production.rb +67 -0
  21. data/test/dummy/config/environments/test.rb +37 -0
  22. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  23. data/test/dummy/config/initializers/inflections.rb +15 -0
  24. data/test/dummy/config/initializers/mime_types.rb +5 -0
  25. data/test/dummy/config/initializers/secret_token.rb +7 -0
  26. data/test/dummy/config/initializers/session_store.rb +8 -0
  27. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  28. data/test/dummy/config/locales/en.yml +205 -0
  29. data/test/dummy/config/routes.rb +58 -0
  30. data/test/dummy/config.ru +4 -0
  31. data/test/dummy/db/test.sqlite3 +0 -0
  32. data/test/dummy/log/test.log +3 -0
  33. data/test/dummy/public/404.html +26 -0
  34. data/test/dummy/public/422.html +26 -0
  35. data/test/dummy/public/500.html +25 -0
  36. data/test/dummy/public/favicon.ico +0 -0
  37. data/test/dummy/script/rails +6 -0
  38. data/test/en.yml +205 -0
  39. data/test/test_helper.rb +15 -0
  40. data/test/time_segment_round_test.rb +48 -0
  41. data/test/time_segment_test.rb +53 -0
  42. data/test/time_test.rb +15 -0
  43. metadata +171 -0
data/test/en.yml ADDED
@@ -0,0 +1,205 @@
1
+ en:
2
+ date:
3
+ abbr_day_names:
4
+ - Sun
5
+ - Mon
6
+ - Tue
7
+ - Wed
8
+ - Thu
9
+ - Fri
10
+ - Sat
11
+ abbr_month_names:
12
+ -
13
+ - Jan
14
+ - Feb
15
+ - Mar
16
+ - Apr
17
+ - May
18
+ - Jun
19
+ - Jul
20
+ - Aug
21
+ - Sep
22
+ - Oct
23
+ - Nov
24
+ - Dec
25
+ day_names:
26
+ - Sunday
27
+ - Monday
28
+ - Tuesday
29
+ - Wednesday
30
+ - Thursday
31
+ - Friday
32
+ - Saturday
33
+ formats:
34
+ default: ! '%Y-%m-%d'
35
+ long: ! '%B %d, %Y'
36
+ short: ! '%b %d'
37
+ month_names:
38
+ -
39
+ - January
40
+ - February
41
+ - March
42
+ - April
43
+ - May
44
+ - June
45
+ - July
46
+ - August
47
+ - September
48
+ - October
49
+ - November
50
+ - December
51
+ order:
52
+ - :year
53
+ - :month
54
+ - :day
55
+ datetime:
56
+ distance_in_words:
57
+ about_x_hours:
58
+ one: about 1 hour
59
+ other: about %{count} hours
60
+ about_x_months:
61
+ one: about 1 month
62
+ other: about %{count} months
63
+ about_x_years:
64
+ one: about 1 year
65
+ other: about %{count} years
66
+ almost_x_years:
67
+ one: almost 1 year
68
+ other: almost %{count} years
69
+ half_a_minute: half a minute
70
+ less_than_x_minutes:
71
+ one: less than a minute
72
+ other: less than %{count} minutes
73
+ less_than_x_seconds:
74
+ one: less than 1 second
75
+ other: less than %{count} seconds
76
+ over_x_years:
77
+ one: over 1 year
78
+ other: over %{count} years
79
+ x_days:
80
+ one: 1 day
81
+ other: ! '%{count} days'
82
+ x_minutes:
83
+ one: 1 minute
84
+ other: ! '%{count} minutes'
85
+ x_months:
86
+ one: 1 month
87
+ other: ! '%{count} months'
88
+ x_seconds:
89
+ one: 1 second
90
+ other: ! '%{count} seconds'
91
+ prompts:
92
+ day: Day
93
+ hour: Hour
94
+ minute: Minute
95
+ month: Month
96
+ second: Seconds
97
+ year: Year
98
+ errors: &errors
99
+ format: ! '%{attribute} %{message}'
100
+ messages:
101
+ accepted: must be accepted
102
+ blank: can't be blank
103
+ confirmation: doesn't match confirmation
104
+ empty: can't be empty
105
+ equal_to: must be equal to %{count}
106
+ even: must be even
107
+ exclusion: is reserved
108
+ greater_than: must be greater than %{count}
109
+ greater_than_or_equal_to: must be greater than or equal to %{count}
110
+ inclusion: is not included in the list
111
+ invalid: is invalid
112
+ less_than: must be less than %{count}
113
+ less_than_or_equal_to: must be less than or equal to %{count}
114
+ not_a_number: is not a number
115
+ not_an_integer: must be an integer
116
+ odd: must be odd
117
+ record_invalid: ! 'Validation failed: %{errors}'
118
+ taken: has already been taken
119
+ too_long:
120
+ one: is too long (maximum is 1 character)
121
+ other: is too long (maximum is %{count} characters)
122
+ too_short:
123
+ one: is too short (minimum is 1 character)
124
+ other: is too short (minimum is %{count} characters)
125
+ wrong_length:
126
+ one: is the wrong length (should be 1 character)
127
+ other: is the wrong length (should be %{count} characters)
128
+ template:
129
+ body: ! 'There were problems with the following fields:'
130
+ header:
131
+ one: 1 error prohibited this %{model} from being saved
132
+ other: ! '%{count} errors prohibited this %{model} from being saved'
133
+ helpers:
134
+ select:
135
+ prompt: Please select
136
+ submit:
137
+ create: Create %{model}
138
+ submit: Save %{model}
139
+ update: Update %{model}
140
+ number:
141
+ currency:
142
+ format:
143
+ delimiter: ! ','
144
+ format: ! '%u%n'
145
+ precision: 2
146
+ separator: .
147
+ significant: false
148
+ strip_insignificant_zeros: false
149
+ unit: $
150
+ format:
151
+ delimiter: ! ','
152
+ precision: 3
153
+ separator: .
154
+ significant: false
155
+ strip_insignificant_zeros: false
156
+ human:
157
+ decimal_units:
158
+ format: ! '%n %u'
159
+ units:
160
+ billion: Billion
161
+ million: Million
162
+ quadrillion: Quadrillion
163
+ thousand: Thousand
164
+ trillion: Trillion
165
+ unit: ''
166
+ format:
167
+ delimiter: ''
168
+ precision: 3
169
+ significant: true
170
+ strip_insignificant_zeros: true
171
+ storage_units:
172
+ format: ! '%n %u'
173
+ units:
174
+ byte:
175
+ one: Byte
176
+ other: Bytes
177
+ gb: GB
178
+ kb: KB
179
+ mb: MB
180
+ tb: TB
181
+ percentage:
182
+ format:
183
+ delimiter: ''
184
+ precision:
185
+ format:
186
+ delimiter: ''
187
+ support:
188
+ array:
189
+ last_word_connector: ! ', and '
190
+ two_words_connector: ! ' and '
191
+ words_connector: ! ', '
192
+ time:
193
+ am: am
194
+ formats:
195
+ default: ! '%a, %d %b %Y %H:%M:%S %z'
196
+ long: ! '%B %d, %Y %H:%M'
197
+ short: ! '%d %b %H:%M'
198
+ pm: pm
199
+ # remove these aliases after 'activemodel' and 'activerecord' namespaces are removed from Rails repository
200
+ activemodel:
201
+ errors:
202
+ <<: *errors
203
+ activerecord:
204
+ errors:
205
+ <<: *errors
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
@@ -0,0 +1,48 @@
1
+ require 'test/unit'
2
+ require 'time_segment'
3
+
4
+ I18n.load_path += ['./test/en.yml']
5
+ class TimeSegmentRoundTest < Test::Unit::TestCase
6
+ def test_round_years
7
+ from = Time.new(2012,10,7,14,31,12)
8
+ to = Time.new(2014,2,10,17,01,06)
9
+ ts = from.time_segment_to(to)
10
+ assert_equal("over 1 year", ts.round(:locale => "en"))
11
+ end
12
+
13
+ def test_round_months
14
+ ts = TimeSegment.new(Time.new(2013,12,12,12,12,12),Time.new(2014,3,12,12,12,12))
15
+ #remember that: 1 month = 30.436875 days and Februay has only 28 days. so here is only 2 months
16
+ assert_equal("2 months", ts.round)
17
+ ts = TimeSegment.new(Time.new(2013,12,12,12,12,12),Time.new(2014,2,10,12,12,12))
18
+ assert_equal("1 month", ts.round)
19
+ end
20
+
21
+ def test_round_days
22
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,14,12,12,12))
23
+ assert_equal("2 days", ts.round)
24
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,13,12,12,12))
25
+ assert_equal("1 day", ts.round)
26
+ end
27
+
28
+ def test_round_hours
29
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,12,14,12,12))
30
+ assert_equal("about 2 hours", ts.round)
31
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,12,13,12,12))
32
+ assert_equal("about 1 hour", ts.round)
33
+ end
34
+
35
+ def test_round_minutes
36
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,12,12,14,12))
37
+ assert_equal("2 minutes", ts.round)
38
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,12,12,13,12))
39
+ assert_equal("1 minute", ts.round)
40
+ end
41
+
42
+ def test_round_seconds
43
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,12,12,12,14))
44
+ assert_equal("2 seconds", ts.round)
45
+ ts = TimeSegment.new(Time.new(2014,12,12,12,12,12),Time.new(2014,12,12,12,12,13))
46
+ assert_equal("1 second", ts.round)
47
+ end
48
+ end
@@ -0,0 +1,53 @@
1
+ require 'test/unit'
2
+ require 'time_segment'
3
+
4
+ class TimeSegmentTest < Test::Unit::TestCase
5
+ def setup
6
+ @from = Time.new(2012,10,7,14,31,12)
7
+ @to = Time.new(2014,2,10,17,01,06)
8
+
9
+ @in_seconds = (@to - @from).round.to_i
10
+
11
+ @ts = TimeSegment.new(@from,@to)
12
+ end
13
+
14
+ def test_in_years
15
+ assert_equal(1,@ts.in_years)
16
+ end
17
+
18
+ def test_in_months
19
+ assert_equal(16, @ts.in_months)
20
+ end
21
+
22
+ def test_in_days
23
+ days = @in_seconds/86400
24
+ assert_equal(days, @ts.in_days)
25
+ end
26
+
27
+ def test_in_hours
28
+ hours = @in_seconds/3600
29
+ assert_equal(hours, @ts.in_hours)
30
+ end
31
+
32
+ def test_in_minutes
33
+ minutes = @in_seconds/60
34
+ assert_equal(minutes, @ts.in_minutes)
35
+ end
36
+
37
+ def test_in_seconds
38
+ assert_equal(@in_seconds, @ts.in_seconds)
39
+ end
40
+
41
+ def test_months_days_hours_minutes
42
+ _,remainder = @in_seconds.divmod TimeSegment::YEAR_IN_SEC
43
+ months, remainder = remainder.divmod TimeSegment::MONTH_IN_SEC
44
+ days, remainder = remainder.divmod TimeSegment::DAY_IN_SEC
45
+ hours, remainder = remainder.divmod 3600
46
+ minutes, remainder = remainder.divmod 60
47
+
48
+ assert_equal(months, @ts.months)
49
+ assert_equal(days, @ts.days)
50
+ assert_equal(hours, @ts.hours)
51
+ assert_equal(minutes, @ts.minutes)
52
+ end
53
+ end
data/test/time_test.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require 'time_segment'
3
+ require 'time_segment/core_ext'
4
+
5
+ class TestTime < Test::Unit::TestCase
6
+ def test_time_segment_to_now
7
+ t = Time.now
8
+ assert_equal true, t.respond_to?(:time_segment_to_now)
9
+ end
10
+
11
+ def test_time_segment_to
12
+ t = Time.now
13
+ assert_equal true, t.respond_to?(:time_segment_to)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_segment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - CrazyJin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rails-i18n
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Class TimeSegment allows you to handle time segment easy.
63
+ email:
64
+ - eccentricjinp@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/time_segment.rb
70
+ - lib/time_segment/core_ext.rb
71
+ - lib/time_segment/version.rb
72
+ - lib/tasks/time_segment_tasks.rake
73
+ - MIT-LICENSE
74
+ - Rakefile
75
+ - README.rdoc
76
+ - test/dummy/config.ru
77
+ - test/dummy/public/422.html
78
+ - test/dummy/public/500.html
79
+ - test/dummy/public/favicon.ico
80
+ - test/dummy/public/404.html
81
+ - test/dummy/Rakefile
82
+ - test/dummy/README.rdoc
83
+ - test/dummy/log/test.log
84
+ - test/dummy/config/application.rb
85
+ - test/dummy/config/routes.rb
86
+ - test/dummy/config/locales/en.yml
87
+ - test/dummy/config/environment.rb
88
+ - test/dummy/config/initializers/wrap_parameters.rb
89
+ - test/dummy/config/initializers/backtrace_silencers.rb
90
+ - test/dummy/config/initializers/secret_token.rb
91
+ - test/dummy/config/initializers/inflections.rb
92
+ - test/dummy/config/initializers/mime_types.rb
93
+ - test/dummy/config/initializers/session_store.rb
94
+ - test/dummy/config/environments/production.rb
95
+ - test/dummy/config/environments/test.rb
96
+ - test/dummy/config/environments/development.rb
97
+ - test/dummy/config/database.yml
98
+ - test/dummy/config/boot.rb
99
+ - test/dummy/script/rails
100
+ - test/dummy/app/controllers/application_controller.rb
101
+ - test/dummy/app/views/layouts/application.html.erb
102
+ - test/dummy/app/assets/javascripts/application.js
103
+ - test/dummy/app/assets/stylesheets/application.css
104
+ - test/dummy/app/helpers/application_helper.rb
105
+ - test/dummy/db/test.sqlite3
106
+ - test/time_segment_round_test.rb
107
+ - test/time_segment_test.rb
108
+ - test/test_helper.rb
109
+ - test/en.yml
110
+ - test/time_test.rb
111
+ homepage: ''
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 1.8.24
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: TimeSegment.
135
+ test_files:
136
+ - test/dummy/config.ru
137
+ - test/dummy/public/422.html
138
+ - test/dummy/public/500.html
139
+ - test/dummy/public/favicon.ico
140
+ - test/dummy/public/404.html
141
+ - test/dummy/Rakefile
142
+ - test/dummy/README.rdoc
143
+ - test/dummy/log/test.log
144
+ - test/dummy/config/application.rb
145
+ - test/dummy/config/routes.rb
146
+ - test/dummy/config/locales/en.yml
147
+ - test/dummy/config/environment.rb
148
+ - test/dummy/config/initializers/wrap_parameters.rb
149
+ - test/dummy/config/initializers/backtrace_silencers.rb
150
+ - test/dummy/config/initializers/secret_token.rb
151
+ - test/dummy/config/initializers/inflections.rb
152
+ - test/dummy/config/initializers/mime_types.rb
153
+ - test/dummy/config/initializers/session_store.rb
154
+ - test/dummy/config/environments/production.rb
155
+ - test/dummy/config/environments/test.rb
156
+ - test/dummy/config/environments/development.rb
157
+ - test/dummy/config/database.yml
158
+ - test/dummy/config/boot.rb
159
+ - test/dummy/script/rails
160
+ - test/dummy/app/controllers/application_controller.rb
161
+ - test/dummy/app/views/layouts/application.html.erb
162
+ - test/dummy/app/assets/javascripts/application.js
163
+ - test/dummy/app/assets/stylesheets/application.css
164
+ - test/dummy/app/helpers/application_helper.rb
165
+ - test/dummy/db/test.sqlite3
166
+ - test/time_segment_round_test.rb
167
+ - test/time_segment_test.rb
168
+ - test/test_helper.rb
169
+ - test/en.yml
170
+ - test/time_test.rb
171
+ has_rdoc: