dotiw 4.0.1 → 5.3.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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +45 -0
- data/.rspec +2 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +42 -6
- data/Gemfile +2 -0
- data/MIT-LICENSE +1 -1
- data/README.markdown +151 -63
- data/Rakefile +3 -1
- data/benchmarks/time_hash_bench.rb +19 -0
- data/dotiw.gemspec +17 -19
- data/gemfiles/rails_4.gemfile +5 -3
- data/gemfiles/rails_5.0.gemfile +5 -3
- data/gemfiles/rails_5.1.gemfile +5 -3
- data/gemfiles/rails_5.2.gemfile +9 -0
- data/gemfiles/rails_6.0.gemfile +9 -0
- data/lib/dotiw.rb +33 -14
- data/lib/dotiw/action_view/helpers/date_helper.rb +32 -0
- data/lib/dotiw/locale/ar.yml +84 -26
- data/lib/dotiw/locale/da.yml +35 -0
- data/lib/dotiw/locale/de.yml +36 -1
- data/lib/dotiw/locale/en.yml +35 -0
- data/lib/dotiw/locale/es.yml +36 -1
- data/lib/dotiw/locale/fr.yml +35 -0
- data/lib/dotiw/locale/id.yml +35 -0
- data/lib/dotiw/locale/it.yml +35 -0
- data/lib/dotiw/locale/ja.yml +35 -0
- data/lib/dotiw/locale/ko.yml +23 -0
- data/lib/dotiw/locale/nb.yml +36 -1
- data/lib/dotiw/locale/nl.yml +35 -0
- data/lib/dotiw/locale/pl.yml +42 -0
- data/lib/dotiw/locale/pt-BR.yml +35 -0
- data/lib/dotiw/locale/ru.yml +37 -0
- data/lib/dotiw/locale/sv.yml +48 -0
- data/lib/dotiw/locale/vi.yml +48 -0
- data/lib/dotiw/locale/zh-CN.yml +23 -0
- data/lib/dotiw/locale/zh-TW.yml +60 -0
- data/lib/dotiw/methods.rb +108 -0
- data/lib/dotiw/time_hash.rb +52 -40
- data/lib/dotiw/version.rb +2 -2
- data/spec/lib/dotiw_spec.rb +304 -159
- data/spec/lib/i18n/ar.yml +2 -0
- data/spec/lib/i18n/da.yml +2 -0
- data/spec/lib/i18n/de.yml +2 -0
- data/spec/lib/i18n/en.yml +2 -0
- data/spec/lib/i18n/es.yml +3 -0
- data/spec/lib/i18n/fr.yml +2 -0
- data/spec/lib/i18n/id.yml +2 -0
- data/spec/lib/i18n/it.yml +3 -0
- data/spec/lib/i18n/ja.yml +2 -0
- data/spec/lib/i18n/ko.yml +2 -0
- data/spec/lib/i18n/nb.yml +2 -0
- data/spec/lib/i18n/nl.yml +2 -0
- data/spec/lib/i18n/pl.yml +2 -0
- data/spec/lib/i18n/pt-BR.yml +2 -0
- data/spec/lib/i18n/ru.yml +5 -0
- data/spec/lib/i18n/sv.yml +2 -0
- data/spec/lib/i18n/vi.yml +22 -0
- data/spec/lib/i18n/zh-CN.yml +2 -0
- data/spec/lib/i18n/zh-TW.yml +2 -0
- data/spec/spec_helper.rb +2 -9
- metadata +76 -30
- data/.travis.yml +0 -27
- data/lib/dotiw/action_view_ext/helpers/date_helper.rb +0 -103
@@ -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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
ROOT_PATH = File.join(File.dirname(__FILE__), '..')
|
4
|
-
|
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
|
+
version: 5.3.1
|
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:
|
12
|
+
date: 2021-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
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: '
|
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:
|
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:
|
71
|
+
name: pry
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
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: '
|
83
|
+
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
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:
|
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:
|
113
|
+
name: tzinfo
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "
|
116
|
+
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
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:
|
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,26 @@ executables: []
|
|
136
136
|
extensions: []
|
137
137
|
extra_rdoc_files: []
|
138
138
|
files:
|
139
|
+
- ".github/workflows/ruby.yml"
|
139
140
|
- ".gitignore"
|
140
|
-
- ".
|
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/
|
158
|
+
- lib/dotiw/action_view/helpers/date_helper.rb
|
154
159
|
- lib/dotiw/locale/ar.yml
|
155
160
|
- lib/dotiw/locale/da.yml
|
156
161
|
- lib/dotiw/locale/de.yml
|
@@ -166,16 +171,39 @@ files:
|
|
166
171
|
- lib/dotiw/locale/pl.yml
|
167
172
|
- lib/dotiw/locale/pt-BR.yml
|
168
173
|
- lib/dotiw/locale/ru.yml
|
174
|
+
- lib/dotiw/locale/sv.yml
|
175
|
+
- lib/dotiw/locale/vi.yml
|
169
176
|
- lib/dotiw/locale/zh-CN.yml
|
177
|
+
- lib/dotiw/locale/zh-TW.yml
|
178
|
+
- lib/dotiw/methods.rb
|
170
179
|
- lib/dotiw/time_hash.rb
|
171
180
|
- lib/dotiw/version.rb
|
172
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
|
173
201
|
- spec/spec_helper.rb
|
174
|
-
homepage: https://github.com/radar/
|
202
|
+
homepage: https://github.com/radar/distance_of_time_in_words
|
175
203
|
licenses:
|
176
204
|
- MIT
|
177
205
|
metadata: {}
|
178
|
-
post_install_message:
|
206
|
+
post_install_message:
|
179
207
|
rdoc_options: []
|
180
208
|
require_paths:
|
181
209
|
- lib
|
@@ -190,11 +218,29 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
218
|
- !ruby/object:Gem::Version
|
191
219
|
version: '0'
|
192
220
|
requirements: []
|
193
|
-
|
194
|
-
|
195
|
-
signing_key:
|
221
|
+
rubygems_version: 3.1.3
|
222
|
+
signing_key:
|
196
223
|
specification_version: 4
|
197
224
|
summary: Better distance_of_time_in_words for Rails
|
198
225
|
test_files:
|
199
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
|
200
246
|
- spec/spec_helper.rb
|
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
|