dotiw 4.0.1 → 5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/Rakefile
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'benchmark/ips'
|
4
|
+
require 'benchmark/memory'
|
5
|
+
require 'active_support/core_ext/numeric'
|
6
|
+
require 'active_support/core_ext/integer'
|
7
|
+
|
8
|
+
require_relative '../lib/dotiw/time_hash'
|
9
|
+
|
10
|
+
from = Time.now
|
11
|
+
to = Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds
|
12
|
+
|
13
|
+
%i[ips memory].each do |type|
|
14
|
+
Benchmark.public_send(type) do |x|
|
15
|
+
x.report('master') { DOTIW::TimeHash.new(nil, from, to) }
|
16
|
+
|
17
|
+
x.compare!
|
18
|
+
end
|
19
|
+
end
|
data/dotiw.gemspec
CHANGED
@@ -1,37 +1,35 @@
|
|
1
|
-
#
|
2
|
-
# -*- encoding: utf-8 -*-
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
5
4
|
require 'dotiw/version'
|
6
5
|
|
7
6
|
Gem::Specification.new do |s|
|
8
7
|
s.name = 'dotiw'
|
9
8
|
s.version = DOTIW::VERSION
|
10
|
-
s.licenses = [
|
9
|
+
s.licenses = ['MIT']
|
11
10
|
|
12
|
-
s.authors = [
|
13
|
-
s.date = %q{2016-03-08}
|
11
|
+
s.authors = ['Ryan Bigg', 'Lauran Jansen']
|
14
12
|
s.description = "dotiw is a gem for Rails that overrides the
|
15
13
|
default distance_of_time_in_words and provides
|
16
14
|
a more accurate output. Do you crave accuracy
|
17
15
|
down to the second? So do I. That's why I made
|
18
16
|
this gem. - Ryan"
|
19
|
-
s.summary =
|
20
|
-
s.email = [
|
21
|
-
s.homepage =
|
17
|
+
s.summary = 'Better distance_of_time_in_words for Rails'
|
18
|
+
s.email = ['radarlistener@gmail.com', 'github@lauranjansen.com']
|
19
|
+
s.homepage = 'https://github.com/radar/distance_of_time_in_words'
|
22
20
|
|
23
|
-
s.add_dependency
|
24
|
-
s.add_dependency
|
21
|
+
s.add_dependency 'activesupport'
|
22
|
+
s.add_dependency 'i18n'
|
25
23
|
|
26
|
-
s.add_development_dependency
|
27
|
-
s.add_development_dependency
|
28
|
-
s.add_development_dependency
|
29
|
-
s.add_development_dependency
|
30
|
-
s.add_development_dependency
|
31
|
-
s.add_development_dependency
|
24
|
+
s.add_development_dependency 'appraisal'
|
25
|
+
s.add_development_dependency 'bundler'
|
26
|
+
s.add_development_dependency 'pry'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
s.add_development_dependency 'tzinfo', '~> 1.2.7'
|
32
30
|
|
33
31
|
s.files = `git ls-files`.split("\n")
|
34
32
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
35
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
36
|
-
s.require_paths = [
|
33
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
34
|
+
s.require_paths = ['lib']
|
37
35
|
end
|
data/gemfiles/rails_4.gemfile
CHANGED
data/gemfiles/rails_5.0.gemfile
CHANGED
data/gemfiles/rails_5.1.gemfile
CHANGED
data/lib/dotiw.rb
CHANGED
@@ -1,30 +1,49 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'i18n'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
require 'dotiw/action_view_ext/helpers/date_helper'
|
8
|
-
end
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/core_ext'
|
9
7
|
|
10
8
|
module DOTIW
|
9
|
+
extend ActiveSupport::Autoload
|
10
|
+
|
11
|
+
eager_autoload do
|
12
|
+
autoload :VERSION, 'dotiw/version'
|
13
|
+
autoload :TimeHash, 'dotiw/time_hash'
|
14
|
+
autoload :Methods, 'dotiw/methods'
|
15
|
+
end
|
16
|
+
|
11
17
|
extend self
|
12
|
-
|
13
|
-
autoload :VERSION, 'dotiw/version'
|
14
|
-
autoload :TimeHash, 'dotiw/time_hash'
|
15
18
|
|
16
19
|
DEFAULT_I18N_SCOPE = :'datetime.dotiw'
|
20
|
+
DEFAULT_I18N_SCOPE_COMPACT = :'datetime.dotiw_compact'
|
17
21
|
|
18
|
-
def init_i18n
|
22
|
+
def init_i18n!
|
19
23
|
I18n.load_path.unshift(*locale_files)
|
20
24
|
I18n.reload!
|
21
25
|
end
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
def languages
|
28
|
+
@languages ||= (locale_files.map { |path| path.split(%r{[/.]})[-2].to_sym })
|
29
|
+
end
|
30
|
+
|
25
31
|
def locale_files
|
26
|
-
|
32
|
+
files 'dotiw/locale', '*.yml'
|
27
33
|
end
|
28
|
-
end # DOTIW
|
29
34
|
|
30
|
-
|
35
|
+
protected
|
36
|
+
|
37
|
+
def files(directory, ext)
|
38
|
+
Dir[File.join File.dirname(__FILE__), directory, ext]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
DOTIW.init_i18n!
|
43
|
+
|
44
|
+
begin
|
45
|
+
require 'action_view'
|
46
|
+
require_relative 'dotiw/action_view/helpers/date_helper'
|
47
|
+
rescue LoadError
|
48
|
+
# TODO: don't rely on exception
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module DateHelper
|
6
|
+
alias _distance_of_time_in_words distance_of_time_in_words
|
7
|
+
alias _time_ago_in_words time_ago_in_words
|
8
|
+
|
9
|
+
include DOTIW::Methods
|
10
|
+
|
11
|
+
def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
|
12
|
+
return _distance_of_time_in_words(from_time, to_time, options) if options[:vague]
|
13
|
+
|
14
|
+
DOTIW::Methods.distance_of_time_in_words(from_time, to_time, include_seconds_or_options, options.except(:vague))
|
15
|
+
end
|
16
|
+
|
17
|
+
def distance_of_time_in_words_to_now(to_time = 0, include_seconds_or_options = {}, options = {})
|
18
|
+
return _distance_of_time_in_words(Time.now, to_time, options) if options[:vague]
|
19
|
+
|
20
|
+
DOTIW::Methods.distance_of_time_in_words(Time.now, to_time, include_seconds_or_options, options.except(:vague))
|
21
|
+
end
|
22
|
+
|
23
|
+
def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
|
24
|
+
options[:precision] ||= 0
|
25
|
+
options = options_with_scope(options)
|
26
|
+
distance = to_time - from_time
|
27
|
+
result = ((current_time - from_time) / distance) * 100
|
28
|
+
number_with_precision(result, options).to_s + '%'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/dotiw/locale/ar.yml
CHANGED
@@ -2,45 +2,103 @@ ar:
|
|
2
2
|
datetime:
|
3
3
|
dotiw:
|
4
4
|
seconds:
|
5
|
-
|
5
|
+
zero: ثانية
|
6
|
+
one: ثانية واحدة
|
6
7
|
two: ثانيتين
|
7
|
-
few: "%{count}
|
8
|
-
many: "%{count}
|
9
|
-
other: "%{count}
|
8
|
+
few: "%{count} توانٍ"
|
9
|
+
many: "%{count} ثانية"
|
10
|
+
other: "%{count} ثانية"
|
10
11
|
minutes:
|
11
|
-
|
12
|
+
zero: دقيقة
|
13
|
+
one: دقيقة واحدة
|
12
14
|
two: دقيقتين
|
13
15
|
few: "%{count} دقائق"
|
14
|
-
many: "%{count}
|
15
|
-
other: "%{count}
|
16
|
+
many: "%{count} دقيقة"
|
17
|
+
other: "%{count} دقيقة"
|
16
18
|
hours:
|
17
|
-
|
19
|
+
zero: ساعة
|
20
|
+
one: ساعة واحدة
|
18
21
|
two: ساعتين
|
19
22
|
few: "%{count} ساعات"
|
20
|
-
many: "%{count}
|
21
|
-
other: "%{count}
|
23
|
+
many: "%{count} ساعة"
|
24
|
+
other: "%{count} ساعة"
|
22
25
|
days:
|
23
|
-
|
24
|
-
|
26
|
+
zero: يوم
|
27
|
+
one: يوم واحد
|
28
|
+
two: يومين
|
25
29
|
few: "%{count} أيام"
|
26
|
-
many: "%{count}
|
27
|
-
other: "%{count}
|
30
|
+
many: "%{count} يومًا"
|
31
|
+
other: "%{count} يوم"
|
28
32
|
weeks:
|
29
|
-
|
30
|
-
|
33
|
+
zero: أسبوع
|
34
|
+
one: أسبوع واحدة
|
35
|
+
two: أسبوعين
|
31
36
|
few: "%{count} أسابيع"
|
32
37
|
many: "%{count} أسابيع"
|
33
|
-
other: "%{count}
|
38
|
+
other: "%{count} أسيوع"
|
34
39
|
months:
|
35
|
-
|
40
|
+
zero: شهر
|
41
|
+
one: شهر واحد
|
36
42
|
two: شهرين
|
37
43
|
few: "%{count} أشهر"
|
38
|
-
many: "%{count}
|
39
|
-
other: "%{count}
|
44
|
+
many: "%{count} شهراً"
|
45
|
+
other: "%{count} شهر"
|
40
46
|
years:
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
zero: عام
|
48
|
+
one: عام واحد
|
49
|
+
two: عامين
|
50
|
+
few: "%{count} أعوام"
|
51
|
+
many: "%{count} عاماً"
|
52
|
+
other: "%{count} عام"
|
53
|
+
less_than_x: "%{distance} أقل من"
|
54
|
+
dotiw_compact:
|
55
|
+
seconds:
|
56
|
+
zero: ثانية
|
57
|
+
one: ثانية واحدة
|
58
|
+
two: ثانيتين
|
59
|
+
few: "%{count}توانٍ"
|
60
|
+
many: "%{count}ثانية"
|
61
|
+
other: "%{count}ثانية"
|
62
|
+
minutes:
|
63
|
+
zero: دقيقة
|
64
|
+
one: دقيقة واحدة
|
65
|
+
two: دقيقتين
|
66
|
+
few: "%{count}دقائق"
|
67
|
+
many: "%{count}دقيقة"
|
68
|
+
other: "%{count}دقيقة"
|
69
|
+
hours:
|
70
|
+
zero: ساعة
|
71
|
+
one: ساعة واحدة
|
72
|
+
two: ساعتين
|
73
|
+
few: "%{count}ساعات"
|
74
|
+
many: "%{count}ساعة"
|
75
|
+
other: "%{count}ساعة"
|
76
|
+
days:
|
77
|
+
zero: يوم
|
78
|
+
one: يوم واحد
|
79
|
+
two: يومين
|
80
|
+
few: "%{count}أيام"
|
81
|
+
many: "%{count}يومًا"
|
82
|
+
other: "%{count}يوم"
|
83
|
+
weeks:
|
84
|
+
zero: أسبوع
|
85
|
+
one: أسبوع واحدة
|
86
|
+
two: أسبوعين
|
87
|
+
few: "%{count}أسابيع"
|
88
|
+
many: "%{count}أسابيع"
|
89
|
+
other: "%{count}أسيوع"
|
90
|
+
months:
|
91
|
+
zero: شهر
|
92
|
+
one: شهر واحد
|
93
|
+
two: شهرين
|
94
|
+
few: "%{count}أشهر"
|
95
|
+
many: "%{count}شهراً"
|
96
|
+
other: "%{count}شهر"
|
97
|
+
years:
|
98
|
+
zero: عام
|
99
|
+
one: عام واحد
|
100
|
+
two: عامين
|
101
|
+
few: "%{count}أعوام"
|
102
|
+
many: "%{count}عاماً"
|
103
|
+
other: "%{count}عام"
|
104
|
+
less_than_x: "%{distance}>"
|
data/lib/dotiw/locale/da.yml
CHANGED
@@ -21,3 +21,38 @@ da:
|
|
21
21
|
other: "%{count} måneder"
|
22
22
|
years: "%{count} år"
|
23
23
|
less_than_x: "mindre end %{distance}"
|
24
|
+
dotiw_compact:
|
25
|
+
seconds:
|
26
|
+
one: 1s
|
27
|
+
other: "%{count}s"
|
28
|
+
minutes:
|
29
|
+
one: 1m
|
30
|
+
other: "%{count}m"
|
31
|
+
hours:
|
32
|
+
one: 1t
|
33
|
+
other: "%{count}t"
|
34
|
+
days:
|
35
|
+
one: 1d
|
36
|
+
other: "%{count}d"
|
37
|
+
weeks:
|
38
|
+
one: 1u
|
39
|
+
other: "%{count}u"
|
40
|
+
months:
|
41
|
+
one: 1må
|
42
|
+
other: "%{count}må"
|
43
|
+
years:
|
44
|
+
one: 1år
|
45
|
+
other: "%{count}år"
|
46
|
+
less_than_x: "<%{distance}"
|
47
|
+
words_connector: ""
|
48
|
+
two_words_connector: ""
|
49
|
+
last_word_connector: ""
|
50
|
+
about_x_years:
|
51
|
+
one: ~1y
|
52
|
+
any: "~%{count}y"
|
53
|
+
over_x_years:
|
54
|
+
one: ">1y"
|
55
|
+
other: ">%{count}y"
|
56
|
+
almost_x_years:
|
57
|
+
one: ~1y
|
58
|
+
any: "~%{count}y"
|
data/lib/dotiw/locale/de.yml
CHANGED
@@ -22,4 +22,39 @@ de:
|
|
22
22
|
years:
|
23
23
|
one: 1 Jahr
|
24
24
|
other: "%{count} Jahre"
|
25
|
-
less_than_x: "weniger als %{distance}"
|
25
|
+
less_than_x: "weniger als %{distance}"
|
26
|
+
dotiw_compact:
|
27
|
+
seconds:
|
28
|
+
one: 1s
|
29
|
+
other: "%{count}s"
|
30
|
+
minutes:
|
31
|
+
one: 1m
|
32
|
+
other: "%{count}m"
|
33
|
+
hours:
|
34
|
+
one: 1std
|
35
|
+
other: "%{count}std"
|
36
|
+
days:
|
37
|
+
one: 1t
|
38
|
+
other: "%{count}t"
|
39
|
+
weeks:
|
40
|
+
one: 1w
|
41
|
+
other: "%{count}w"
|
42
|
+
months:
|
43
|
+
one: 1mo
|
44
|
+
other: "%{count}mo"
|
45
|
+
years:
|
46
|
+
one: 1j
|
47
|
+
other: "%{count}j"
|
48
|
+
less_than_x: "<%{distance}"
|
49
|
+
words_connector: ""
|
50
|
+
two_words_connector: ""
|
51
|
+
last_word_connector: ""
|
52
|
+
about_x_years:
|
53
|
+
one: ~1y
|
54
|
+
any: "~%{count}y"
|
55
|
+
over_x_years:
|
56
|
+
one: ">1y"
|
57
|
+
other: ">%{count}y"
|
58
|
+
almost_x_years:
|
59
|
+
one: ~1y
|
60
|
+
any: "~%{count}y"
|