dotiw 3.0.1 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +45 -0
- data/.gitignore +2 -1
- data/.rspec +2 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +29 -0
- data/CONTRIBUTING.md +34 -0
- data/Gemfile +2 -0
- data/MIT-LICENSE +1 -1
- data/README.markdown +139 -70
- data/Rakefile +3 -1
- data/dotiw.gemspec +22 -17
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4.gemfile +9 -0
- data/gemfiles/rails_5.0.gemfile +9 -0
- data/gemfiles/rails_5.1.gemfile +9 -0
- data/gemfiles/rails_5.2.gemfile +9 -0
- data/gemfiles/rails_6.0.gemfile +9 -0
- data/lib/dotiw.rb +31 -13
- data/lib/dotiw/action_view/helpers/date_helper.rb +24 -0
- data/lib/dotiw/locale/ar.yml +53 -0
- data/lib/dotiw/locale/da.yml +23 -0
- data/lib/dotiw/locale/fr.yml +25 -0
- data/lib/dotiw/locale/id.yml +25 -0
- data/lib/dotiw/locale/ko.yml +25 -0
- data/lib/dotiw/locale/pl.yml +7 -0
- data/lib/dotiw/locale/pt-BR.yml +25 -0
- data/lib/dotiw/locale/vi.yml +25 -0
- data/lib/dotiw/locale/zh-CN.yml +25 -0
- data/lib/dotiw/methods.rb +93 -0
- data/lib/dotiw/time_hash.rb +65 -38
- data/lib/dotiw/version.rb +2 -2
- data/spec/lib/dotiw_spec.rb +264 -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/vi.yml +22 -0
- data/spec/lib/i18n/zh-CN.yml +2 -0
- data/spec/spec_helper.rb +2 -9
- metadata +110 -21
- data/.travis.yml +0 -5
- 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,29 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotiw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
|
-
|
8
|
+
- Lauran Jansen
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: activesupport
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
+
version: '0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
+
version: '0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: i18n
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +40,7 @@ dependencies:
|
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
+
name: appraisal
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - ">="
|
@@ -66,6 +67,34 @@ dependencies:
|
|
66
67
|
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: pry
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
69
98
|
- !ruby/object:Gem::Dependency
|
70
99
|
name: rspec
|
71
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,48 +113,92 @@ dependencies:
|
|
84
113
|
name: tzinfo
|
85
114
|
requirement: !ruby/object:Gem::Requirement
|
86
115
|
requirements:
|
87
|
-
- - "
|
116
|
+
- - "~>"
|
88
117
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
118
|
+
version: 1.2.7
|
90
119
|
type: :development
|
91
120
|
prerelease: false
|
92
121
|
version_requirements: !ruby/object:Gem::Requirement
|
93
122
|
requirements:
|
94
|
-
- - "
|
123
|
+
- - "~>"
|
95
124
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
description:
|
98
|
-
|
125
|
+
version: 1.2.7
|
126
|
+
description: |-
|
127
|
+
dotiw is a gem for Rails that overrides the
|
128
|
+
default distance_of_time_in_words and provides
|
129
|
+
a more accurate output. Do you crave accuracy
|
130
|
+
down to the second? So do I. That's why I made
|
131
|
+
this gem. - Ryan
|
132
|
+
email:
|
133
|
+
- radarlistener@gmail.com
|
134
|
+
- github@lauranjansen.com
|
99
135
|
executables: []
|
100
136
|
extensions: []
|
101
137
|
extra_rdoc_files: []
|
102
138
|
files:
|
139
|
+
- ".github/workflows/ruby.yml"
|
103
140
|
- ".gitignore"
|
104
|
-
- ".
|
141
|
+
- ".rspec"
|
142
|
+
- Appraisals
|
143
|
+
- CHANGELOG.md
|
144
|
+
- CONTRIBUTING.md
|
105
145
|
- Gemfile
|
106
146
|
- MIT-LICENSE
|
107
147
|
- README.markdown
|
108
148
|
- Rakefile
|
109
149
|
- dotiw.gemspec
|
150
|
+
- gemfiles/.bundle/config
|
151
|
+
- gemfiles/rails_4.gemfile
|
152
|
+
- gemfiles/rails_5.0.gemfile
|
153
|
+
- gemfiles/rails_5.1.gemfile
|
154
|
+
- gemfiles/rails_5.2.gemfile
|
155
|
+
- gemfiles/rails_6.0.gemfile
|
110
156
|
- lib/dotiw.rb
|
111
|
-
- lib/dotiw/
|
157
|
+
- lib/dotiw/action_view/helpers/date_helper.rb
|
158
|
+
- lib/dotiw/locale/ar.yml
|
159
|
+
- lib/dotiw/locale/da.yml
|
112
160
|
- lib/dotiw/locale/de.yml
|
113
161
|
- lib/dotiw/locale/en.yml
|
114
162
|
- lib/dotiw/locale/es.yml
|
163
|
+
- lib/dotiw/locale/fr.yml
|
164
|
+
- lib/dotiw/locale/id.yml
|
115
165
|
- lib/dotiw/locale/it.yml
|
116
166
|
- lib/dotiw/locale/ja.yml
|
167
|
+
- lib/dotiw/locale/ko.yml
|
117
168
|
- lib/dotiw/locale/nb.yml
|
118
169
|
- lib/dotiw/locale/nl.yml
|
119
170
|
- lib/dotiw/locale/pl.yml
|
171
|
+
- lib/dotiw/locale/pt-BR.yml
|
120
172
|
- lib/dotiw/locale/ru.yml
|
173
|
+
- lib/dotiw/locale/vi.yml
|
174
|
+
- lib/dotiw/locale/zh-CN.yml
|
175
|
+
- lib/dotiw/methods.rb
|
121
176
|
- lib/dotiw/time_hash.rb
|
122
177
|
- lib/dotiw/version.rb
|
123
178
|
- spec/lib/dotiw_spec.rb
|
179
|
+
- spec/lib/i18n/ar.yml
|
180
|
+
- spec/lib/i18n/da.yml
|
181
|
+
- spec/lib/i18n/de.yml
|
182
|
+
- spec/lib/i18n/en.yml
|
183
|
+
- spec/lib/i18n/es.yml
|
184
|
+
- spec/lib/i18n/fr.yml
|
185
|
+
- spec/lib/i18n/id.yml
|
186
|
+
- spec/lib/i18n/it.yml
|
187
|
+
- spec/lib/i18n/ja.yml
|
188
|
+
- spec/lib/i18n/ko.yml
|
189
|
+
- spec/lib/i18n/nb.yml
|
190
|
+
- spec/lib/i18n/nl.yml
|
191
|
+
- spec/lib/i18n/pl.yml
|
192
|
+
- spec/lib/i18n/pt-BR.yml
|
193
|
+
- spec/lib/i18n/ru.yml
|
194
|
+
- spec/lib/i18n/vi.yml
|
195
|
+
- spec/lib/i18n/zh-CN.yml
|
124
196
|
- spec/spec_helper.rb
|
125
|
-
homepage:
|
126
|
-
licenses:
|
197
|
+
homepage: https://github.com/radar/distance_of_time_in_words
|
198
|
+
licenses:
|
199
|
+
- MIT
|
127
200
|
metadata: {}
|
128
|
-
post_install_message:
|
201
|
+
post_install_message:
|
129
202
|
rdoc_options: []
|
130
203
|
require_paths:
|
131
204
|
- lib
|
@@ -140,11 +213,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
213
|
- !ruby/object:Gem::Version
|
141
214
|
version: '0'
|
142
215
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
signing_key:
|
216
|
+
rubygems_version: 3.1.2
|
217
|
+
signing_key:
|
146
218
|
specification_version: 4
|
147
219
|
summary: Better distance_of_time_in_words for Rails
|
148
220
|
test_files:
|
149
221
|
- spec/lib/dotiw_spec.rb
|
222
|
+
- spec/lib/i18n/ar.yml
|
223
|
+
- spec/lib/i18n/da.yml
|
224
|
+
- spec/lib/i18n/de.yml
|
225
|
+
- spec/lib/i18n/en.yml
|
226
|
+
- spec/lib/i18n/es.yml
|
227
|
+
- spec/lib/i18n/fr.yml
|
228
|
+
- spec/lib/i18n/id.yml
|
229
|
+
- spec/lib/i18n/it.yml
|
230
|
+
- spec/lib/i18n/ja.yml
|
231
|
+
- spec/lib/i18n/ko.yml
|
232
|
+
- spec/lib/i18n/nb.yml
|
233
|
+
- spec/lib/i18n/nl.yml
|
234
|
+
- spec/lib/i18n/pl.yml
|
235
|
+
- spec/lib/i18n/pt-BR.yml
|
236
|
+
- spec/lib/i18n/ru.yml
|
237
|
+
- spec/lib/i18n/vi.yml
|
238
|
+
- spec/lib/i18n/zh-CN.yml
|
150
239
|
- spec/spec_helper.rb
|
data/.travis.yml
DELETED
@@ -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.now, 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
|