dotiw 2.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7ac361d8ee4fa014e09e9f77026c08b4fecbe8c
4
- data.tar.gz: 0dc62da9541e16dd15228c7659b502013cae5a49
3
+ metadata.gz: aed9b495f66627b6c68f2e8ca572e2958ef44bf8
4
+ data.tar.gz: d49193040ff64bb85cd25829666a47268fc9ccc8
5
5
  SHA512:
6
- metadata.gz: 8effe0793345b5319dd18ccf19bb018c4940d1ffab22094e97490a951548f07e1b22c2273130f09a557ecaefe06572901b33b082d4b5940bd4ad50d0aea44ba4
7
- data.tar.gz: b659b4568937f7dfc770dc271b9bdc894bd253c5008fed536f8d0aff65257e948d3ea9c45869365fac064020a5ef7a349ddbcdd9fcec56ca9be39be0684a91bc
6
+ metadata.gz: eb4f3572b53a3a6dad22d64fd9793ce6df58791664b8dc9a3a98e6f7745b1a6fdad38d6b7e9014de30e46f33ad472ea5bc96ab1cc4bd0de97e897ebdc5aad318
7
+ data.tar.gz: 6d19cfebf638180ddf0bd8d5f2479df83baeb3426220dd57c645deb40294950f71200ffa5c0199e31ea9905359e2c12f71aac8bd749fdee85a658fc7b658c375
@@ -36,11 +36,25 @@ world*:
36
36
 
37
37
  Oh, and did I mention it supports I18n? Oh yeah. Rock on!
38
38
 
39
+ ## Install
40
+
41
+ Install it as a gem:
42
+
43
+ ```ruby
44
+ gem 'dotiw'
45
+ ```
46
+
47
+ Or from GitHub:
48
+
49
+ ```ruby
50
+ gem 'dotiw', github: 'radar/dotiw'
51
+ ```
52
+
39
53
  ### Options
40
54
 
41
55
  #### :locale
42
56
 
43
- You can pass in a locale and it'll output it in whatever language you want (provided you have translations, otherwise it'll default to English):
57
+ You can pass in a locale and it'll output it in whatever language you want (provided you have translations, otherwise it'll default to your app's default locale (the `config.i18n.default_locale` you have set in `/config/application.rb`):
44
58
 
45
59
  >> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, :locale => :es)
46
60
  => "1 minuto"
@@ -5,9 +5,9 @@ module ActionView
5
5
 
6
6
  def distance_of_time_in_words_hash(from_time, to_time, options = {})
7
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)
8
+ to_time = to_time.to_time if !to_time.is_a?(Time) && to_time.respond_to?(:to_time)
9
9
 
10
- DOTIW::TimeHash.new((from_time - to_time).abs, from_time, to_time, options).to_hash
10
+ DOTIW::TimeHash.new(nil, from_time, to_time, options).to_hash
11
11
  end
12
12
 
13
13
  def distance_of_time(seconds, options = {})
@@ -40,35 +40,46 @@ module ActionView
40
40
  distance_of_time_in_words(from_time, Time.now, include_seconds_or_options)
41
41
  end
42
42
 
43
- private
43
+ private
44
44
  def display_time_in_words(hash, options = {})
45
45
  options.reverse_merge!(
46
- :include_seconds => false
46
+ :include_seconds => false
47
47
  ).symbolize_keys!
48
48
 
49
49
  include_seconds = options.delete(:include_seconds)
50
50
  hash.delete(:seconds) if !include_seconds && hash[:minutes]
51
51
 
52
- options[:except] = Array.wrap(options[:except]).map!(&:to_s) if options[:except]
53
- options[:only] = Array.wrap(options[:only]).map!(&:to_s) if options[:only]
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
54
 
55
55
  # Remove all the values that are nil or excluded. Keep the required ones.
56
56
  hash.delete_if do |key, value|
57
57
  value.nil? || value.zero? ||
