dotiw 3.0.1 → 3.1.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/.travis.yml +7 -1
- data/CHANGELOG.md +10 -0
- data/CONTRIBUTING.md +34 -0
- data/README.markdown +15 -15
- data/dotiw.gemspec +10 -5
- data/lib/dotiw/action_view_ext/helpers/date_helper.rb +1 -1
- 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/pt-BR.yml +25 -0
- data/lib/dotiw/time_hash.rb +30 -9
- data/lib/dotiw/version.rb +1 -1
- data/spec/lib/dotiw_spec.rb +36 -29
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b71e3935ad86d61036e453b41579881ac1a8f3b
|
4
|
+
data.tar.gz: 26e1ce49677a8dead460ac3c3b0b4db93f3e196b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6157f043c6114509982a82b1bc5c6973b81bbcb7cb4293a8388dd1736cac3427c578301f866d86f685a201fdc7e1163067c9ef4e32d2a738804578290a4c6b8
|
7
|
+
data.tar.gz: 837d5ec5c403dcb288bba9b3be908b98ad9d6e7191b3f777014f5b77242c84ff5d48fb43ce25c4614bcd2ff6659b34d2e8b74f4400e7e213c41dc8fe9a8ccdb8
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## 3.1.1 (2016/03/08)
|
2
|
+
* Add CHANGELOG.md
|
3
|
+
|
4
|
+
## 3.1.0 (2016/03/07)
|
5
|
+
|
6
|
+
* [#68](https://github.com/radar/dotiw/pull/68): Add support for weeks - [@lauranjansen](https://github.com/lauranjansen)
|
7
|
+
* [#69](https://github.com/radar/dotiw/pull/69): Add Indonesian language support - [@avidmaulanas](https://github.com/avidmaulanas)
|
8
|
+
* [#70](https://github.com/radar/dotiw/pull/70): Add French language support - [@geo1004](https://github.com/geo1004)
|
9
|
+
* [#72](https://github.com/radar/dotiw/pull/72): Add Danish language support - [@kaspernj](https://github.com/kaspernj)
|
10
|
+
* [#71](https://github.com/radar/dotiw/pull/71): Update bundler and ruby versions for Travis CI - [@lauranjansen](https://github.com/lauranjansen)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
DOTIW is an open source project and we encourage contributions.
|
2
|
+
|
3
|
+
## Filing an issue
|
4
|
+
|
5
|
+
When filing an issue on the DOTIW project, please provide these details:
|
6
|
+
|
7
|
+
* A comprehensive list of steps to reproduce the issue.
|
8
|
+
* What you're *expecting* to happen compared with what's *actually* happening.
|
9
|
+
* Your application's complete `Gemfile.lock`, and `Gemfile.lock` as text in a [Gist](https://gist.github.com) (*not as an image*)
|
10
|
+
* Any relevant stack traces ("Full trace" preferred)
|
11
|
+
|
12
|
+
In 99% of cases, this information is enough to determine the cause and solution
|
13
|
+
to the problem that is being described.
|
14
|
+
|
15
|
+
Please remember to format code using triple backticks (\`) so that it is neatly
|
16
|
+
formatted when the issue is posted.
|
17
|
+
|
18
|
+
## Pull requests
|
19
|
+
|
20
|
+
We gladly accept pull requests to add documentation, fix bugs and, in some circumstances,
|
21
|
+
add new features to DOTIW.
|
22
|
+
|
23
|
+
Here's a quick guide:
|
24
|
+
|
25
|
+
1. Fork the repo.
|
26
|
+
|
27
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great
|
28
|
+
to know that you have a clean slate.
|
29
|
+
|
30
|
+
3. Create new branch then make changes and add tests for your changes. Only
|
31
|
+
refactoring and documentation changes require no new tests. If you are adding
|
32
|
+
functionality or fixing a bug, we need tests!
|
33
|
+
|
34
|
+
4. Push to your fork and submit a pull request.
|
data/README.markdown
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
dotiw is a gem for Rails that overrides the default `distance_of_time_in_words` and provides a more accurate output. Do you crave accuracy down to the second? So do I. That's why I made this gem. Take this for a totally kickass example:
|
4
4
|
|
5
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 3.
|
6
|
-
=> "1 year, 2 months, 3
|
7
|
-
|
5
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds, true)
|
6
|
+
=> "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"
|
7
|
+
|
8
8
|
Also if one of the measurement is zero it will not output it:
|
9
9
|
|
10
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months +
|
11
|
-
=> "1 year, 2 months, 4
|
12
|
-
|
10
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 5.hours + 6.minutes + 7.seconds, true)
|
11
|
+
=> "1 year, 2 months, 4 days, 6 minutes, and 7 seconds"
|
12
|
+
|
13
13
|
Better than "about 1 year", am I right? Of course I am.
|
14
14
|
|
15
15
|
"But Ryan!", you say, "What happens if the time is only in seconds but because of the default the seconds aren't shown? Won't it be blank?"
|
@@ -21,7 +21,7 @@ Better than "about 1 year", am I right? Of course I am.
|
|
21
21
|
The third argument for this method is whether or not to include seconds. By default this is `false` (because in Rails' `distance_of_time_in_words` it is), you can turn it on though by passing `true` as the third argument:
|
22
22
|
|
23
23
|
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 1.second, true)
|
24
|
-
=> "1 year, and 1 second"
|
24
|
+
=> "1 year, and 1 second"
|
25
25
|
|
26
26
|
Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility",
|
27
27
|
because that's just an insanely radical thing to do. \m/
|
@@ -58,7 +58,7 @@ You can pass in a locale and it'll output it in whatever language you want (prov
|
|
58
58
|
|
59
59
|
>> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, :locale => :es)
|
60
60
|
=> "1 minuto"
|
61
|
-
|
61
|
+
|
62
62
|
This will also be passed to `to_sentence`
|
63
63
|
|
64
64
|
#### :vague
|
@@ -95,7 +95,7 @@ Culling a whole group of measurements of time:
|
|
95
95
|
|
96
96
|
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :except => [:minutes, :hours])
|
97
97
|
=> "1 day"
|
98
|
-
|
98
|
+
|
99
99
|
#### :highest\_measure\_only
|
100
100
|
|
101
101
|
For times when Rails `distance_of_time_in_words` is not precise enough and `DOTIW` is too precise. For instance, if you only want to know the highest time part (measure) that elapsed between two dates.
|
@@ -125,7 +125,7 @@ Using something other than a comma:
|
|
125
125
|
|
126
126
|
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :words_connector => ' - ')
|
127
127
|
=> "1 hour - 1 minute, and 1 second"
|
128
|
-
|
128
|
+
|
129
129
|
#### :two\_words\_connector
|
130
130
|
|
131
131
|
**This is an option for `to_sentence`, defaults to ' and '**
|
@@ -135,7 +135,7 @@ Using something other than 'and':
|
|
135
135
|
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, true, :two_words_connector => ' plus ')
|
136
136
|
=> "1 hour plus 1 minute"
|
137
137
|
|
138
|
-
#### :last\_word\_connector
|
138
|
+
#### :last\_word\_connector
|
139
139
|
|
140
140
|
**This is an option for `to_sentence`, defaults to ', and '**
|
141
141
|
|
@@ -155,17 +155,17 @@ If you have simply a number of seconds you can get the "stringified" version of
|
|
155
155
|
|
156
156
|
Don't like any format you're given? That's cool too! Here, have an indifferent hash version:
|
157
157
|
|
158
|
-
>> distance_of_time_in_words_hash(Time.now, Time.now + 1.year + 2.months + 3.
|
159
|
-
=> {:days => 3, :seconds =>
|
158
|
+
>> distance_of_time_in_words_hash(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds)
|
159
|
+
=> {:days => 4, :weeks => 3, :seconds => 7, :minutes => 6, :years => 1, :hours => 5, :months => 2}
|
160
160
|
|
161
161
|
Indifferent means that you can access all keys by their `String` or `Symbol` version.
|
162
|
-
|
162
|
+
|
163
163
|
## distance\_of\_time\_in\_percent
|
164
164
|
|
165
165
|
If you want to calculate a distance of time in percent, use `distance_of_time_in_percent`. The first argument is the beginning time, the second argument the "current" time and the third argument is the end time. This method takes the same options as [`number_with_precision`](http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_with_precision).
|
166
166
|
|
167
167
|
distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time, options)
|
168
|
-
|
168
|
+
|
169
169
|
|
170
170
|
## Contributors
|
171
171
|
|
data/dotiw.gemspec
CHANGED
@@ -7,12 +7,18 @@ require 'dotiw/version'
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'dotiw'
|
9
9
|
s.version = DOTIW::VERSION
|
10
|
+
s.licenses = ["MIT"]
|
10
11
|
|
11
|
-
s.authors = ["Ryan Bigg"]
|
12
|
-
s.date = %q{
|
13
|
-
s.description = "
|
12
|
+
s.authors = ["Ryan Bigg", "Lauran Jansen"]
|
13
|
+
s.date = %q{2016-03-08}
|
14
|
+
s.description = "dotiw is a gem for Rails that overrides the
|
15
|
+
default distance_of_time_in_words and provides
|
16
|
+
a more accurate output. Do you crave accuracy
|
17
|
+
down to the second? So do I. That's why I made
|
18
|
+
this gem. - Ryan"
|
14
19
|
s.summary = "Better distance_of_time_in_words for Rails"
|
15
|
-
s.email = "radarlistener@gmail.com"
|
20
|
+
s.email = ["radarlistener@gmail.com", "github@lauranjansen.com"]
|
21
|
+
s.homepage = "https://github.com/radar/dotiw"
|
16
22
|
|
17
23
|
s.add_dependency "actionpack", ">= 3"
|
18
24
|
s.add_dependency "i18n"
|
@@ -27,4 +33,3 @@ Gem::Specification.new do |s|
|
|
27
33
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
34
|
s.require_paths = ["lib"]
|
29
35
|
end
|
30
|
-
|
@@ -37,7 +37,7 @@ module ActionView
|
|
37
37
|
alias_method :old_time_ago_in_words, :time_ago_in_words
|
38
38
|
|
39
39
|
def time_ago_in_words(from_time, include_seconds_or_options = {})
|
40
|
-
distance_of_time_in_words(from_time, Time.
|
40
|
+
distance_of_time_in_words(from_time, Time.current, include_seconds_or_options)
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
@@ -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
|
+
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}"
|
data/lib/dotiw/time_hash.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module DOTIW
|
4
4
|
class TimeHash
|
5
|
-
TIME_FRACTIONS = [:seconds, :minutes, :hours, :days, :months, :years]
|
5
|
+
TIME_FRACTIONS = [:seconds, :minutes, :hours, :days, :weeks, :months, :years]
|
6
6
|
|
7
7
|
attr_accessor :distance, :smallest, :largest, :from_time, :to_time
|
8
8
|
|
@@ -10,7 +10,7 @@ module DOTIW
|
|
10
10
|
self.output = ActiveSupport::OrderedHash.new
|
11
11
|
self.options = options
|
12
12
|
self.distance = distance
|
13
|
-
self.from_time = from_time || Time.
|
13
|
+
self.from_time = from_time || Time.current
|
14
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
16
|
self.to_time += 1.hour if @to_time_not_given && self.smallest.dst? && !self.largest.dst?
|
@@ -48,10 +48,12 @@ module DOTIW
|
|
48
48
|
build_minutes
|
49
49
|
elsif distance < 1.day
|
50
50
|
build_hours
|
51
|
-
elsif distance <
|
51
|
+
elsif distance < 7.days
|
52
52
|
build_days
|
53
|
-
|
54
|
-
|
53
|
+
elsif distance < 28.days
|
54
|
+
build_weeks
|
55
|
+
else # greater than a week
|
56
|
+
build_years_months_weeks_days
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -76,28 +78,46 @@ module DOTIW
|
|
76
78
|
output[:days], self.distance = distance.divmod(1.day) if output[:days].nil?
|
77
79
|
end
|
78
80
|
|
81
|
+
def build_weeks
|
82
|
+
output[:weeks], self.distance = distance.divmod(1.week) if output[:weeks].nil?
|
83
|
+
end
|
84
|
+
|
79
85
|
def build_months
|
80
|
-
|
86
|
+
build_years_months_weeks_days
|
81
87
|
|
82
88
|
if (years = output.delete(:years)) > 0
|
83
89
|
output[:months] += (years * 12)
|
84
90
|
end
|
85
91
|
end
|
86
92
|
|
87
|
-
def
|
93
|
+
def build_years_months_weeks_days
|
88
94
|
months = (largest.year - smallest.year) * 12 + (largest.month - smallest.month)
|
89
95
|
years, months = months.divmod(12)
|
90
96
|
|
91
97
|
days = largest.day - smallest.day
|
92
98
|
|
99
|
+
weeks, days = days.divmod(7)
|
100
|
+
|
93
101
|
# Will otherwise incorrectly say one more day if our range goes over a day.
|
94
102
|
days -= 1 if largest.hour < smallest.hour
|
95
103
|
|
96
104
|
if days < 0
|
97
|
-
# Convert
|
105
|
+
# Convert a week to days and add to total
|
106
|
+
weeks -= 1
|
107
|
+
days += 7
|
108
|
+
end
|
109
|
+
|
110
|
+
if weeks < 0
|
111
|
+
# Convert the last month to a week and add to total
|
98
112
|
months -= 1
|
99
113
|
last_month = largest.advance(:months => -1)
|
100
|
-
|
114
|
+
days_in_month = Time.days_in_month(last_month.month, last_month.year)
|
115
|
+
weeks += days_in_month / 7
|
116
|
+
days += days_in_month % 7
|
117
|
+
if days >= 7
|
118
|
+
days -= 7
|
119
|
+
weeks += 1
|
120
|
+
end
|
101
121
|
end
|
102
122
|
|
103
123
|
if months < 0
|
@@ -108,6 +128,7 @@ module DOTIW
|
|
108
128
|
|
109
129
|
output[:years] = years
|
110
130
|
output[:months] = months
|
131
|
+
output[:weeks] = weeks
|
111
132
|
output[:days] = days
|
112
133
|
|
113
134
|
total_days, self.distance = distance.abs.divmod(1.day)
|
data/lib/dotiw/version.rb
CHANGED
data/spec/lib/dotiw_spec.rb
CHANGED
@@ -23,8 +23,9 @@ describe "A better distance_of_time_in_words" do
|
|
23
23
|
[10.minutes.to_i, "10 minutes"],
|
24
24
|
[1.hour.to_i, "1 hour"],
|
25
25
|
[1.hour + 30.seconds, "1 hour and 30 seconds"],
|
26
|
-
[4.weeks.to_i, "
|
27
|
-
[
|
26
|
+
[4.weeks.to_i, "4 weeks"],
|
27
|
+
[4.weeks + 2.days, "4 weeks and 2 days"],
|
28
|
+
[24.weeks.to_i, "5 months, 2 weeks, and 1 day"]
|
28
29
|
]
|
29
30
|
fragments.each do |number, result|
|
30
31
|
it "#{number} == #{result}" do
|
@@ -38,7 +39,7 @@ describe "A better distance_of_time_in_words" do
|
|
38
39
|
expect(distance_of_time(2.5.hours + 30.seconds, except: 'seconds')).to eq("2 hours and 30 minutes")
|
39
40
|
end
|
40
41
|
|
41
|
-
it "except:seconds
|
42
|
+
it "except:seconds has higher precedence than include_seconds:true" do
|
42
43
|
expect(distance_of_time(1.2.minute, include_seconds: true, except: 'seconds')).to eq('1 minute')
|
43
44
|
end
|
44
45
|
end
|
@@ -48,7 +49,7 @@ describe "A better distance_of_time_in_words" do
|
|
48
49
|
describe "hash version" do
|
49
50
|
describe "giving correct numbers of" do
|
50
51
|
|
51
|
-
[:years, :months, :days, :minutes, :seconds].each do |name|
|
52
|
+
[:years, :months, :weeks, :days, :minutes, :seconds].each do |name|
|
52
53
|
describe name do
|
53
54
|
it "exactly" do
|
54
55
|
hash = distance_of_time_in_words_hash(START_TIME, START_TIME + 1.send(name))
|
@@ -64,13 +65,14 @@ describe "A better distance_of_time_in_words" do
|
|
64
65
|
|
65
66
|
it "should be happy with lots of measurements" do
|
66
67
|
hash = distance_of_time_in_words_hash(START_TIME,
|
67
|
-
START_TIME + 1.year + 2.months + 3.
|
68
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds)
|
68
69
|
expect(hash[:years]).to eq(1)
|
69
70
|
expect(hash[:months]).to eq(2)
|
70
|
-
expect(hash[:
|
71
|
-
expect(hash[:
|
72
|
-
expect(hash[:
|
73
|
-
expect(hash[:
|
71
|
+
expect(hash[:weeks]).to eq(3)
|
72
|
+
expect(hash[:days]).to eq(4)
|
73
|
+
expect(hash[:hours]).to eq(5)
|
74
|
+
expect(hash[:minutes]).to eq(6)
|
75
|
+
expect(hash[:seconds]).to eq(7)
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
@@ -91,14 +93,14 @@ describe "A better distance_of_time_in_words" do
|
|
91
93
|
[START_TIME, START_TIME + 1.minute, "1 minute"],
|
92
94
|
[START_TIME, START_TIME + 3.years, "3 years"],
|
93
95
|
[START_TIME, START_TIME + 10.years, "10 years"],
|
94
|
-
[START_TIME, START_TIME +
|
96
|
+
[START_TIME, START_TIME + 8.months, "8 months"],
|
95
97
|
[START_TIME, START_TIME + 3.hour, "3 hours"],
|
96
98
|
[START_TIME, START_TIME + 13.months, "1 year and 1 month"],
|
97
99
|
# Any numeric sequence is merely coincidental.
|
98
|
-
[START_TIME, START_TIME + 1.year + 2.months + 3.
|
100
|
+
[START_TIME, START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds, "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"],
|
99
101
|
["2009-3-16".to_time, "2008-4-14".to_time, "11 months and 2 days"],
|
100
102
|
["2009-3-16".to_time + 1.minute, "2008-4-14".to_time, "11 months, 2 days, and 1 minute"],
|
101
|
-
["2009-4-14".to_time, "2008-3-16".to_time, "1 year and
|
103
|
+
["2009-4-14".to_time, "2008-3-16".to_time, "1 year, 4 weeks, and 1 day"],
|
102
104
|
["2009-2-01".to_time, "2009-3-01".to_time, "1 month"],
|
103
105
|
["2008-2-01".to_time, "2008-3-01".to_time, "1 month"]
|
104
106
|
]
|
@@ -126,10 +128,14 @@ describe "A better distance_of_time_in_words" do
|
|
126
128
|
START_TIME + 2.day + 10000.hour + 10.second,
|
127
129
|
:days,
|
128
130
|
"418 days, 16 hours, and 10 seconds"],
|
131
|
+
[START_TIME,
|
132
|
+
START_TIME + 2.day + 10000.hour + 10.second,
|
133
|
+
:weeks,
|
134
|
+
"59 weeks, 5 days, 16 hours, and 10 seconds"],
|
129
135
|
[START_TIME,
|
130
136
|
START_TIME + 2.day + 10000.hour + 10.second,
|
131
137
|
:months,
|
132
|
-
"13 months,
|
138
|
+
"13 months, 3 weeks, 1 day, 16 hours, and 10 seconds"],
|
133
139
|
["2015-1-15".to_time, "2016-3-15".to_time, :months, "14 months"]
|
134
140
|
|
135
141
|
]
|
@@ -148,8 +154,9 @@ describe "A better distance_of_time_in_words" do
|
|
148
154
|
[5.minutes.to_i, "5 minutes"],
|
149
155
|
[10.minutes.to_i, "10 minutes"],
|
150
156
|
[1.hour.to_i, "1 hour"],
|
151
|
-
[
|
152
|
-
[
|
157
|
+
[6.days.to_i, "6 days"],
|
158
|
+
[4.weeks.to_i, "4 weeks"],
|
159
|
+
[24.weeks.to_i, "5 months, 2 weeks, and 1 day"]
|
153
160
|
]
|
154
161
|
fragments.each do |start, output|
|
155
162
|
it "should be #{output}" do
|
@@ -164,9 +171,9 @@ describe "A better distance_of_time_in_words" do
|
|
164
171
|
fragments = [
|
165
172
|
# Any numeric sequence is merely coincidental.
|
166
173
|
[START_TIME,
|
167
|
-
START_TIME + 1.year + 2.months + 3.
|
174
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
168
175
|
{ :words_connector => " - " },
|
169
|
-
"1 year - 2 months - 3
|
176
|
+
"1 year - 2 months - 3 weeks - 4 days - 5 hours - 6 minutes, and 7 seconds"],
|
170
177
|
[START_TIME,
|
171
178
|
START_TIME + 5.minutes + 6.seconds,
|
172
179
|
{ :two_words_connector => " - " },
|
@@ -191,25 +198,25 @@ describe "A better distance_of_time_in_words" do
|
|
191
198
|
{ :only => ["minutes", "hours"]},
|
192
199
|
"1 hour and 1 minute"],
|
193
200
|
[START_TIME,
|
194
|
-
START_TIME + 1.year + 2.months + 3.
|
201
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
195
202
|
{ :vague => true },
|
196
203
|
"about 1 year"],
|
197
204
|
[START_TIME,
|
198
|
-
START_TIME + 1.year + 2.months + 3.
|
205
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
199
206
|
{ :vague => "Yes please" },
|
200
207
|
"about 1 year"],
|
201
208
|
[START_TIME,
|
202
|
-
START_TIME + 1.year + 2.months + 3.
|
209
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
203
210
|
{ :vague => false },
|
204
|
-
"1 year, 2 months, 3
|
211
|
+
"1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"],
|
205
212
|
[START_TIME,
|
206
|
-
START_TIME + 1.year + 2.months + 3.
|
213
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
207
214
|
{ :vague => nil },
|
208
|
-
"1 year, 2 months, 3
|
215
|
+
"1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"],
|
209
216
|
[START_TIME,
|
210
|
-
START_TIME + 1.year + 2.months + 3.
|
217
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
211
218
|
{ :except => "minutes" },
|
212
|
-
"1 year, 2 months, 3
|
219
|
+
"1 year, 2 months, 3 weeks, 4 days, 5 hours, and 7 seconds"],
|
213
220
|
[START_TIME,
|
214
221
|
START_TIME + 1.hour + 2.minutes + 3.seconds,
|
215
222
|
{ :highest_measure_only => true },
|
@@ -225,7 +232,7 @@ describe "A better distance_of_time_in_words" do
|
|
225
232
|
[START_TIME,
|
226
233
|
START_TIME + 2.year + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
227
234
|
{ :highest_measures => 2 },
|
228
|
-
"2 years and
|
235
|
+
"2 years and 3 weeks"],
|
229
236
|
[START_TIME,
|
230
237
|
START_TIME + 4.days + 6.minutes + 7.seconds,
|
231
238
|
{ :highest_measures => 3 },
|
@@ -233,7 +240,7 @@ describe "A better distance_of_time_in_words" do
|
|
233
240
|
[START_TIME,
|
234
241
|
START_TIME + 1.year + 2.weeks,
|
235
242
|
{ :highest_measures => 3 },
|
236
|
-
"1 year and
|
243
|
+
"1 year and 2 weeks"],
|
237
244
|
[START_TIME,
|
238
245
|
START_TIME + 1.days,
|
239
246
|
{ :only => [:years, :months] },
|
@@ -260,8 +267,8 @@ describe "A better distance_of_time_in_words" do
|
|
260
267
|
|
261
268
|
it "removes seconds in all other cases" do
|
262
269
|
expect(distance_of_time_in_words(START_TIME,
|
263
|
-
START_TIME + 1.year + 2.months + 3.
|
264
|
-
false)).to eq("1 year, 2 months, 3
|
270
|
+
START_TIME + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds,
|
271
|
+
false)).to eq("1 year, 2 months, 3 weeks, 4 days, 5 hours, and 6 minutes")
|
265
272
|
end
|
266
273
|
end # include_seconds
|
267
274
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotiw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
|
+
- Lauran Jansen
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: actionpack
|
@@ -94,14 +95,23 @@ dependencies:
|
|
94
95
|
- - ">="
|
95
96
|
- !ruby/object:Gem::Version
|
96
97
|
version: '0'
|
97
|
-
description:
|
98
|
-
|
98
|
+
description: |-
|
99
|
+
dotiw is a gem for Rails that overrides the
|
100
|
+
default distance_of_time_in_words and provides
|
101
|
+
a more accurate output. Do you crave accuracy
|
102
|
+
down to the second? So do I. That's why I made
|
103
|
+
this gem. - Ryan
|
104
|
+
email:
|
105
|
+
- radarlistener@gmail.com
|
106
|
+
- github@lauranjansen.com
|
99
107
|
executables: []
|
100
108
|
extensions: []
|
101
109
|
extra_rdoc_files: []
|
102
110
|
files:
|
103
111
|
- ".gitignore"
|
104
112
|
- ".travis.yml"
|
113
|
+
- CHANGELOG.md
|
114
|
+
- CONTRIBUTING.md
|
105
115
|
- Gemfile
|
106
116
|
- MIT-LICENSE
|
107
117
|
- README.markdown
|
@@ -109,21 +119,26 @@ files:
|
|
109
119
|
- dotiw.gemspec
|
110
120
|
- lib/dotiw.rb
|
111
121
|
- lib/dotiw/action_view_ext/helpers/date_helper.rb
|
122
|
+
- lib/dotiw/locale/da.yml
|
112
123
|
- lib/dotiw/locale/de.yml
|
113
124
|
- lib/dotiw/locale/en.yml
|
114
125
|
- lib/dotiw/locale/es.yml
|
126
|
+
- lib/dotiw/locale/fr.yml
|
127
|
+
- lib/dotiw/locale/id.yml
|
115
128
|
- lib/dotiw/locale/it.yml
|
116
129
|
- lib/dotiw/locale/ja.yml
|
117
130
|
- lib/dotiw/locale/nb.yml
|
118
131
|
- lib/dotiw/locale/nl.yml
|
119
132
|
- lib/dotiw/locale/pl.yml
|
133
|
+
- lib/dotiw/locale/pt-BR.yml
|
120
134
|
- lib/dotiw/locale/ru.yml
|
121
135
|
- lib/dotiw/time_hash.rb
|
122
136
|
- lib/dotiw/version.rb
|
123
137
|
- spec/lib/dotiw_spec.rb
|
124
138
|
- spec/spec_helper.rb
|
125
|
-
homepage:
|
126
|
-
licenses:
|
139
|
+
homepage: https://github.com/radar/dotiw
|
140
|
+
licenses:
|
141
|
+
- MIT
|
127
142
|
metadata: {}
|
128
143
|
post_install_message:
|
129
144
|
rdoc_options: []
|
@@ -141,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
156
|
version: '0'
|
142
157
|
requirements: []
|
143
158
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.5.1
|
145
160
|
signing_key:
|
146
161
|
specification_version: 4
|
147
162
|
summary: Better distance_of_time_in_words for Rails
|