dotiw 4.0.0 → 5.3.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.
Files changed (64) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +45 -0
  3. data/.rspec +2 -0
  4. data/Appraisals +19 -0
  5. data/CHANGELOG.md +38 -6
  6. data/Gemfile +2 -0
  7. data/MIT-LICENSE +1 -1
  8. data/README.markdown +151 -63
  9. data/Rakefile +3 -1
  10. data/benchmarks/time_hash_bench.rb +19 -0
  11. data/dotiw.gemspec +17 -19
  12. data/gemfiles/rails_4.gemfile +5 -3
  13. data/gemfiles/rails_5.0.gemfile +5 -3
  14. data/gemfiles/rails_5.1.gemfile +5 -3
  15. data/gemfiles/rails_5.2.gemfile +9 -0
  16. data/gemfiles/rails_6.0.gemfile +9 -0
  17. data/lib/dotiw.rb +33 -14
  18. data/lib/dotiw/action_view/helpers/date_helper.rb +32 -0
  19. data/lib/dotiw/locale/ar.yml +104 -0
  20. data/lib/dotiw/locale/da.yml +35 -0
  21. data/lib/dotiw/locale/de.yml +36 -1
  22. data/lib/dotiw/locale/en.yml +35 -0
  23. data/lib/dotiw/locale/es.yml +36 -1
  24. data/lib/dotiw/locale/fr.yml +35 -0
  25. data/lib/dotiw/locale/id.yml +35 -0
  26. data/lib/dotiw/locale/it.yml +35 -0
  27. data/lib/dotiw/locale/ja.yml +35 -0
  28. data/lib/dotiw/locale/ko.yml +48 -0
  29. data/lib/dotiw/locale/nb.yml +36 -1
  30. data/lib/dotiw/locale/nl.yml +35 -0
  31. data/lib/dotiw/locale/pl.yml +42 -0
  32. data/lib/dotiw/locale/pt-BR.yml +35 -0
  33. data/lib/dotiw/locale/ru.yml +37 -0
  34. data/lib/dotiw/locale/sv.yml +48 -0
  35. data/lib/dotiw/locale/vi.yml +48 -0
  36. data/lib/dotiw/locale/zh-CN.yml +48 -0
  37. data/lib/dotiw/locale/zh-TW.yml +60 -0
  38. data/lib/dotiw/methods.rb +108 -0
  39. data/lib/dotiw/time_hash.rb +52 -40
  40. data/lib/dotiw/version.rb +2 -2
  41. data/spec/lib/dotiw_spec.rb +303 -159
  42. data/spec/lib/i18n/ar.yml +2 -0
  43. data/spec/lib/i18n/da.yml +2 -0
  44. data/spec/lib/i18n/de.yml +2 -0
  45. data/spec/lib/i18n/en.yml +2 -0
  46. data/spec/lib/i18n/es.yml +3 -0
  47. data/spec/lib/i18n/fr.yml +2 -0
  48. data/spec/lib/i18n/id.yml +2 -0
  49. data/spec/lib/i18n/it.yml +3 -0
  50. data/spec/lib/i18n/ja.yml +2 -0
  51. data/spec/lib/i18n/ko.yml +2 -0
  52. data/spec/lib/i18n/nb.yml +2 -0
  53. data/spec/lib/i18n/nl.yml +2 -0
  54. data/spec/lib/i18n/pl.yml +2 -0
  55. data/spec/lib/i18n/pt-BR.yml +2 -0
  56. data/spec/lib/i18n/ru.yml +5 -0
  57. data/spec/lib/i18n/sv.yml +2 -0
  58. data/spec/lib/i18n/vi.yml +22 -0
  59. data/spec/lib/i18n/zh-CN.yml +2 -0
  60. data/spec/lib/i18n/zh-TW.yml +2 -0
  61. data/spec/spec_helper.rb +2 -9
  62. metadata +79 -31
  63. data/.travis.yml +0 -27
  64. data/lib/dotiw/action_view_ext/helpers/date_helper.rb +0 -103
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: ثانية واحدة
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 sekund
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 Sekunde
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 second
@@ -0,0 +1,3 @@
1
+ days:
2
+ 1.day: un día
3
+ 5.days: 5 días
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 seconde
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 detik
@@ -0,0 +1,3 @@
1
+ days:
2
+ 1.day: un giorno
3
+ 5.days: 5 giorni
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1秒
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 일 초
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 sekund
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 seconde
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 sekunda
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 segundo
@@ -0,0 +1,5 @@
1
+ seconds:
2
+ 0.5.seconds: меньше, чем 1 секунда
3
+ 1.second: 1 секунда
4
+ minutes:
5
+ 1.minute: 1 минута
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 sekund
@@ -0,0 +1,22 @@
1
+ seconds:
2
+ 0.5.second: ít hơn 1 giây
3
+ 1.second: 1 giây
4
+ 3.seconds: 3 giây
5
+ minutes:
6
+ 1.minute: 1 phút
7
+ 10.minutes: 10 phút
8
+ hours:
9
+ 1.hour: 1 giờ
10
+ 2.hours: 2 giờ
11
+ days:
12
+ 1.day: 1 ngày
13
+ 2.days: 2 ngày
14
+ weeks:
15
+ 1.week: 1 tuần
16
+ 2.weeks: 2 tuần
17
+ months:
18
+ 1.month: 1 tháng
19
+ 2.months: 2 tháng
20
+ years:
21
+ 1.year: 1 năm
22
+ 2.years: 2 năm
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 秒
@@ -0,0 +1,2 @@
1
+ seconds:
2
+ 1.second: 1 秒
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,10 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  ROOT_PATH = File.join(File.dirname(__FILE__), '..')
4
- $:.unshift ROOT_PATH unless $:.include? ROOT_PATH
5
-
6
- # Files that are usually required by Rails, but in a testing context will not be.
7
- require 'erb'
8
-
9
- require 'active_support/all'
10
- require 'action_view'
4
+ $LOAD_PATH.unshift ROOT_PATH unless $LOAD_PATH.include? ROOT_PATH
11
5
 
