dotiw 3.0 → 5.0.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.
- 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 +24 -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 +22 -11
- 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/zh-CN.yml +25 -0
- data/lib/dotiw/methods.rb +91 -0
- data/lib/dotiw/time_hash.rb +65 -38
- data/lib/dotiw/version.rb +2 -2
- data/spec/lib/dotiw_spec.rb +206 -157
- data/spec/spec_helper.rb +2 -9
- metadata +76 -22
- data/.travis.yml +0 -5
- data/lib/dotiw/action_view_ext/helpers/date_helper.rb +0 -103
data/Rakefile
CHANGED
data/dotiw.gemspec
CHANGED
@@ -1,30 +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
|
9
|
+
s.licenses = ['MIT']
|
10
10
|
|
11
|
-
s.authors = ["Ryan Bigg"]
|
12
|
-
s.
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
s.authors = ["Ryan Bigg", "Lauran Jansen"]
|
12
|
+
s.description = "dotiw is a gem for Rails that overrides the
|
13
|
+
default distance_of_time_in_words and provides
|
14
|
+
a more accurate output. Do you crave accuracy
|
15
|
+
down to the second? So do I. That's why I made
|
16
|
+
this gem. - Ryan"
|
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'
|
16
20
|
|
17
|
-
s.add_dependency
|
18
|
-
s.add_dependency
|
21
|
+
s.add_dependency 'i18n'
|
22
|
+
s.add_dependency 'activesupport'
|
19
23
|
|
20
|
-
s.add_development_dependency
|
21
|
-
s.add_development_dependency
|
22
|
-
s.add_development_dependency
|
23
|
-
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'
|
24
30
|
|
25
31
|
s.files = `git ls-files`.split("\n")
|
26
32
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
-
s.require_paths = [
|
33
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
34
|
+
s.require_paths = ['lib']
|
29
35
|
end
|
30
|
-
|
data/lib/dotiw.rb
CHANGED
@@ -1,30 +1,41 @@
|
|
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'
|
17
20
|
|
18
|
-
def init_i18n
|
21
|
+
def init_i18n!
|
19
22
|
I18n.load_path.unshift(*locale_files)
|
20
23
|
I18n.reload!
|
21
24
|
end
|
22
25
|
|
23
|
-
protected
|
26
|
+
protected
|
27
|
+
|
24
28
|
# Returns all locale files shipped with library
|
25
29
|
def locale_files
|
26
30
|
Dir[File.join(File.dirname(__FILE__), 'dotiw', 'locale', '**/*')]
|
27
31
|
end
|
28
32
|
end # DOTIW
|
29
33
|
|
30
|
-
DOTIW.init_i18n
|
34
|
+
DOTIW.init_i18n!
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'action_view'
|
38
|
+
require_relative 'dotiw/action_view/helpers/date_helper'
|
39
|
+
rescue LoadError
|
40
|
+
# TODO: don't rely on exception
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module DateHelper
|
6
|
+
alias_method :_distance_of_time_in_words, :distance_of_time_in_words
|
7
|
+
alias_method :_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.delete(:vague)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def distance_of_time_in_percent(from_time, current_time, to_time, options = {})
|
17
|
+
options[:precision] ||= 0
|
18
|
+
distance = to_time - from_time
|
19
|
+
result = ((current_time - from_time) / distance) * 100
|
20
|
+
number_with_precision(result, options).to_s + '%'
|
21
|
+
end
|
22
|
+
end # DateHelper
|
23
|
+
end # Helpers
|
24
|
+
end # ActionView
|
@@ -0,0 +1,53 @@
|
|
1
|
+
ar:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
zero: ثانية
|
6
|
+
one: ثانية واحدة
|
7
|
+
two: ثانيتين
|
8
|
+
few: "%{count} توانٍ"
|
9
|
+
many: "%{count} ثانية"
|
10
|
+
other: "%{count} ثانية"
|
11
|
+
minutes:
|
12
|
+
zero: دقيقة
|
13
|
+
one: دقيقة واحدة
|
14
|
+
two: دقيقتين
|
15
|
+
few: "%{count} دقائق"
|
16
|
+
many: "%{count} دقيقة"
|
17
|
+
other: "%{count} دقيقة"
|
18
|
+
hours:
|
19
|
+
zero: ساعة
|
20
|
+
one: ساعة واحدة
|
21
|
+
two: ساعتين
|
22
|
+
few: "%{count} ساعات"
|
23
|
+
many: "%{count} ساعة"
|
24
|
+
other: "%{count} ساعة"
|
25
|
+
days:
|
26
|
+
zero: يوم
|
27
|
+
one: يوم واحد
|
28
|
+
two: يومين
|
29
|
+
few: "%{count} أيام"
|
30
|
+
many: "%{count} يومًا"
|
31
|
+
other: "%{count} يوم"
|
32
|
+
weeks:
|
33
|
+
zero: أسبوع
|
34
|
+
one: أسبوع واحدة
|
35
|
+
two: أسبوعين
|
36
|
+
few: "%{count} أسابيع"
|
37
|
+
many: "%{count} أسابيع"
|
38
|
+
other: "%{count} أسيوع"
|
39
|
+
months:
|
40
|
+
zero: شهر
|
41
|
+
one: شهر واحد
|
42
|
+
two: شهرين
|
43
|
+
few: "%{count} أشهر"
|
44
|
+
many: "%{count} شهراً"
|
45
|
+
other: "%{count} شهر"
|
46
|
+
years:
|
47
|
+
zero: عام
|
48
|
+
one: عام واحد
|
49
|
+
two: عامين
|
50
|
+
few: "%{count} أعوام"
|
51
|
+
many: "%{count} عاماً"
|
52
|
+
other: "%{count} عام"
|
53
|
+
less_than_x: "%{distance} أقل من"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
da:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: "1 sekund"
|
6
|
+
other: "%{count} sekunder"
|
7
|
+
minutes:
|
8
|
+
one: "1 minut"
|
9
|
+
other: "%{count} minutter"
|
10
|
+
hours:
|
11
|
+
one: "1 time"
|
12
|
+
other: "%{count} timer"
|
13
|
+
days:
|
14
|
+
one: "1 dag"
|
15
|
+
other: "%{count} dage"
|
16
|
+
weeks:
|
17
|
+
one: "1 uge"
|
18
|
+
other: "%{count} uger"
|
19
|
+
months:
|
20
|
+
one: "1 måned"
|
21
|
+
other: "%{count} måneder"
|
22
|
+
years: "%{count} år"
|
23
|
+
less_than_x: "mindre end %{distance}"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
fr:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: 1 seconde
|
6
|
+
other: "%{count} secondes"
|
7
|
+
minutes:
|
8
|
+
one: 1 minute
|
9
|
+
other: "%{count} minutes"
|
10
|
+
hours:
|
11
|
+
one: 1 heure
|
12
|
+
other: "%{count} heures"
|
13
|
+
days:
|
14
|
+
one: 1 jour
|
15
|
+
other: "%{count} jours"
|
16
|
+
weeks:
|
17
|
+
one: 1 semaine
|
18
|
+
other: "%{count} semaines"
|
19
|
+
months:
|
20
|
+
one: 1 mois
|
21
|
+
other: "%{count} mois"
|
22
|
+
years:
|
23
|
+
one: 1 an
|
24
|
+
other: "%{count} ans"
|
25
|
+
less_than_x: "moins de %{distance}"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
id:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: 1 detik
|
6
|
+
other: "%{count} detik"
|
7
|
+
minutes:
|
8
|
+
one: 1 menit
|
9
|
+
other: "%{count} menit"
|
10
|
+
hours:
|
11
|
+
one: 1 jam
|
12
|
+
other: "%{count} jam"
|
13
|
+
days:
|
14
|
+
one: 1 hari
|
15
|
+
other: "%{count} hari"
|
16
|
+
weeks:
|
17
|
+
one: 1 minggu
|
18
|
+
other: "%{count} minggu"
|
19
|
+
months:
|
20
|
+
one: 1 bulan
|
21
|
+
other: "%{count} bulan"
|
22
|
+
years:
|
23
|
+
one: 1 tahun
|
24
|
+
other: "%{count} tahun"
|
25
|
+
less_than_x: "kurang dari %{distance}"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
ko:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: 일 초
|
6
|
+
other: "%{count} 초"
|
7
|
+
minutes:
|
8
|
+
one: 일 분
|
9
|
+
other: "%{count} 분"
|
10
|
+
hours:
|
11
|
+
one: 한 시간
|
12
|
+
other: "%{count} 시간"
|
13
|
+
days:
|
14
|
+
one: 하루
|
15
|
+
other: "%{count} 일"
|
16
|
+
weeks:
|
17
|
+
one: 일주
|
18
|
+
other: "%{count} 주"
|
19
|
+
months:
|
20
|
+
one: 한 달
|
21
|
+
other: "%{count} 달"
|
22
|
+
years:
|
23
|
+
one: 일년
|
24
|
+
other: "%{count} 년"
|
25
|
+
less_than_x: "%{distance} 미만"
|
data/lib/dotiw/locale/pl.yml
CHANGED
@@ -4,29 +4,36 @@ pl:
|
|
4
4
|
seconds:
|
5
5
|
one: "1 sekunda"
|
6
6
|
few: "%{count} sekundy"
|
7
|
+
many: "%{count} sekund"
|
7
8
|
other: "%{count} sekund"
|
8
9
|
minutes:
|
9
10
|
one: "1 minuta"
|
10
11
|
few: "%{count} minuty"
|
12
|
+
many: "%{count} minut"
|
11
13
|
other: "%{count} minut"
|
12
14
|
hours:
|
13
15
|
one: "1 godzina"
|
14
16
|
few: "%{count} godziny"
|
17
|
+
many: "%{count} godzin"
|
15
18
|
other: "%{count} godzin"
|
16
19
|
days:
|
17
20
|
one: "1 dzień"
|
18
21
|
few: "%{count} dni"
|
22
|
+
many: "%{count} dni"
|
19
23
|
other: "%{count} dni"
|
20
24
|
weeks:
|
21
25
|
one: "1 tydzień"
|
22
26
|
few: "%{count} tygodnie"
|
27
|
+
many: "%{count} tygodni"
|
23
28
|
other: "%{count} tygodni"
|
24
29
|
months:
|
25
30
|
one: "1 miesiąc"
|
26
31
|
few: "%{count} miesiące"
|
32
|
+
many: "%{count} miesięcy"
|
27
33
|
other: "%{count} miesięcy"
|
28
34
|
years:
|
29
35
|
one: "1 rok"
|
30
36
|
few: "%{count} lata"
|
37
|
+
many: "%{count} lat"
|
31
38
|
other: "%{count} lat"
|
32
39
|
less_than_x: "mniej niż %{distance}"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
pt-BR:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: 1 segundo
|
6
|
+
other: "%{count} segundos"
|
7
|
+
minutes:
|
8
|
+
one: 1 minuto
|
9
|
+
other: "%{count} minutos"
|
10
|
+
hours:
|
11
|
+
one: 1 hora
|
12
|
+
other: "%{count} horas"
|
13
|
+
days:
|
14
|
+
one: 1 dia
|
15
|
+
other: "%{count} dias"
|
16
|
+
weeks:
|
17
|
+
one: 1 semana
|
18
|
+
other: "%{count} semanas"
|
19
|
+
months:
|
20
|
+
one: 1 mês
|
21
|
+
other: "%{count} meses"
|
22
|
+
years:
|
23
|
+
one: 1 ano
|
24
|
+
other: "%{count} anos"
|
25
|
+
less_than_x: "menos de %{distance}"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
zh-CN:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: 1 秒
|
6
|
+
other: "%{count} 秒"
|
7
|
+
minutes:
|
8
|
+
one: 1 分钟
|
9
|
+
other: "%{count} 分钟"
|
10
|
+
hours:
|
11
|
+
one: 1 小时
|
12
|
+
other: "%{count} 小时"
|
13
|
+
days:
|
14
|
+
one: 1 天
|
15
|
+
other: "%{count} 天"
|
16
|
+
weeks:
|
17
|
+
one: 1 周
|
18
|
+
other: "%{count} 周"
|
19
|
+
months:
|
20
|
+
one: 1 月
|
21
|
+
other: "%{count} 月"
|
22
|
+
years:
|
23
|
+
one: 1 年
|
24
|
+
other: "%{count} 年"
|
25
|
+
less_than_x: "小于 %{distance}"
|