58
- (options[:except] && options[:except].include?(key.to_s)) ||
59
- (options[:only] && !options[:only].include?(key.to_s))
58
+ (options[:except] && options[:except].include?(key)) ||
59
+ (options[:only] && !options[:only].include?(key))
60
60
  end
61
- return I18n.t('datetime.distance_in_words.less_than_x_seconds', :count => 1, :locale => options[:locale]) if hash.empty?
62
-
63
- options.delete(:except)
64
- options.delete(:only)
65
61
 
66
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
+
67
76
  output = []
68
77
  I18n.with_options :locale => options[:locale], :scope => i18n_scope do |locale|
69
78
  output = hash.map { |key, value| locale.t(key, :count => value) }
70
79
  end
71
80
 
81
+ options.delete(:except)
82
+ options.delete(:only)
72
83
  highest_measures = options.delete(:highest_measures)
73
84
  highest_measures = 1 if options.delete(:highest_measure_only)
74
85
  if highest_measures
@@ -76,14 +87,14 @@ module ActionView
76
87
  end
77
88
 
78
89
  options[:words_connector] ||= I18n.translate :'datetime.dotiw.words_connector',
79
- :default => :'support.array.words_connector',
80
- :locale => options[:locale]
90
+ :default => :'support.array.words_connector',
91
+ :locale => options[:locale]
81
92
  options[:two_words_connector] ||= I18n.translate :'datetime.dotiw.two_words_connector',
82
- :default => :'support.array.two_words_connector',
83
- :locale => options[:locale]
93
+ :default => :'support.array.two_words_connector',
94
+ :locale => options[:locale]
84
95
  options[:last_word_connector] ||= I18n.translate :'datetime.dotiw.last_word_connector',
85
- :default => :'support.array.last_word_connector',
86
- :locale => options[:locale]
96
+ :default => :'support.array.last_word_connector',
97
+ :locale => options[:locale]
87
98
 
88
99
  output.to_sentence(options)
89
100
  end
@@ -0,0 +1,25 @@
1
+ de:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 1 Sekunde
6
+ other: "%{count} Sekunden"
7
+ minutes:
8
+ one: 1 Minute
9
+ other: "%{count} Minuten"
10
+ hours:
11
+ one: 1 Stunde
12
+ other: "%{count} Stunden"
13
+ days:
14
+ one: 1 Tag
15
+ other: "%{count} Tage"
16
+ weeks:
17
+ one: 1 Woche
18
+ other: "%{count} Wochen"
19
+ months:
20
+ one: 1 Monat
21
+ other: "%{count} Monate"
22
+ years:
23
+ one: 1 Jahr
24
+ other: "%{count} Jahre"
25
+ less_than_x: "weniger als %{distance}"
@@ -22,3 +22,4 @@ en:
22
22
  years:
23
23
  one: 1 year
24
24
  other: "%{count} years"
25
+ less_than_x: "less than %{distance}"
@@ -2,10 +2,10 @@ es:
2
2
  datetime:
3
3
  dotiw:
4
4
  seconds:
5
- one: uno segundo
5
+ one: un segundo
6
6
  other: "%{count} segundos"
7
7
  minutes:
8
- one: uno minuto
8
+ one: un minuto
9
9
  other: "%{count} minutos"
10
10
  hours:
11
11
  one: una hora
@@ -22,3 +22,4 @@ es:
22
22
  years:
23
23
  one: un año
24
24
  other: "%{count} años"