12
6
  require 'dotiw'
13
7
 
14
8
  Time.zone = 'UTC'
15
9
 
16
- I18n.load_path << Dir[File.join(File.dirname(__FILE__), 'translations', '*')]
17
10
  I18n.locale = :en
metadata CHANGED
@@ -1,30 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotiw
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  - Lauran Jansen
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-08 00:00:00.000000000 Z
12
+ date: 2021-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: actionpack
15
+ name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '4'
20
+ version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '4'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: i18n
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
- name: rake
43
+ name: appraisal
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
@@ -68,21 +68,21 @@ dependencies:
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
- name: rspec
71
+ name: pry
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '3.0'
76
+ version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '3.0'
83
+ version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: tzinfo
85
+ name: rake
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,33 +96,33 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: appraisal
99
+ name: rspec
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: '3.0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: '3.0'
112
112
  - !ruby/object:Gem::Dependency
113
- name: pry
113
+ name: tzinfo
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: 1.2.7
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 1.2.7
126
126
  description: |-
127
127
  dotiw is a gem for Rails that overrides the
128
128
  default distance_of_time_in_words and provides
@@ -136,21 +136,27 @@ executables: []
136
136
  extensions: []
137
137
  extra_rdoc_files: []
138
138
  files:
139
+ - ".github/workflows/ruby.yml"
139
140
  - ".gitignore"
140
- - ".travis.yml"
141
+ - ".rspec"
142
+ - Appraisals
141
143
  - CHANGELOG.md
142
144
  - CONTRIBUTING.md
143
145
  - Gemfile
144
146
  - MIT-LICENSE
145
147
  - README.markdown
146
148
  - Rakefile
149
+ - benchmarks/time_hash_bench.rb
147
150
  - dotiw.gemspec
148
151
  - gemfiles/.bundle/config
149
152
  - gemfiles/rails_4.gemfile
150
153
  - gemfiles/rails_5.0.gemfile
151
154
  - gemfiles/rails_5.1.gemfile
155
+ - gemfiles/rails_5.2.gemfile
156
+ - gemfiles/rails_6.0.gemfile
152
157
  - lib/dotiw.rb
153
- - lib/dotiw/action_view_ext/helpers/date_helper.rb
158
+ - lib/dotiw/action_view/helpers/date_helper.rb
159
+ - lib/dotiw/locale/ar.yml
154
160
  - lib/dotiw/locale/da.yml
155
161
  - lib/dotiw/locale/de.yml
156
162
  - lib/dotiw/locale/en.yml
@@ -159,20 +165,45 @@ files:
159
165
  - lib/dotiw/locale/id.yml
160
166
  - lib/dotiw/locale/it.yml
161
167
  - lib/dotiw/locale/ja.yml
168
+ - lib/dotiw/locale/ko.yml
162
169
  - lib/dotiw/locale/nb.yml
163
170
  - lib/dotiw/locale/nl.yml
164
171
  - lib/dotiw/locale/pl.yml
165
172
  - lib/dotiw/locale/pt-BR.yml
