dotiw 1.1.1 → 2.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 +7 -0
- data/.travis.yml +5 -0
- data/Gemfile +1 -1
- data/README.markdown +48 -46
- data/Rakefile +6 -7
- data/dotiw.gemspec +9 -7
- data/lib/dotiw.rb +21 -74
- data/lib/dotiw/action_view_ext/helpers/date_helper.rb +92 -0
- data/lib/dotiw/locale/en.yml +24 -0
- data/lib/dotiw/time_hash.rb +68 -67
- data/lib/dotiw/version.rb +1 -1
- data/spec/lib/dotiw_spec.rb +88 -68
- data/spec/spec_helper.rb +4 -6
- data/spec/translations/es.yml +23 -8
- metadata +100 -59
- data/init.rb +0 -3
- data/rails/init.rb +0 -1
- data/spec/translations/en.yml +0 -24
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7ac361d8ee4fa014e09e9f77026c08b4fecbe8c
|
4
|
+
data.tar.gz: 0dc62da9541e16dd15228c7659b502013cae5a49
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8effe0793345b5319dd18ccf19bb018c4940d1ffab22094e97490a951548f07e1b22c2273130f09a557ecaefe06572901b33b082d4b5940bd4ad50d0aea44ba4
|
7
|
+
data.tar.gz: b659b4568937f7dfc770dc271b9bdc894bd253c5008fed536f8d0aff65257e948d3ea9c45869365fac064020a5ef7a349ddbcdd9fcec56ca9be39be0684a91bc
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# dotiw
|
1
|
+
# dotiw [](https://travis-ci.org/radar/dotiw)
|
2
2
|
|
3
3
|
dotiw is a plugin 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 plugin. Take this for a totally kickass example:
|
4
4
|
|
@@ -23,11 +23,18 @@ The third argument for this method is whether or not to include seconds. By defa
|
|
23
23
|
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 1.second, true)
|
24
24
|
=> "1 year, and 1 second"
|
25
25
|
|
26
|
-
Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility"
|
26
|
+
Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility",
|
27
|
+
because that's just an insanely radical thing to do. \m/
|
27
28
|
|
28
|
-
The last argument is an optional options hash that can be used to manipulate behavior and (which uses `to_sentence`).
|
29
|
+
The last argument is an optional options hash that can be used to manipulate behavior and (which uses `to_sentence`).
|
29
30
|
|
30
|
-
|
31
|
+
Don't like having to pass in `Time.now` all the time? Then use `time_ago_in_words` which also will *rock your
|
32
|
+
world*:
|
33
|
+
|
34
|
+
>> time_ago_in_words(Time.now + 3.days + 1.second)
|
35
|
+
=> "3 days, and 1 second"
|
36
|
+
|
37
|
+
Oh, and did I mention it supports I18n? Oh yeah. Rock on!
|
31
38
|
|
32
39
|
### Options
|
33
40
|
|
@@ -35,7 +42,7 @@ Oh, and did I mention it supports I18n? Oh yeah.
|
|
35
42
|
|
36
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):
|
37
44
|
|
38
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, :locale =>
|
45
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, :locale => :es)
|
39
46
|
=> "1 minuto"
|
40
47
|
|
41
48
|
This will also be passed to `to_sentence`
|
@@ -44,57 +51,65 @@ This will also be passed to `to_sentence`
|
|
44
51
|
|
45
52
|
Specify this if you want it to use the old `distance_of_time_in_words`. The value can be anything except `nil` or `false`.
|
46
53
|
|
47
|
-
#### :singularize
|
48
|
-
|
49
|
-
Specify if all values of the hash should be presented in their singular form. By default they will be pluralized whenever outside the `-1..1` range. If you wish to have them signularized, just add the option `:singularize => :always`.
|
50
|
-
|
51
|
-
This option is useful for Russian and Icelandic folks (https://github.com/radar/dotiw/issues#issue/2).
|
52
|
-
|
53
|
-
>> distance_of_time_in_words(Time.now, Time.now + 2.hour + 2.minute, true, :singularize => :always)
|
54
|
-
=> "2 hour and 2 minute"
|
55
|
-
|
56
54
|
#### :accumulate_on
|
57
55
|
|
58
56
|
Specifies the maximum output unit which will accumulate all the surplus. Say you set it to seconds and your time difference is of 2 minutes then the output would be 120 seconds. Here's a code example:
|
59
57
|
|
60
|
-
>> distance_of_time_in_words(Time.now, Time.now + 2.
|
61
|
-
=> "121 minutes
|
58
|
+
>> distance_of_time_in_words(Time.now, Time.now + 2.hours + 70.seconds, true, :accumulate_on => :minutes)
|
59
|
+
=> "121 minutes and 10 seconds"
|
62
60
|
|
63
61
|
#### :only
|
64
62
|
|
65
|
-
**Note that values passed into this option must be passed in as strings!**
|
66
|
-
|
67
63
|
Only want a specific measurement of time? No problem!
|
68
64
|
|
69
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :only =>
|
65
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :only => :minutes)
|
70
66
|
=> "1 minute"
|
71
67
|
|
72
68
|
You only want some? No problem too!
|
73
69
|
|
74
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :only => [
|
70
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :only => [:minutes, :hours])
|
75
71
|
=> "1 hour and 1 minute"
|
76
72
|
|
77
73
|
#### :except
|
78
74
|
|
79
|
-
**Note that values passed into this option must be passed in as strings!**
|
80
|
-
|
81
75
|
Don't want a measurement of time? No problem!
|
82
76
|
|
83
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :except =>
|
77
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :except => :minutes)
|
84
78
|
=> "1 hour"
|
85
79
|
|
86
80
|
Culling a whole group of measurements of time:
|
87
81
|
|
88
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :except => [
|
82
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :except => [:minutes, :hours])
|
89
83
|
=> "1 day"
|
90
84
|
|
85
|
+
#### :highest\_measure\_only
|
86
|
+
|
87
|
+
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.
|
88
|
+
|
89
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :highest_measure_only => true)
|
90
|
+
=> "1 hour"
|
91
|
+
|
92
|
+
Notice how minutes and seconds were removed from the output. Another example:
|
93
|
+
|
94
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, :highest_measure_only => true)
|
95
|
+
=> "1 minute"
|
96
|
+
|
97
|
+
Minutes are the highest measure, so seconds were discarded from the output.
|
98
|
+
|
99
|
+
#### :highest\_measures
|
100
|
+
|
101
|
+
When you want variable precision from `DOTIW`:
|
102
|
+
|
103
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :highest_measures => 2)
|
104
|
+
=> "1 hour and 1 minute"
|
105
|
+
|
91
106
|
#### :words_connector
|
92
107
|
|
93
108
|
**This is an option for `to_sentence`, defaults to ', '**
|
94
109
|
|
95
110
|
Using something other than a comma:
|
96
111
|
|
97
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true,
|
112
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :words_connector => ' - ')
|
98
113
|
=> "1 hour - 1 minute, and 1 second"
|
99
114
|
|
100
115
|
#### :two\_words\_connector
|
@@ -103,7 +118,7 @@ Using something other than a comma:
|
|
103
118
|
|
104
119
|
Using something other than 'and':
|
105
120
|
|
106
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, true,
|
121
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, true, :two_words_connector => ' plus ')
|
107
122
|
=> "1 hour plus 1 minute"
|
108
123
|
|
109
124
|
#### :last\_word\_connector
|
@@ -112,23 +127,9 @@ Using something other than 'and':
|
|
112
127
|
|
113
128
|
Using something other than ', and':
|
114
129
|
|
115
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true,
|
130
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :last_word_connector => ', finally ')
|
116
131
|
=> "1 hour, 1 minute, finally 1 second"
|
117
132
|
|
118
|
-
#### :highest\_measure\_only
|
119
|
-
|
120
|
-
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.
|
121
|
-
|
122
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, { :highest_measure_only => true })
|
123
|
-
=> "1 hour"
|
124
|
-
|
125
|
-
Notice how minutes and seconds were removed from the output. Another example:
|
126
|
-
|
127
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, { :highest_measure_only => true })
|
128
|
-
=> "1 minute"
|
129
|
-
|
130
|
-
Minutes are the highest measure, so seconds were discarded from the output.
|
131
|
-
|
132
133
|
## distance\_of\_time
|
133
134
|
|
134
135
|
If you have simply a number of seconds you can get the "stringified" version of this by using `distance_of_time`:
|
@@ -141,19 +142,20 @@ If you have simply a number of seconds you can get the "stringified" version of
|
|
141
142
|
Don't like any format you're given? That's cool too! Here, have an indifferent hash version:
|
142
143
|
|
143
144
|
>> distance_of_time_in_words_hash(Time.now, Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds)
|
144
|
-
=> {
|
145
|
+
=> {:days => 3, :seconds => 6, :minutes => 5, :years => 1, :hours => 4, :months => 2}
|
145
146
|
|
146
147
|
Indifferent means that you can access all keys by their `String` or `Symbol` version.
|
147
148
|
|
148
149
|
## distance\_of\_time\_in\_percent
|
149
150
|
|
150
|
-
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`]
|
151
|
+
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).
|
151
152
|
|
152
153
|
distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time, options)
|
153
154
|
|
154
155
|
|
155
156
|
## Contributors
|
156
157
|
|
157
|
-
* [chendo]
|
158
|
-
* [Derander]
|
159
|
-
* [DBA]
|
158
|
+
* [chendo](http://github.com/chendo) - for talking through it with me and drawing on the whiteboard
|
159
|
+
* [Derander](http://github.com/derander) - correct Spanish translations
|
160
|
+
* [DBA](http://github.com/dba) - commits leading up to the 0.7 release
|
161
|
+
* [Sija](http://github.com/Sija) - rails 4 support, v2.0 release
|
data/Rakefile
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'bundler'
|
4
|
+
|
5
|
+
require 'rspec/core'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
4
8
|
Bundler::GemHelper.install_tasks
|
5
9
|
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
11
|
|
7
|
-
|
8
|
-
require 'rspec/core/rake_task'
|
9
|
-
[:spec, :rcov].each { |task| RSpec::Core::RakeTask.new(task) }
|
10
|
-
task :default => :spec
|
11
|
-
rescue LoadError
|
12
|
-
raise 'RSpec could not be loaded. Run `bundle install` to get all development dependencies.'
|
13
|
-
end
|
12
|
+
task :default => :spec
|
data/dotiw.gemspec
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
# dotiw.gemspec
|
2
2
|
# -*- encoding: utf-8 -*-
|
3
3
|
|
4
|
-
$:.
|
4
|
+
$:.push File.expand_path("../lib", __FILE__)
|
5
5
|
require 'dotiw/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'dotiw'
|
9
9
|
s.version = DOTIW::VERSION
|
10
|
-
|
11
|
-
s.required_rubygems_version = '>= 1.3.6'
|
10
|
+
|
12
11
|
s.authors = ["Ryan Bigg"]
|
13
12
|
s.date = %q{2010-12-23}
|
14
13
|
s.description = "Better distance_of_time_in_words for Rails"
|
15
14
|
s.summary = "Better distance_of_time_in_words for Rails"
|
16
15
|
s.email = "radarlistener@gmail.com"
|
17
16
|
|
18
|
-
s.add_dependency "actionpack", "
|
19
|
-
|
20
|
-
|
21
|
-
s.add_development_dependency "
|
17
|
+
s.add_dependency "actionpack", ">= 3"
|
18
|
+
s.add_dependency "i18n"
|
19
|
+
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "bundler"
|
22
|
+
s.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
s.add_development_dependency "tzinfo"
|
22
24
|
|
23
25
|
s.files = `git ls-files`.split("\n")
|
24
26
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/dotiw.rb
CHANGED
@@ -1,83 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'i18n'
|
4
|
+
|
5
|
+
# Rails hacks
|
6
|
+
if defined?(ActionView::Helpers)
|
7
|
+
require 'dotiw/action_view_ext/helpers/date_helper'
|
8
|
+
end
|
9
|
+
|
3
10
|
module DOTIW
|
11
|
+
extend self
|
12
|
+
|
4
13
|
autoload :VERSION, 'dotiw/version'
|
5
14
|
autoload :TimeHash, 'dotiw/time_hash'
|
6
|
-
end # DOTIW
|
7
|
-
|
8
|
-
module ActionView
|
9
|
-
module Helpers
|
10
|
-
module DateHelper
|
11
|
-
alias_method :old_distance_of_time_in_words, :distance_of_time_in_words
|
12
|
-
|
13
|
-
def distance_of_time_in_words_hash(from_time, to_time, options = {})
|
14
|
-
from_time = from_time.to_time if !from_time.is_a?(Time) && from_time.respond_to?(:to_time)
|
15
|
-
to_time = to_time.to_time if !to_time.is_a?(Time) && to_time.respond_to?(:to_time)
|
16
|
-
|
17
|
-
DOTIW::TimeHash.new((from_time - to_time).abs, from_time, to_time, options).to_hash
|
18
|
-
end
|
19
|
-
|
20
|
-
def distance_of_time(seconds, options = {})
|
21
|
-
display_time_in_words DOTIW::TimeHash.new(seconds).to_hash, options
|
22
|
-
end
|
23
|
-
|
24
|
-
def distance_of_time_in_words(from_time, to_time, include_seconds = false, options = {})
|
25
|
-
return old_distance_of_time_in_words(from_time, to_time, include_seconds, options) if options.delete(:vague)
|
26
|
-
hash = distance_of_time_in_words_hash(from_time, to_time, options)
|
27
|
-
display_time_in_words(hash, include_seconds, 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
15
|
|
37
|
-
|
38
|
-
def display_time_in_words(hash, include_seconds = false, options = {})
|
39
|
-
options.symbolize_keys!
|
40
|
-
I18n.locale = options[:locale] if options[:locale]
|
16
|
+
DEFAULT_I18N_SCOPE = :'datetime.dotiw'
|
41
17
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
time_measurements[:days] = I18n.t(:days, :default => "days")
|
47
|
-
time_measurements[:hours] = I18n.t(:hours, :default => "hours")
|
48
|
-
time_measurements[:minutes] = I18n.t(:minutes, :default => "minutes")
|
49
|
-
time_measurements[:seconds] = I18n.t(:seconds, :default => "seconds")
|
18
|
+
def init_i18n
|
19
|
+
I18n.load_path.unshift(*locale_files)
|
20
|
+
I18n.reload!
|
21
|
+
end
|
50
22
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
options.delete(:except)
|
60
|
-
options.delete(:only)
|
61
|
-
|
62
|
-
output = []
|
63
|
-
|
64
|
-
time_measurements = Hash[*time_measurements.first] if options.delete(:highest_measure_only)
|
65
|
-
|
66
|
-
time_measurements.each do |measure, key|
|
67
|
-
name = options[:singularize] == :always || hash[key].between?(-1, 1) ? key.singularize : key
|
68
|
-
output += ["#{hash[key]} #{name}"]
|
69
|
-
end
|
70
|
-
|
71
|
-
options.delete(:singularize)
|
72
|
-
|
73
|
-
# maybe only grab the first few values
|
74
|
-
if options[:precision]
|
75
|
-
output = output[0...options[:precision]]
|
76
|
-
options.delete(:precision)
|
77
|
-
end
|
23
|
+
protected
|
24
|
+
# Returns all locale files shipped with library
|
25
|
+
def locale_files
|
26
|
+
Dir[File.join(File.dirname(__FILE__), 'dotiw', 'locale', '**/*')]
|
27
|
+
end
|
28
|
+
end # DOTIW
|
78
29
|
|
79
|
-
|
80
|
-
end
|
81
|
-
end # DateHelper
|
82
|
-
end # Helpers
|
83
|
-
end # ActionView
|
30
|
+
DOTIW.init_i18n
|
@@ -0,0 +1,92 @@
|
|
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((from_time - to_time).abs, 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_s) if options[:except]
|
53
|
+
options[:only] = Array.wrap(options[:only]).map!(&:to_s) 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.to_s)) ||
|
59
|
+
(options[:only] && !options[:only].include?(key.to_s))
|
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
|
+
|
66
|
+
i18n_scope = options.delete(:scope) || DOTIW::DEFAULT_I18N_SCOPE
|
67
|
+
output = []
|
68
|
+
I18n.with_options :locale => options[:locale], :scope => i18n_scope do |locale|
|
69
|
+
output = hash.map { |key, value| locale.t(key, :count => value) }
|
70
|
+
end
|
71
|
+
|
72
|
+
highest_measures = options.delete(:highest_measures)
|
73
|
+
highest_measures = 1 if options.delete(:highest_measure_only)
|
74
|
+
if highest_measures
|
75
|
+
output = output[0...highest_measures]
|
76
|
+
end
|
77
|
+
|
78
|
+
options[:words_connector] ||= I18n.translate :'datetime.dotiw.words_connector',
|
79
|
+
:default => :'support.array.words_connector',
|
80
|
+
:locale => options[:locale]
|
81
|
+
options[:two_words_connector] ||= I18n.translate :'datetime.dotiw.two_words_connector',
|
82
|
+
:default => :'support.array.two_words_connector',
|
83
|
+
:locale => options[:locale]
|
84
|
+
options[:last_word_connector] ||= I18n.translate :'datetime.dotiw.last_word_connector',
|
85
|
+
:default => :'support.array.last_word_connector',
|
86
|
+
:locale => options[:locale]
|
87
|
+
|
88
|
+
output.to_sentence(options)
|
89
|
+
end
|
90
|
+
end # DateHelper
|
91
|
+
end # Helpers
|
92
|
+
end # ActionView
|
@@ -0,0 +1,24 @@
|
|
1
|
+
en:
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: 1 second
|
6
|
+
other: "%{count} seconds"
|
7
|
+
minutes:
|
8
|
+
one: 1 minute
|
9
|
+
other: "%{count} minutes"
|
10
|
+
hours:
|
11
|
+
one: 1 hour
|
12
|
+
other: "%{count} hours"
|
13
|
+
days:
|
14
|
+
one: 1 day
|
15
|
+
other: "%{count} days"
|
16
|
+
weeks:
|
17
|
+
one: 1 week
|
18
|
+
other: "%{count} weeks"
|
19
|
+
months:
|
20
|
+
one: 1 month
|
21
|
+
other: "%{count} months"
|
22
|
+
years:
|
23
|
+
one: 1 year
|
24
|
+
other: "%{count} years"
|
data/lib/dotiw/time_hash.rb
CHANGED
@@ -4,18 +4,16 @@ module DOTIW
|
|
4
4
|
class TimeHash
|
5
5
|
TIME_FRACTIONS = [:seconds, :minutes, :hours, :days, :months, :years]
|
6
6
|
|
7
|
-
attr_accessor :distance, :smallest, :largest, :from_time, :to_time
|
7
|
+
attr_accessor :distance, :smallest, :largest, :from_time, :to_time
|
8
8
|
|
9
9
|
def initialize(distance, from_time = nil, to_time = nil, options = {})
|
10
|
-
self.output =
|
10
|
+
self.output = ActiveSupport::OrderedHash.new
|
11
11
|
self.options = options
|
12
12
|
self.distance = distance
|
13
13
|
self.from_time = from_time || Time.now
|
14
14
|
self.to_time = to_time || (self.from_time + self.distance.seconds)
|
15
15
|
self.smallest, self.largest = [self.from_time, self.to_time].minmax
|
16
16
|
|
17
|
-
I18n.locale = options[:locale] if options[:locale]
|
18
|
-
|
19
17
|
build_time_hash
|
20
18
|
end
|
21
19
|
|
@@ -23,84 +21,87 @@ module DOTIW
|
|
23
21
|
output
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
24
|
+
private
|
25
|
+
attr_accessor :options, :output
|
26
|
+
|
27
|
+
def build_time_hash
|
28
|
+
if accumulate_on = options.delete(:accumulate_on)
|
29
|
+
accumulate_on = accumulate_on.to_sym
|
30
|
+
if accumulate_on == :years
|
31
|
+
return build_time_hash
|
32
|
+
end
|
33
|
+
TIME_FRACTIONS.index(accumulate_on).downto(0) { |i| self.send("build_#{TIME_FRACTIONS[i]}") }
|
34
|
+
else
|
35
|
+
while distance > 0
|
36
|
+
if distance < 1.minute
|
37
|
+
build_seconds
|
38
|
+
elsif distance < 1.hour
|
39
|
+
build_minutes
|
40
|
+
elsif distance < 1.day
|
41
|
+
build_hours
|
42
|
+
elsif distance < 28.days
|
43
|
+
build_days
|
44
|
+
else # greater than a month
|
45
|
+
build_years_months_days
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
|
-
output
|
50
48
|
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
self.distance = 0
|
55
|
-
end
|
50
|
+
output
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
53
|
+
def build_seconds
|
54
|
+
output[:seconds] = distance.to_i
|
55
|
+
self.distance = 0
|
56
|
+
end
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
58
|
+
def build_minutes
|
59
|
+
output[:minutes], self.distance = distance.divmod(1.minute)
|
60
|
+
end
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
def build_hours
|
63
|
+
output[:hours], self.distance = distance.divmod(1.hour)
|
64
|
+
end
|
68
65
|
|
69
|
-
|
70
|
-
|
66
|
+
def build_days
|
67
|
+
output[:days], self.distance = distance.divmod(1.day)
|
68
|
+
end
|
71
69
|
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
def build_months
|
71
|
+
build_years_months_days
|
72
|
+
|
73
|
+
if (years = output.delete(:years)) > 0
|
74
|
+
output[:months] += (years * 12)
|
75
75
|
end
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
def build_years_months_days
|
79
|
+
months = (largest.year - smallest.year) * 12 + (largest.month - smallest.month)
|
80
|
+
years, months = months.divmod(12)
|
80
81
|
|
81
|
-
|
82
|
+
days = largest.day - smallest.day
|
82
83
|
|
83
|
-
|
84
|
-
|
84
|
+
# Will otherwise incorrectly say one more day if our range goes over a day.
|
85
|
+
days -= 1 if largest.hour < smallest.hour
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
if days < 0
|
88
|
+
# Convert the last month to days and add to total
|
89
|
+
months -= 1
|
90
|
+
last_month = largest.advance(:months => -1)
|
91
|
+
days += Time.days_in_month(last_month.month, last_month.year)
|
92
|
+
end
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
if months < 0
|
95
|
+
# Convert a year to months
|
96
|
+
years -= 1
|
97
|
+
months += 12
|
98
|
+
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
output[:years] = years
|
101
|
+
output[:months] = months
|
102
|
+
output[:days] = days
|
102
103
|
|
103
|
-
|
104
|
-
|
104
|
+
total_days, self.distance = (from_time - to_time).abs.divmod(1.day)
|
105
|
+
end
|
105
106
|
end # TimeHash
|
106
|
-
end # DOTIW
|
107
|
+
end # DOTIW
|
data/lib/dotiw/version.rb
CHANGED
data/spec/lib/dotiw_spec.rb
CHANGED
@@ -10,22 +10,38 @@ describe "A better distance_of_time_in_words" do
|
|
10
10
|
before do
|
11
11
|
I18n.locale = :en
|
12
12
|
time = "01-08-2009".to_time
|
13
|
-
Time.
|
14
|
-
Time.zone.
|
13
|
+
allow(Time).to receive(:now).and_return(time)
|
14
|
+
allow(Time.zone).to receive(:now).and_return(time)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "distance of time" do
|
18
|
-
[
|
18
|
+
fragments = [
|
19
|
+
[0.5.minutes, "30 seconds"],
|
20
|
+
[4.5.minutes, "4 minutes and 30 seconds"],
|
19
21
|
[5.minutes.to_i, "5 minutes"],
|
20
22
|
[10.minutes.to_i, "10 minutes"],
|
21
23
|
[1.hour.to_i, "1 hour"],
|
24
|
+
[1.hour + 30.seconds, "1 hour and 30 seconds"],
|
22
25
|
[4.weeks.to_i, "28 days"],
|
23
26
|
[24.weeks.to_i, "5 months and 15 days"]
|
24
|
-
]
|
27
|
+
]
|
28
|
+
fragments.each do |number, result|
|
25
29
|
it "#{number} == #{result}" do
|
26
|
-
distance_of_time(number).
|
30
|
+
expect(distance_of_time(number)).to eq(result)
|
27
31
|
end
|
28
32
|
end
|
33
|
+
|
34
|
+
describe "with options" do
|
35
|
+
it "except:seconds should skip seconds" do
|
36
|
+
expect(distance_of_time(1.2.minute, except: 'seconds')).to eq("1 minute")
|
37
|
+
expect(distance_of_time(2.5.hours + 30.seconds, except: 'seconds')).to eq("2 hours and 30 minutes")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "except:seconds har higher presedence than include_seconds:true" do
|
41
|
+
expect(distance_of_time(1.2.minute, include_seconds: true, except: 'seconds')).to eq('1 minute')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
29
45
|
end
|
30
46
|
|
31
47
|
describe "hash version" do
|
@@ -35,12 +51,12 @@ describe "A better distance_of_time_in_words" do
|
|
35
51
|
describe name do
|
36
52
|
it "exactly" do
|
37
53
|
hash = distance_of_time_in_words_hash(Time.now, Time.now + 1.send(name))
|
38
|
-
hash[name
|
54
|
+
expect(hash[name]).to eq(1)
|
39
55
|
end
|
40
56
|
|
41
57
|
it "two" do
|
42
58
|
hash = distance_of_time_in_words_hash(Time.now, Time.now + 2.send(name))
|
43
|
-
hash[name
|
59
|
+
expect(hash[name]).to eq(2)
|
44
60
|
end
|
45
61
|
end
|
46
62
|
end
|
@@ -48,47 +64,29 @@ describe "A better distance_of_time_in_words" do
|
|
48
64
|
it "should be happy with lots of measurements" do
|
49
65
|
hash = distance_of_time_in_words_hash(Time.now,
|
50
66
|
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds)
|
51
|
-
hash[
|
52
|
-
hash[
|
53
|
-
hash[
|
54
|
-
hash[
|
55
|
-
hash[
|
56
|
-
hash[
|
57
|
-
end
|
58
|
-
|
59
|
-
it "debe estar contento con las mediciones en español" do
|
60
|
-
hash = distance_of_time_in_words_hash(Time.now,
|
61
|
-
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
62
|
-
:locale => "es")
|
63
|
-
hash["años"].should eql(1)
|
64
|
-
hash["meses"].should eql(2)
|
65
|
-
hash["días"].should eql(3)
|
66
|
-
hash["horas"].should eql(4)
|
67
|
-
hash["minutos"].should eql(5)
|
68
|
-
hash["segundos"].should eql(6)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "debe hablar español" do
|
72
|
-
I18n.locale = :es
|
73
|
-
hash = distance_of_time_in_words_hash(Time.now, Time.now + 5.days)
|
74
|
-
hash["días"].should eql(5)
|
67
|
+
expect(hash[:years]).to eq(1)
|
68
|
+
expect(hash[:months]).to eq(2)
|
69
|
+
expect(hash[:days]).to eq(3)
|
70
|
+
expect(hash[:hours]).to eq(4)
|
71
|
+
expect(hash[:minutes]).to eq(5)
|
72
|
+
expect(hash[:seconds]).to eq(6)
|
75
73
|
end
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
79
77
|
describe "real version" do
|
80
78
|
it "debe hablar español" do
|
81
|
-
distance_of_time_in_words(Time.now, Time.now +
|
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")
|
82
81
|
end
|
83
82
|
|
84
|
-
[
|
83
|
+
fragments = [
|
85
84
|
[Time.now, Time.now + 5.days + 3.minutes, "5 days and 3 minutes"],
|
86
85
|
[Time.now, Time.now + 1.minute, "1 minute"],
|
87
86
|
[Time.now, Time.now + 3.years, "3 years"],
|
88
87
|
[Time.now, Time.now + 10.years, "10 years"],
|
88
|
+
[Time.now, Time.now + 10.years, "10 years"],
|
89
89
|
[Time.now, Time.now + 3.hour, "3 hours"],
|
90
|
-
# Need to be +1.day because it will output "1 year and 30 days" otherwise.
|
91
|
-
# Haven't investigated fully how this is caused.
|
92
90
|
[Time.now, Time.now + 13.months, "1 year and 1 month"],
|
93
91
|
# Any numeric sequence is merely coincidental.
|
94
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"],
|
@@ -97,14 +95,15 @@ describe "A better distance_of_time_in_words" do
|
|
97
95
|
["2009-4-14".to_time, "2008-3-16".to_time, "1 year and 29 days"],
|
98
96
|
["2009-2-01".to_time, "2009-3-01".to_time, "1 month"],
|
99
97
|
["2008-2-01".to_time, "2008-3-01".to_time, "1 month"]
|
100
|
-
]
|
98
|
+
]
|
99
|
+
fragments.each do |start, finish, output|
|
101
100
|
it "should be #{output}" do
|
102
|
-
distance_of_time_in_words(start, finish, true).
|
101
|
+
expect(distance_of_time_in_words(start, finish, true)).to eq(output)
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
105
|
describe "accumulate on" do
|
107
|
-
[
|
106
|
+
fragments = [
|
108
107
|
[Time.now,
|
109
108
|
Time.now + 10.minute,
|
110
109
|
:seconds,
|
@@ -124,21 +123,37 @@ describe "A better distance_of_time_in_words" do
|
|
124
123
|
[Time.now,
|
125
124
|
Time.now + 2.day + 10000.hour + 10.second,
|
126
125
|
:months,
|
127
|
-
"13 months, 16 hours, and 10 seconds"]
|
128
|
-
|
129
|
-
|
130
|
-
:years,
|
131
|
-
"1 year, 1 month, 22 days, 16 hours, and 10 seconds"]
|
132
|
-
].each do |start, finish, accumulator, output|
|
126
|
+
"13 months, 16 hours, and 10 seconds"]
|
127
|
+
]
|
128
|
+
fragments.each do |start, finish, accumulator, output|
|
133
129
|
it "should be #{output}" do
|
134
|
-
distance_of_time_in_words(start, finish, true, :accumulate_on => accumulator).
|
130
|
+
expect(distance_of_time_in_words(start, finish, true, :accumulate_on => accumulator)).to eq(output)
|
135
131
|
end
|
136
132
|
end
|
137
133
|
end # :accumulate_on
|
134
|
+
|
135
|
+
describe "without finish time" do
|
136
|
+
# A missing finish argument should default to zero, essentially returning
|
137
|
+
# the equivalent of distance_of_time in order to be backwards-compatible
|
138
|
+
# with the original rails distance_of_time_in_words helper.
|
139
|
+
fragments = [
|
140
|
+
[5.minutes.to_i, "5 minutes"],
|
141
|
+
[10.minutes.to_i, "10 minutes"],
|
142
|
+
[1.hour.to_i, "1 hour"],
|
143
|
+
[4.weeks.to_i, "28 days"],
|
144
|
+
[24.weeks.to_i, "5 months and 15 days"]
|
145
|
+
]
|
146
|
+
fragments.each do |start, output|
|
147
|
+
it "should be #{output}" do
|
148
|
+
expect(distance_of_time_in_words(start)).to eq(output)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
138
153
|
end
|
139
154
|
|
140
155
|
describe "with output options" do
|
141
|
-
[
|
156
|
+
fragments = [
|
142
157
|
# Any numeric sequence is merely coincidental.
|
143
158
|
[Time.now,
|
144
159
|
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
@@ -167,18 +182,6 @@ describe "A better distance_of_time_in_words" do
|
|
167
182
|
Time.now + 1.hour + 1.day + 1.minute,
|
168
183
|
{ :only => ["minutes", "hours"]},
|
169
184
|
"1 hour and 1 minute"],
|
170
|
-
[Time.now,
|
171
|
-
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
172
|
-
{ :precision => 2 },
|
173
|
-
"1 year and 2 months"],
|
174
|
-
[Time.now,
|
175
|
-
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
176
|
-
{ :precision => 3 },
|
177
|
-
"1 year, 2 months, and 3 days"],
|
178
|
-
[Time.now,
|
179
|
-
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
180
|
-
{ :precision => 10 },
|
181
|
-
"1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds"],
|
182
185
|
[Time.now,
|
183
186
|
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
184
187
|
{ :vague => true },
|
@@ -197,31 +200,48 @@ describe "A better distance_of_time_in_words" do
|
|
197
200
|
"1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds"],
|
198
201
|
[Time.now,
|
199
202
|
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
200
|
-
{
|
203
|
+
{ :except => "minutes" },
|
201
204
|
"1 year, 2 months, 3 days, 4 hours, and 6 seconds"],
|
202
205
|
[Time.now,
|
203
206
|
Time.now + 1.hour + 2.minutes + 3.seconds,
|
204
207
|
{ :highest_measure_only => true },
|
205
208
|
"1 hour"],
|
209
|
+
[Time.now,
|
210
|
+
Time.now + 1.hours + 2.minutes + 3.seconds,
|
211
|
+
{ :highest_measures => 1 },
|
212
|
+
"1 hour"],
|
206
213
|
[Time.now,
|
207
214
|
Time.now + 2.year + 3.months + 4.days + 5.hours + 6.minutes + 7.seconds,
|
208
|
-
{ :
|
209
|
-
"2
|
210
|
-
|
215
|
+
{ :highest_measures => 3 },
|
216
|
+
"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,
|
219
|
+
{ :highest_measures => 2 },
|
220
|
+
"2 years and 25 days"],
|
221
|
+
[Time.now,
|
222
|
+
Time.now + 4.days + 6.minutes + 7.seconds,
|
223
|
+
{ :highest_measures => 3 },
|
224
|
+
"4 days, 6 minutes, and 7 seconds"],
|
225
|
+
[Time.now,
|
226
|
+
Time.now + 1.year + 2.weeks,
|
227
|
+
{ :highest_measures => 3 },
|
228
|
+
"1 year and 14 days"]
|
229
|
+
]
|
230
|
+
fragments.each do |start, finish, options, output|
|
211
231
|
it "should be #{output}" do
|
212
|
-
distance_of_time_in_words(start, finish, true, options).
|
232
|
+
expect(distance_of_time_in_words(start, finish, true, options)).to eq(output)
|
213
233
|
end
|
214
234
|
end
|
215
235
|
|
216
236
|
describe "include_seconds" do
|
217
237
|
it "is ignored if only seconds have passed" do
|
218
|
-
distance_of_time_in_words(Time.now, Time.now + 1.second, false).
|
238
|
+
expect(distance_of_time_in_words(Time.now, Time.now + 1.second, false)).to eq("1 second")
|
219
239
|
end
|
220
240
|
|
221
241
|
it "removes seconds in all other cases" do
|
222
|
-
distance_of_time_in_words(Time.now,
|
242
|
+
expect(distance_of_time_in_words(Time.now,
|
223
243
|
Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds,
|
224
|
-
false).
|
244
|
+
false)).to eq("1 year, 2 months, 3 days, 4 hours, and 5 minutes")
|
225
245
|
end
|
226
246
|
end # include_seconds
|
227
247
|
end
|
@@ -232,11 +252,11 @@ describe "A better distance_of_time_in_words" do
|
|
232
252
|
end
|
233
253
|
|
234
254
|
it "calculates 15%" do
|
235
|
-
time_in_percent.
|
255
|
+
expect(time_in_percent).to eq("15%")
|
236
256
|
end
|
237
257
|
|
238
258
|
it "calculates 15.3%" do
|
239
|
-
time_in_percent(:precision => 1).
|
259
|
+
expect(time_in_percent(:precision => 1)).to eq("15.3%")
|
240
260
|
end
|
241
261
|
end
|
242
262
|
|
data/spec/spec_helper.rb
CHANGED
@@ -7,13 +7,11 @@ $:.unshift ROOT_PATH unless $:.include? ROOT_PATH
|
|
7
7
|
require 'erb'
|
8
8
|
|
9
9
|
require 'active_support/all'
|
10
|
+
require 'action_view'
|
10
11
|
|
11
|
-
require '
|
12
|
-
require 'action_view/helpers'
|
13
|
-
|
14
|
-
require 'init' # require dotiw through init (like a plugin would)
|
12
|
+
require 'dotiw'
|
15
13
|
|
16
14
|
Time.zone = 'UTC'
|
17
|
-
|
18
|
-
I18n.load_path << Dir[File.join(File.dirname(__FILE__),
|
15
|
+
|
16
|
+
I18n.load_path << Dir[File.join(File.dirname(__FILE__), 'translations', '*')]
|
19
17
|
I18n.locale = :en
|
data/spec/translations/es.yml
CHANGED
@@ -1,9 +1,24 @@
|
|
1
1
|
es:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
datetime:
|
3
|
+
dotiw:
|
4
|
+
seconds:
|
5
|
+
one: uno segundo
|
6
|
+
other: "%{count} segundos"
|
7
|
+
minutes:
|
8
|
+
one: uno minuto
|
9
|
+
other: "%{count} minutos"
|
10
|
+
hours:
|
11
|
+
one: una hora
|
12
|
+
other: "%{count} horas"
|
13
|
+
days:
|
14
|
+
one: un día
|
15
|
+
other: "%{count} días"
|
16
|
+
weeks:
|
17
|
+
one: una semana
|
18
|
+
other: "%{count} semanas"
|
19
|
+
months:
|
20
|
+
one: un mes
|
21
|
+
other: "%{count} meses"
|
22
|
+
years:
|
23
|
+
one: un año
|
24
|
+
other: "%{count} años"
|
metadata
CHANGED
@@ -1,103 +1,144 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotiw
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '2.0'
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Ryan Bigg
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2010-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
16
14
|
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
17
21
|
prerelease: false
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: i18n
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
24
34
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: bundler
|
28
35
|
prerelease: false
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
35
62
|
type: :development
|
36
|
-
|
37
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
38
70
|
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
39
77
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tzinfo
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
46
90
|
type: :development
|
47
|
-
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
48
97
|
description: Better distance_of_time_in_words for Rails
|
49
98
|
email: radarlistener@gmail.com
|
50
99
|
executables: []
|
51
|
-
|
52
100
|
extensions: []
|
53
|
-
|
54
101
|
extra_rdoc_files: []
|
55
|
-
|
56
|
-
|
57
|
-
- .
|
102
|
+
files:
|
103
|
+
- ".gitignore"
|
104
|
+
- ".travis.yml"
|
58
105
|
- Gemfile
|
59
106
|
- MIT-LICENSE
|
60
107
|
- README.markdown
|
61
108
|
- Rakefile
|
62
109
|
- dotiw.gemspec
|
63
|
-
- init.rb
|
64
110
|
- lib/dotiw.rb
|
111
|
+
- lib/dotiw/action_view_ext/helpers/date_helper.rb
|
112
|
+
- lib/dotiw/locale/en.yml
|
65
113
|
- lib/dotiw/time_hash.rb
|
66
114
|
- lib/dotiw/version.rb
|
67
|
-
- rails/init.rb
|
68
115
|
- spec/lib/dotiw_spec.rb
|
69
116
|
- spec/spec_helper.rb
|
70
|
-
- spec/translations/en.yml
|
71
117
|
- spec/translations/es.yml
|
72
118
|
homepage:
|
73
119
|
licenses: []
|
74
|
-
|
120
|
+
metadata: {}
|
75
121
|
post_install_message:
|
76
122
|
rdoc_options: []
|
77
|
-
|
78
|
-
require_paths:
|
123
|
+
require_paths:
|
79
124
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
|
82
|
-
requirements:
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
83
127
|
- - ">="
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version:
|
86
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
-
|
88
|
-
requirements:
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
89
132
|
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version:
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
92
135
|
requirements: []
|
93
|
-
|
94
136
|
rubyforge_project:
|
95
|
-
rubygems_version:
|
137
|
+
rubygems_version: 2.2.2
|
96
138
|
signing_key:
|
97
|
-
specification_version:
|
139
|
+
specification_version: 4
|
98
140
|
summary: Better distance_of_time_in_words for Rails
|
99
|
-
test_files:
|
141
|
+
test_files:
|
100
142
|
- spec/lib/dotiw_spec.rb
|
101
143
|
- spec/spec_helper.rb
|
102
|
-
- spec/translations/en.yml
|
103
144
|
- spec/translations/es.yml
|
data/init.rb
DELETED
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'dotiw'
|
data/spec/translations/en.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
en:
|
2
|
-
seconds: seconds
|
3
|
-
minutes: minutes
|
4
|
-
hours: hours
|
5
|
-
days: days
|
6
|
-
weeks: weeks
|
7
|
-
months: months
|
8
|
-
years: years
|
9
|
-
|
10
|
-
support:
|
11
|
-
array:
|
12
|
-
two_words_connector: " and "
|
13
|
-
words_connector: ", "
|
14
|
-
last_word_connector: ", and "
|
15
|
-
|
16
|
-
datetime:
|
17
|
-
distance_in_words:
|
18
|
-
about_x_years:
|
19
|
-
one: "about 1 year"
|
20
|
-
many: "about %{count} years"
|
21
|
-
|
22
|
-
number:
|
23
|
-
format:
|
24
|
-
separator: "."
|