25
+ less_than_x: "menos de %{distance}"
@@ -0,0 +1,24 @@
1
+ it:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: un secondo
6
+ other: "%{count} secondi"
7
+ minutes:
8
+ one: un minuto
9
+ other: "%{count} minuti"
10
+ hours:
11
+ one: una ora
12
+ other: "%{count} ore"
13
+ days:
14
+ one: un giorno
15
+ other: "%{count} giorni"
16
+ weeks:
17
+ one: una settimana
18
+ other: "%{count} settimane"
19
+ months:
20
+ one: un mese
21
+ other: "%{count} mesi"
22
+ years:
23
+ one: un anno
24
+ other: "%{count} anni"
@@ -0,0 +1,24 @@
1
+ ja:
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}年間"
@@ -0,0 +1,25 @@
1
+ nb:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 1 sekund
6
+ other: "%{count} sekunder"
7
+ minutes:
8
+ one: 1 minutt
9
+ other: "%{count} minutter"
10
+ hours:
11
+ one: 1 time
12
+ other: "%{count} timer"
13
+ days:
14
+ one: 1 dag
15
+ other: "%{count} dager"
16
+ weeks:
17
+ one: 1 uke
18
+ other: "%{count} uke"
19
+ months:
20
+ one: 1 måned
21
+ other: "%{count} måneder"
22
+ years:
23
+ one: 1 år
24
+ other: "%{count} år"
25
+ less_than_x: "mindre enn %{distance}"
@@ -0,0 +1,25 @@
1
+ nl:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: 1 seconde
6
+ other: "%{count} seconden"
7
+ minutes:
8
+ one: 1 minuut
9
+ other: "%{count} minuten"
10
+ hours:
11
+ one: 1 uur
12
+ other: "%{count} uur"
13
+ days:
14
+ one: 1 dag
15
+ other: "%{count} dagen"
16
+ weeks:
17
+ one: 1 week
18
+ other: "%{count} weken"
19
+ months:
20
+ one: 1 maand
21
+ other: "%{count} maanden"
22
+ years:
23
+ one: 1 jaar
24
+ other: "%{count} jaar"
25
+ less_than_x: "minder dan %{distance}"
@@ -0,0 +1,32 @@
1
+ pl:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: "1 sekunda"
6
+ few: "%{count} sekundy"
7
+ other: "%{count} sekund"
8
+ minutes:
9
+ one: "1 minuta"
10
+ few: "%{count} minuty"
11
+ other: "%{count} minut"
12
+ hours:
13
+ one: "1 godzina"
14
+ few: "%{count} godziny"
15
+ other: "%{count} godzin"
16
+ days:
17
+ one: "1 dzień"
18
+ few: "%{count} dni"
19
+ other: "%{count} dni"
20
+ weeks:
21
+ one: "1 tydzień"
22
+ few: "%{count} tygodnie"
23
+ other: "%{count} tygodni"
24
+ months:
25
+ one: "1 miesiąc"
26
+ few: "%{count} miesiące"
27
+ other: "%{count} miesięcy"
28
+ years:
29
+ one: "1 rok"
30
+ few: "%{count} lata"
31
+ other: "%{count} lat"
32
+ less_than_x: "mniej niż %{distance}"
@@ -0,0 +1,39 @@
1
+ ru:
2
+ datetime:
3
+ dotiw:
4
+ seconds:
5
+ one: "%{count} секунда"
6
+ few: "%{count} секунды"
7
+ many: "%{count} секунд"
8
+ other: "%{count} секунды"
9
+ minutes:
10
+ one: "%{count} минута"
11
+ few: "%{count} минуты"
12
+ many: "%{count} минут"
13
+ other: "%{count} минуты"
14
+ hours:
15
+ one: "%{count} час"
16
+ few: "%{count} часа"
17
+ many: "%{count} часов"
18
+ other: "%{count} часа"
19
+ days:
20
+ one: "%{count} день"
21
+ few: "%{count} дня"
22
+ many: "%{count} дней"
23
+ other: "%{count} дня"
24
+ weeks:
25
+ one: "%{count} неделя"
26
+ few: "%{count} недели"
27
+ many: "%{count} недель"
28
+ other: "%{count} недели"
29
+ months:
30
+ one: "%{count} месяц"
31
+ few: "%{count} месяца"
32
+ many: "%{count} месяцев"
33
+ other: "%{count} месяца"
34
+ years:
35
+ one: "%{count} год"
36
+ few: "%{count} года"
37
+ many: "%{count} лет"
38
+ other: "%{count} года"
39
+ less_than_x: "меньше, чем %{distance}"
@@ -11,8 +11,17 @@ module DOTIW
11
11
  self.options = options