166
173
  - lib/dotiw/locale/ru.yml
174
+ - lib/dotiw/locale/sv.yml
175
+ - lib/dotiw/locale/vi.yml
176
+ - lib/dotiw/locale/zh-CN.yml
177
+ - lib/dotiw/locale/zh-TW.yml
178
+ - lib/dotiw/methods.rb
167
179
  - lib/dotiw/time_hash.rb
168
180
  - lib/dotiw/version.rb
169
181
  - spec/lib/dotiw_spec.rb
182
+ - spec/lib/i18n/ar.yml
183
+ - spec/lib/i18n/da.yml
184
+ - spec/lib/i18n/de.yml
185
+ - spec/lib/i18n/en.yml
186
+ - spec/lib/i18n/es.yml
187
+ - spec/lib/i18n/fr.yml
188
+ - spec/lib/i18n/id.yml
189
+ - spec/lib/i18n/it.yml
190
+ - spec/lib/i18n/ja.yml
191
+ - spec/lib/i18n/ko.yml
192
+ - spec/lib/i18n/nb.yml
193
+ - spec/lib/i18n/nl.yml
194
+ - spec/lib/i18n/pl.yml
195
+ - spec/lib/i18n/pt-BR.yml
196
+ - spec/lib/i18n/ru.yml
197
+ - spec/lib/i18n/sv.yml
198
+ - spec/lib/i18n/vi.yml
199
+ - spec/lib/i18n/zh-CN.yml
200
+ - spec/lib/i18n/zh-TW.yml
170
201
  - spec/spec_helper.rb
171
- homepage: https://github.com/radar/dotiw
202
+ homepage: https://github.com/radar/distance_of_time_in_words
172
203
  licenses:
173
204
  - MIT
174
205
  metadata: {}
175
- post_install_message:
206
+ post_install_message:
176
207
  rdoc_options: []
177
208
  require_paths:
178
209
  - lib
@@ -187,12 +218,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
218
  - !ruby/object:Gem::Version
188
219
  version: '0'
189
220
  requirements: []
190
- rubyforge_project:
191
- rubygems_version: 2.5.2
192
- signing_key:
221
+ rubygems_version: 3.1.3
222
+ signing_key:
193
223
  specification_version: 4
194
224
  summary: Better distance_of_time_in_words for Rails
195
225
  test_files:
196
226
  - spec/lib/dotiw_spec.rb
227
+ - spec/lib/i18n/ar.yml
228
+ - spec/lib/i18n/da.yml
229
+ - spec/lib/i18n/de.yml
230
+ - spec/lib/i18n/en.yml
231
+ - spec/lib/i18n/es.yml
232
+ - spec/lib/i18n/fr.yml
233
+ - spec/lib/i18n/id.yml
234
+ - spec/lib/i18n/it.yml
235
+ - spec/lib/i18n/ja.yml
236
+ - spec/lib/i18n/ko.yml
237
+ - spec/lib/i18n/nb.yml
238
+ - spec/lib/i18n/nl.yml
239
+ - spec/lib/i18n/pl.yml
240
+ - spec/lib/i18n/pt-BR.yml
241
+ - spec/lib/i18n/ru.yml
242
+ - spec/lib/i18n/sv.yml
243
+ - spec/lib/i18n/vi.yml
244
+ - spec/lib/i18n/zh-CN.yml
245
+ - spec/lib/i18n/zh-TW.yml
197
246
  - spec/spec_helper.rb