12
12
  self.distance = distance
13
13
  self.from_time = from_time || Time.now
14
- self.to_time = to_time || (self.from_time + self.distance.seconds)
14
+ self.to_time = to_time || (@to_time_not_given = true && self.from_time + self.distance.seconds)
15
15
  self.smallest, self.largest = [self.from_time, self.to_time].minmax
16
+ self.to_time += 1.hour if @to_time_not_given && self.smallest.dst? && !self.largest.dst?
17
+ self.to_time -= 1.hour if @to_time_not_given && !self.smallest.dst? && self.largest.dst?
18
+ self.smallest, self.largest = [self.from_time, self.to_time].minmax
19
+ self.distance ||= begin
20
+ d = largest - smallest
21
+ d -= 1.hour if self.smallest.dst? && !self.largest.dst?
22
+ d += 1.hour if !self.smallest.dst? && self.largest.dst?
23
+ d
24
+ end
16
25
 
17
26
  build_time_hash
18
27
  end
@@ -64,7 +73,7 @@ module DOTIW
64
73
  end
65
74
 
66
75
  def build_days
67
- output[:days], self.distance = distance.divmod(1.day)
76
+ output[:days], self.distance = distance.divmod(1.day) if output[:days].nil?
68
77
  end
69
78
 
70
79
  def build_months
@@ -101,7 +110,9 @@ module DOTIW
101
110
  output[:months] = months
102
111
  output[:days] = days
103
112
 
104
- total_days, self.distance = (from_time - to_time).abs.divmod(1.day)
113
+ total_days, self.distance = distance.abs.divmod(1.day)
114
+
115
+ [total_days, self.distance]
105
116
  end
106
117
  end # TimeHash
107
- end # DOTIW
118
+ end # DOTIW
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module DOTIW
4
- VERSION = "2.0"
4
+ VERSION = "3.0"
5
5
  end
@@ -7,11 +7,12 @@ describe "A better distance_of_time_in_words" do
7
7
  include ActionView::Helpers::TextHelper
8
8
  include ActionView::Helpers::NumberHelper
9
9
 
10
+ START_TIME = "01-08-2009".to_time
11
+
10
12
  before do
11
13
  I18n.locale = :en
12
- time = "01-08-2009".to_time
13
- allow(Time).to receive(:now).and_return(time)
14
- allow(Time.zone).to receive(:now).and_return(time)
14
+ allow(Time).to receive(:now).and_return(START_TIME)
15
+ allow(Time.zone).to receive(:now).and_return(START_TIME)
15
16
  end
16
17
 
17
18
  describe "distance of time" do
@@ -50,20 +51,20 @@ describe "A better distance_of_time_in_words" do
50
51
  [:years, :months, :days, :minutes, :seconds].each do |name|
51
52
  describe name do
52
53
  it "exactly" do
53
- hash = distance_of_time_in_words_hash(Time.now, Time.now + 1.send(name))
54
+ hash = distance_of_time_in_words_hash(START_TIME, START_TIME + 1.send(name))
54
55
  expect(hash[name]).to eq(1)
55
56
  end
56
57
 
57
58
  it "two" do
58
- hash = distance_of_time_in_words_hash(Time.now, Time.now + 2.send(name))
59
+ hash = distance_of_time_in_words_hash(START_TIME, START_TIME + 2.send(name))
59
60
  expect(hash[name]).to eq(2)
60
61
  end
61
62
  end
62
63
  end
63
64
 
64
65
  it "should be happy with lots of measurements" do
65
- hash = distance_of_time_in_words_hash(Time.now,
66
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds)
66
+ hash = distance_of_time_in_words_hash(START_TIME,
67
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds)
67
68
  expect(hash[:years]).to eq(1)
68
69
  expect(hash[:months]).to eq(2)
69
70
  expect(hash[:days]).to eq(3)
@@ -76,20 +77,25 @@ describe "A better distance_of_time_in_words" do
76
77
 
77
78
  describe "real version" do
78
79
  it "debe hablar español" do
79
- expect(distance_of_time_in_words(Time.now, Time.now + 1.days, true, :locale => :es)).to eq("un día")
80
- expect(distance_of_time_in_words(Time.now, Time.now + 5.days, true, :locale => :es)).to eq("5 días")
80
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, :locale => :es)).to eq("un día")
81
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, :locale => :es)).to eq("5 días")
82
+ end
83
+
84
+ it "deve parlare l'italiano" do
85
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 1.days, true, :locale => :it)).to eq("un giorno")
86
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 5.days, true, :locale => :it)).to eq("5 giorni")
81
87
  end
82
88
 
83
89
  fragments = [
84
- [Time.now, Time.now + 5.days + 3.minutes, "5 days and 3 minutes"],
85
- [Time.now, Time.now + 1.minute, "1 minute"],
86
- [Time.now, Time.now + 3.years, "3 years"],
87
- [Time.now, Time.now + 10.years, "10 years"],
88
- [Time.now, Time.now + 10.years, "10 years"],
89
- [Time.now, Time.now + 3.hour, "3 hours"],
90
- [Time.now, Time.now + 13.months, "1 year and 1 month"],
90
+ [START_TIME, START_TIME + 5.days + 3.minutes, "5 days and 3 minutes"],
91
+ [START_TIME, START_TIME + 1.minute, "1 minute"],
92
+ [START_TIME, START_TIME + 3.years, "3 years"],
93
+ [START_TIME, START_TIME + 10.years, "10 years"],
94
+ [START_TIME, START_TIME + 10.years, "10 years"],
95
+ [START_TIME, START_TIME + 3.hour, "3 hours"],
96
+ [START_TIME, START_TIME + 13.months, "1 year and 1 month"],
91
97
  # Any numeric sequence is merely coincidental.
92
- [Time.now, Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds, "1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds"],
98
+ [START_TIME, START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds, "1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds"],
93
99
  ["2009-3-16".to_time, "2008-4-14".to_time, "11 months and 2 days"],
94
100
  ["2009-3-16".to_time + 1.minute, "2008-4-14".to_time, "11 months, 2 days, and 1 minute"],
95
101
  ["2009-4-14".to_time, "2008-3-16".to_time, "1 year and 29 days"],
@@ -104,26 +110,28 @@ describe "A better distance_of_time_in_words" do
104
110
 
105
111
  describe "accumulate on" do
106
112
  fragments = [
107
- [Time.now,
108
- Time.now + 10.minute,
113
+ [START_TIME,
114
+ START_TIME + 10.minute,
109
115
  :seconds,
110
116
  "600 seconds"],
111
- [Time.now,
112
- Time.now + 10.hour + 10.minute + 1.second,
117
+ [START_TIME,
118
+ START_TIME + 10.hour + 10.minute + 1.second,
113
119
  :minutes,
114
120
  "610 minutes and 1 second"],
115
- [Time.now,
116
- Time.now + 2.day + 10000.hour + 10.second,
121
+ [START_TIME,
122
+ START_TIME + 2.day + 10000.hour + 10.second,
117
123
  :hours,
118
124
  "10048 hours and 10 seconds"],
119
- [Time.now,
120
- Time.now + 2.day + 10000.hour + 10.second,
125
+ [START_TIME,
126
+ START_TIME + 2.day + 10000.hour + 10.second,
121
127
  :days,
122
128
  "418 days, 16 hours, and 10 seconds"],
123
- [Time.now,
124
- Time.now + 2.day + 10000.hour + 10.second,
129
+ [START_TIME,
130
+ START_TIME + 2.day + 10000.hour + 10.second,
125
131
  :months,
126
- "13 months, 16 hours, and 10 seconds"]
132
+ "13 months, 22 days, 16 hours, and 10 seconds"],
133
+ ["2015-1-15".to_time, "2016-3-15".to_time, :months, "14 months"]
134
+
127
135
  ]
128
136
  fragments.each do |start, finish, accumulator, output|
129
137
  it "should be #{output}" do
@@ -155,77 +163,89 @@ describe "A better distance_of_time_in_words" do
155
163
  describe "with output options" do
156
164
  fragments = [
157
165
  # Any numeric sequence is merely coincidental.
158
- [Time.now,
159
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
166
+ [START_TIME,
167
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
160
168
  { :words_connector => " - " },
161
169
  "1 year - 2 months - 3 days - 4 hours - 5 minutes, and 6 seconds"],
162
- [Time.now,
163
- Time.now + 5.minutes + 6.seconds,
170
+ [START_TIME,
171
+ START_TIME + 5.minutes + 6.seconds,
164
172
  { :two_words_connector => " - " },
165
173
  "5 minutes - 6 seconds"],
166
- [Time.now,
167
- Time.now + 4.hours + 5.minutes + 6.seconds,
174
+ [START_TIME,
175
+ START_TIME + 4.hours + 5.minutes + 6.seconds,
168
176
  { :last_word_connector => " - " },
169
177
  "4 hours, 5 minutes - 6 seconds"],
170
- [Time.now,
171
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
178
+ [START_TIME,
179
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
172
180
  { :except => "minutes" },
173
181
  "1 year, 2 months, 3 days, 4 hours, and 6 seconds"],
174
- [Time.now,
175
- Time.now + 1.hour + 1.minute,
182
+ [START_TIME,
183
+ START_TIME + 1.hour + 1.minute,
176
184
  { :except => "minutes"}, "1 hour"],
177
- [Time.now,
178
- Time.now + 1.hour + 1.day + 1.minute,
185
+ [START_TIME,
186
+ START_TIME + 1.hour + 1.day + 1.minute,
179
187
  { :except => ["minutes", "hours"]},
180
188
  "1 day"],
181
- [Time.now,
182
- Time.now + 1.hour + 1.day + 1.minute,
189
+ [START_TIME,
190
+ START_TIME + 1.hour + 1.day + 1.minute,
183
191
  { :only => ["minutes", "hours"]},
184
192
  "1 hour and 1 minute"],
185
- [Time.now,
186
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
193
+ [START_TIME,
194
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
187
195
  { :vague => true },
188
196
  "about 1 year"],
189
- [Time.now,
190
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
197
+ [START_TIME,
198
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
191
199
  { :vague => "Yes please" },
192
200
  "about 1 year"],
193
- [Time.now,
194
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
201
+ [START_TIME,
202
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
195
203
  { :vague => false },
196
204
  "1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds"],
197
- [Time.now,
198
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
205
+ [START_TIME,
206
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
199
207
  { :vague => nil },
200
208
  "1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds"],
201
- [Time.now,
202
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
209
+ [START_TIME,
210
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
203
211
  { :except => "minutes" },
204
212
  "1 year, 2 months, 3 days, 4 hours, and 6 seconds"],
205
- [Time.now,
206
- Time.now + 1.hour + 2.minutes + 3.seconds,
213
+ [START_TIME,
214
+ START_TIME + 1.hour + 2.minutes + 3.seconds,
207
215
  { :highest_measure_only => true },
208
216
  "1 hour"],
209
- [Time.now,
210
- Time.now + 1.hours + 2.minutes + 3.seconds,
217
+ [START_TIME,
218
+ START_TIME + 1.hours + 2.minutes + 3.seconds,
211
219
  { :highest_measures => 1 },
212
220
  "1 hour"],
213
- [Time.now,
214
- Time.now + 2.year + 3.months + 4.days + 5.hours + 6.minutes + 7.seconds,
221
+ [START_TIME,
222
+ START_TIME + 2.year + 3.months + 4.days + 5.hours + 6.minutes + 7.seconds,
215
223
  { :highest_measures => 3 },
216
224
  "2 years, 3 months, and 4 days"],
217
- [Time.now,
218
- Time.now + 2.year + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
225
+ [START_TIME,
226
+ START_TIME + 2.year + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
219
227
  { :highest_measures => 2 },
220
228
  "2 years and 25 days"],
221
- [Time.now,
222
- Time.now + 4.days + 6.minutes + 7.seconds,
229
+ [START_TIME,
230
+ START_TIME + 4.days + 6.minutes + 7.seconds,
223
231
  { :highest_measures => 3 },
224
232
  "4 days, 6 minutes, and 7 seconds"],
225
- [Time.now,
226
- Time.now + 1.year + 2.weeks,
233
+ [START_TIME,
234
+ START_TIME + 1.year + 2.weeks,
227
235
  { :highest_measures => 3 },
228
- "1 year and 14 days"]
236
+ "1 year and 14 days"],
237
+ [START_TIME,
238
+ START_TIME + 1.days,
239
+ { :only => [:years, :months] },
240
+ "less than 1 month"],
241
+ [START_TIME,
242
+ START_TIME + 5.minutes,
243
+ { :except => [:hours, :minutes, :seconds] },
244
+ "less than 1 day"],
245
+ [START_TIME,
246
+ START_TIME + 1.days,
247
+ { :highest_measures => 1, :only => [:years, :months] },
248
+ "less than 1 month"]
229
249
  ]
230
250
  fragments.each do |start, finish, options, output|
231
251
  it "should be #{output}" do
@@ -235,12 +255,12 @@ describe "A better distance_of_time_in_words" do
235
255
 
236
256
  describe "include_seconds" do
237
257
  it "is ignored if only seconds have passed" do
238
- expect(distance_of_time_in_words(Time.now, Time.now + 1.second, false)).to eq("1 second")
258
+ expect(distance_of_time_in_words(START_TIME, START_TIME + 1.second, false)).to eq("1 second")
239
259
  end
240
260
 
241
261
  it "removes seconds in all other cases" do
242
- expect(distance_of_time_in_words(Time.now,
243
- Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
262
+ expect(distance_of_time_in_words(START_TIME,
263
+ START_TIME + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
244
264
  false)).to eq("1 year, 2 months, 3 days, 4 hours, and 5 minutes")
245
265
  end
246
266
  end # include_seconds
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotiw
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: '3.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
@@ -109,12 +109,19 @@ files:
109
109
  - dotiw.gemspec
110
110
  - lib/dotiw.rb
111
111
  - lib/dotiw/action_view_ext/helpers/date_helper.rb
112
+ - lib/dotiw/locale/de.yml
112
113
  - lib/dotiw/locale/en.yml
114
+ - lib/dotiw/locale/es.yml
115
+ - lib/dotiw/locale/it.yml
116
+ - lib/dotiw/locale/ja.yml
117
+ - lib/dotiw/locale/nb.yml
118
+ - lib/dotiw/locale/nl.yml
119
+ - lib/dotiw/locale/pl.yml
120
+ - lib/dotiw/locale/ru.yml
113
121
  - lib/dotiw/time_hash.rb
114
122
  - lib/dotiw/version.rb
115
123
  - spec/lib/dotiw_spec.rb
116
124
  - spec/spec_helper.rb
117
- - spec/translations/es.yml
118
125
  homepage:
119
126
  licenses: []
120
127
  metadata: {}
@@ -134,11 +141,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
141
  version: '0'
135
142
  requirements: []
136
143
  rubyforge_project:
137
- rubygems_version: 2.2.2
144
+ rubygems_version: 2.4.6
138
145
  signing_key:
139
146
  specification_version: 4
140
147
  summary: Better distance_of_time_in_words for Rails
141
148
  test_files:
142
149
  - spec/lib/dotiw_spec.rb
143
150
  - spec/spec_helper.rb
144
- - spec/translations/es.yml