198
- has_rdoc:
data/.travis.yml DELETED
@@ -1,27 +0,0 @@
1
- rvm:
2
- - 2.4.0
3
- - 2.3.0
4
- - 2.2.4
5
- - 2.1.8
6
- - 2.0.0
7
- - jruby-19mode
8
- gemfile:
9
- - gemfiles/rails_4.gemfile
10
- - gemfiles/rails_5.0.gemfile
11
- - gemfiles/rails_5.1.gemfile
12
- before_install:
13
- - gem update --system
14
- - gem update bundler
15
- install: "bundle install"
16
-
17
- matrix:
18
- exclude:
19
- # Rails 5 requires Ruby >= 2.2.2
20
- - rvm: 2.0.0
21
- gemfile: gemfiles/rails_5.0.gemfile
22
- - rvm: 2.0.0
23
- gemfile: gemfiles/rails_5.1.gemfile
24
- - rvm: 2.1.8
25
- gemfile: gemfiles/rails_5.0.gemfile
26
- - rvm: 2.1.8
27
- gemfile: gemfiles/rails_5.1.gemfile
@@ -1,103 +0,0 @@
1
- module ActionView
2
- module Helpers
3
- module DateHelper
4
- alias_method :old_distance_of_time_in_words, :distance_of_time_in_words
5
-
6
- def distance_of_time_in_words_hash(from_time, to_time, options = {})
7
- from_time = from_time.to_time if !from_time.is_a?(Time) && from_time.respond_to?(:to_time)
8
- to_time = to_time.to_time if !to_time.is_a?(Time) && to_time.respond_to?(:to_time)
9
-
10
- DOTIW::TimeHash.new(nil, from_time, to_time, options).to_hash
11
- end
12
-
13
- def distance_of_time(seconds, options = {})
14
- options[:include_seconds] ||= true
15
- display_time_in_words DOTIW::TimeHash.new(seconds, nil, nil, options).to_hash, options
16
- end
17
-
18
- def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
19
- if include_seconds_or_options.is_a?(Hash)
20
- options = include_seconds_or_options
21
- else
22
- options[:include_seconds] ||= !!include_seconds_or_options
23
- end
24
- return distance_of_time(from_time, options) if to_time == 0
25
- return old_distance_of_time_in_words(from_time, to_time, options) if options.delete(:vague)
26
- hash = distance_of_time_in_words_hash(from_time, to_time, options)
27
- display_time_in_words(hash, options)
28
- end
29
-
30
- def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
31
- options[:precision] ||= 0
32
- distance = to_time - from_time
33
- result = ((current_time - from_time) / distance) * 100
34
- number_with_precision(result, options).to_s + "%"
35
- end
36
-
37
- alias_method :old_time_ago_in_words, :time_ago_in_words
38
-
39
- def time_ago_in_words(from_time, include_seconds_or_options = {})
40
- distance_of_time_in_words(from_time, Time.current, include_seconds_or_options)
41
- end
42
-
43
- private
44
- def display_time_in_words(hash, options = {})
45
- options.reverse_merge!(
46
- :include_seconds => false
47
- ).symbolize_keys!
48
-
49
- include_seconds = options.delete(:include_seconds)
50
- hash.delete(:seconds) if !include_seconds && hash[:minutes]
51
-
52
- options[:except] = Array.wrap(options[:except]).map!(&:to_sym) if options[:except]
53
- options[:only] = Array.wrap(options[:only]).map!(&:to_sym) if options[:only]
54
-
55
- # Remove all the values that are nil or excluded. Keep the required ones.
56
- hash.delete_if do |key, value|
57
- value.nil? || value.zero? ||
58
- (options[:except] && options[:except].include?(key)) ||
59
- (options[:only] && !options[:only].include?(key))
60
- end
61
-
62
- i18n_scope = options.delete(:scope) || DOTIW::DEFAULT_I18N_SCOPE
63
- if hash.empty?
64
- fractions = DOTIW::TimeHash::TIME_FRACTIONS
65
- fractions = fractions & options[:only] if options[:only]
66
- fractions = fractions - options[:except] if options[:except]
67
-
68
- I18n.with_options :locale => options[:locale], :scope => i18n_scope do |locale|
69
- # e.g. try to format 'less than 1 days', fallback to '0 days'
70
- return locale.translate :less_than_x,
71
- :distance => locale.translate(fractions.first, :count => 1),
72
- :default => locale.translate(fractions.first, :count => 0)
73
- end
74
- end
75
-
76
- output = []
77
- I18n.with_options :locale => options[:locale], :scope => i18n_scope do |locale|
78
- output = hash.map { |key, value| locale.t(key, :count => value) }
79
- end
80
-
81
- options.delete(:except)
82
- options.delete(:only)
83
- highest_measures = options.delete(:highest_measures)
84
- highest_measures = 1 if options.delete(:highest_measure_only)
85
- if highest_measures
86
- output = output[0...highest_measures]
87
- end
88
-
89
- options[:words_connector] ||= I18n.translate :'datetime.dotiw.words_connector',
90
- :default => :'support.array.words_connector',
91
- :locale => options[:locale]
92
- options[:two_words_connector] ||= I18n.translate :'datetime.dotiw.two_words_connector',
93
- :default => :'support.array.two_words_connector',
94
- :locale => options[:locale]
95
- options[:last_word_connector] ||= I18n.translate :'datetime.dotiw.last_word_connector',
96
- :default => :'support.array.last_word_connector',
97
- :locale => options[:locale]
98
-
99
- output.to_sentence(options)
100
- end
101
- end # DateHelper
102
- end # Helpers
103
- end # ActionView