dotiw 3.0.1 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +45 -0
- data/.gitignore +2 -1
- data/.rspec +2 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +29 -0
- data/CONTRIBUTING.md +34 -0
- data/Gemfile +2 -0
- data/MIT-LICENSE +1 -1
- data/README.markdown +139 -70
- data/Rakefile +3 -1
- data/dotiw.gemspec +22 -17
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4.gemfile +9 -0
- data/gemfiles/rails_5.0.gemfile +9 -0
- data/gemfiles/rails_5.1.gemfile +9 -0
- data/gemfiles/rails_5.2.gemfile +9 -0
- data/gemfiles/rails_6.0.gemfile +9 -0
- data/lib/dotiw.rb +31 -13
- data/lib/dotiw/action_view/helpers/date_helper.rb +24 -0
- data/lib/dotiw/locale/ar.yml +53 -0
- data/lib/dotiw/locale/da.yml +23 -0
- data/lib/dotiw/locale/fr.yml +25 -0
- data/lib/dotiw/locale/id.yml +25 -0
- data/lib/dotiw/locale/ko.yml +25 -0
- data/lib/dotiw/locale/pl.yml +7 -0
- data/lib/dotiw/locale/pt-BR.yml +25 -0
- data/lib/dotiw/locale/vi.yml +25 -0
- data/lib/dotiw/locale/zh-CN.yml +25 -0
- data/lib/dotiw/methods.rb +93 -0
- data/lib/dotiw/time_hash.rb +65 -38
- data/lib/dotiw/version.rb +2 -2
- data/spec/lib/dotiw_spec.rb +264 -159
- data/spec/lib/i18n/ar.yml +2 -0
- data/spec/lib/i18n/da.yml +2 -0
- data/spec/lib/i18n/de.yml +2 -0
- data/spec/lib/i18n/en.yml +2 -0
- data/spec/lib/i18n/es.yml +3 -0
- data/spec/lib/i18n/fr.yml +2 -0
- data/spec/lib/i18n/id.yml +2 -0
- data/spec/lib/i18n/it.yml +3 -0
- data/spec/lib/i18n/ja.yml +2 -0
- data/spec/lib/i18n/ko.yml +2 -0
- data/spec/lib/i18n/nb.yml +2 -0
- data/spec/lib/i18n/nl.yml +2 -0
- data/spec/lib/i18n/pl.yml +2 -0
- data/spec/lib/i18n/pt-BR.yml +2 -0
- data/spec/lib/i18n/ru.yml +5 -0
- data/spec/lib/i18n/vi.yml +22 -0
- data/spec/lib/i18n/zh-CN.yml +2 -0
- data/spec/spec_helper.rb +2 -9
- metadata +110 -21
- data/.travis.yml +0 -5
- data/lib/dotiw/action_view_ext/helpers/date_helper.rb +0 -103
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c3178c4c07b2647581895e344418e9ce40e3da5d9e3cc1fda714f9817b852e8
|
4
|
+
data.tar.gz: cef2e7944c792c501181789e3ed9f0155e12be6954e40664f495bcb298f40709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db64efc0d3189bca7be013a3faff83820392bcfc69bf111497ea3543d67eba53f3792f62e6c43b1d39b73a6d6fb32811b6ae4f511f04c19d069283cdd18f355
|
7
|
+
data.tar.gz: a9bae3a175fada3623c8275abec2052e377716db914dadd0b2908a33fbff67fa95191062cb37cb20d15a90478b61ddc9647140d04dc37f0be73fd44b833e7957
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- master
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
strategy:
|
15
|
+
fail-fast: false
|
16
|
+
matrix:
|
17
|
+
include:
|
18
|
+
- ruby-version: 2.5.x
|
19
|
+
- ruby-version: 2.6.x
|
20
|
+
- ruby-version: 2.4.x
|
21
|
+
bundler-version: 1.17.3
|
22
|
+
gemfile: gemfiles/rails_4.gemfile
|
23
|
+
- ruby-version: 2.6.x
|
24
|
+
gemfile: gemfiles/rails_5.0.gemfile
|
25
|
+
- ruby-version: 2.6.x
|
26
|
+
gemfile: gemfiles/rails_5.1.gemfile
|
27
|
+
- ruby-version: 2.6.x
|
28
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
29
|
+
- ruby-version: 2.6.x
|
30
|
+
gemfile: gemfiles/rails_6.0.gemfile
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v2
|
33
|
+
- name: Set up Ruby
|
34
|
+
uses: actions/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: ${{ matrix.ruby-version }}
|
37
|
+
- name: Build and test
|
38
|
+
env:
|
39
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
40
|
+
BUNDLER: ${{ matrix.bundler-version }}
|
41
|
+
run: |
|
42
|
+
gem uninstall bundler
|
43
|
+
gem install bundler -v ${BUNDLER:-2.1.4}
|
44
|
+
bundle install --jobs 4 --retry 3
|
45
|
+
bundle exec rake
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
appraise 'rails_4' do
|
2
|
+
gem 'rails', '~> 4.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise 'rails_5.0' do
|
6
|
+
gem 'rails', '~> 5.0.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'rails_5.1' do
|
10
|
+
gem 'rails', '~> 5.1.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'rails_5.2' do
|
14
|
+
gem 'rails', '~> 5.2.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise 'rails_6.0' do
|
18
|
+
gem 'rails', '~> 6.0.0'
|
19
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
## 5.1.0 (2020/08/05)
|
2
|
+
|
3
|
+
* [#111](https://github.com/radar/distance_of_time_in_words/pull/111): Fix: `NoMethodError` when calling `ActionController::Base.helpers.distance_of_time_in_words` - [@denisahearn](https://github.com/denisahearn).
|
4
|
+
* [#106](https://github.com/radar/distance_of_time_in_words/pull/106): Add Vietnamese language support - [@runlevel5 ](https://github.com/runlevel5).
|
5
|
+
|
6
|
+
## 5.0.0 (2020/05/07)
|
7
|
+
|
8
|
+
* [#105](https://github.com/radar/distance_of_time_in_words/pull/105): Support for Ruby w/o Rails - [@dblock](https://github.com/dblock).
|
9
|
+
* [#108](https://github.com/radar/distance_of_time_in_words/pull/108): Fix negative weeks - [@ivanovaleksey](https://github.com/ivanovaleksey).
|
10
|
+
|
11
|
+
## 4.0.1 (2018/06/01)
|
12
|
+
|
13
|
+
## 3.1.1 (2016/03/08)
|
14
|
+
|
15
|
+
## 3.1.0 (2016/03/07)
|
16
|
+
|
17
|
+
* [#68](https://github.com/radar/dotiw/pull/68): Add support for weeks - [@lauranjansen](https://github.com/lauranjansen).
|
18
|
+
* [#69](https://github.com/radar/dotiw/pull/69): Add Indonesian language support - [@avidmaulanas](https://github.com/avidmaulanas).
|
19
|
+
* [#70](https://github.com/radar/dotiw/pull/70): Add French language support - [@geo1004](https://github.com/geo1004).
|
20
|
+
* [#72](https://github.com/radar/dotiw/pull/72): Add Danish language support - [@kaspernj](https://github.com/kaspernj).
|
21
|
+
* [#71](https://github.com/radar/dotiw/pull/71): Update bundler and ruby versions for Travis CI - [@lauranjansen](https://github.com/lauranjansen).
|
22
|
+
|
23
|
+
## 3.0.1 (2015/04/09)
|
24
|
+
|
25
|
+
## 3.0 (2015/04/09)
|
26
|
+
|
27
|
+
## 0.2.4 (2009/10/18)
|
28
|
+
|
29
|
+
* Initial public release - [@radar](https://github.com/radar).
|
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/Gemfile
CHANGED
data/MIT-LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -1,54 +1,83 @@
|
|
1
|
-
# dotiw
|
1
|
+
# dotiw ![Ruby](https://github.com/radar/distance_of_time_in_words/workflows/Ruby/badge.svg)
|
2
2
|
|
3
|
-
dotiw
|
3
|
+
The `dotiw` library that adds `distance_of_time_in_words` to any Ruby project, or overrides the default implementation in Rails with more accurate output.
|
4
|
+
|
5
|
+
Do you crave accuracy down to the second? So do I. That's why I made this gem.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
Add to your `Gemfile`.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dotiw'
|
13
|
+
```
|
14
|
+
|
15
|
+
Run `bundle install`.
|
16
|
+
|
17
|
+
### Pure Ruby
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'dotiw'
|
21
|
+
|
22
|
+
include DOTIW::Methods
|
23
|
+
```
|
24
|
+
|
25
|
+
### Rails
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'dotiw'
|
29
|
+
|
30
|
+
include ActionView::Helpers::DateHelper
|
31
|
+
include ActionView::Helpers::TextHelper
|
32
|
+
include ActionView::Helpers::NumberHelper
|
33
|
+
```
|
34
|
+
|
35
|
+
## distance\_of\_time\_in\_words
|
36
|
+
|
37
|
+
Take this for a totally kick-ass example:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds, true)
|
41
|
+
=> "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"
|
42
|
+
```
|
4
43
|
|
5
|
-
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds, true)
|
6
|
-
=> "1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds"
|
7
|
-
|
8
44
|
Also if one of the measurement is zero it will not output it:
|
9
45
|
|
10
|
-
|
11
|
-
|
12
|
-
|
46
|
+
```ruby
|
47
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 5.hours + 6.minutes + 7.seconds, true)
|
48
|
+
=> "1 year, 2 months, 4 days, 6 minutes, and 7 seconds"
|
49
|
+
```
|
50
|
+
|
13
51
|
Better than "about 1 year", am I right? Of course I am.
|
14
52
|
|
15
53
|
"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?"
|
16
54
|
"No!" I triumphantly reply:
|
17
55
|
|
18
|
-
|
19
|
-
|
56
|
+
```ruby
|
57
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.second, false)
|
58
|
+
=> "1 second"
|
59
|
+
```
|
20
60
|
|
21
61
|
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
62
|
|
23
|
-
|
24
|
-
|
63
|
+
```ruby
|
64
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.year + 1.second, true)
|
65
|
+
=> "1 year, and 1 second"
|
66
|
+
```
|
25
67
|
|
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/
|
68
|
+
Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility", because that's just an insanely radical thing to do. \m/
|
28
69
|
|
29
70
|
The last argument is an optional options hash that can be used to manipulate behavior and (which uses `to_sentence`).
|
30
71
|
|
31
72
|
Don't like having to pass in `Time.now` all the time? Then use `time_ago_in_words` which also will *rock your
|
32
73
|
world*:
|
33
74
|
|
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!
|
38
|
-
|
39
|
-
## Install
|
40
|
-
|
41
|
-
Install it as a gem:
|
42
|
-
|
43
75
|
```ruby
|
44
|
-
|
76
|
+
>> time_ago_in_words(Time.now + 3.days + 1.second)
|
77
|
+
=> "3 days, and 1 second"
|
45
78
|
```
|
46
79
|
|
47
|
-
|
48
|
-
|
49
|
-
```ruby
|
50
|
-
gem 'dotiw', github: 'radar/dotiw'
|
51
|
-
```
|
80
|
+
Oh, and did I mention it supports I18n? Oh yeah. Rock on!
|
52
81
|
|
53
82
|
### Options
|
54
83
|
|
@@ -56,10 +85,12 @@ gem 'dotiw', github: 'radar/dotiw'
|
|
56
85
|
|
57
86
|
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`):
|
58
87
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
88
|
+
```ruby
|
89
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, locale: :es)
|
90
|
+
=> "1 minuto"
|
91
|
+
```
|
92
|
+
|
93
|
+
This will also be passed to `to_sentence`.
|
63
94
|
|
64
95
|
#### :vague
|
65
96
|
|
@@ -67,46 +98,60 @@ Specify this if you want it to use the old `distance_of_time_in_words`. The valu
|
|
67
98
|
|
68
99
|
#### :accumulate_on
|
69
100
|
|
70
|
-
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.
|
101
|
+
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.
|
71
102
|
|
72
|
-
|
73
|
-
|
103
|
+
```ruby
|
104
|
+
>> distance_of_time_in_words(Time.now, Time.now + 2.hours + 70.seconds, true, accumulate_on: :minutes)
|
105
|
+
=> "121 minutes and 10 seconds"
|
106
|
+
```
|
74
107
|
|
75
108
|
#### :only
|
76
109
|
|
77
110
|
Only want a specific measurement of time? No problem!
|
78
111
|
|
79
|
-
|
80
|
-
|
112
|
+
```ruby
|
113
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, only: :minutes)
|
114
|
+
=> "1 minute"
|
115
|
+
```
|
81
116
|
|
82
117
|
You only want some? No problem too!
|
83
118
|
|
84
|
-
|
85
|
-
|
119
|
+
```ruby
|
120
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, only: [:minutes, :hours])
|
121
|
+
=> "1 hour and 1 minute"
|
122
|
+
```
|
86
123
|
|
87
124
|
#### :except
|
88
125
|
|
89
126
|
Don't want a measurement of time? No problem!
|
90
127
|
|
91
|
-
|
92
|
-
|
128
|
+
```ruby
|
129
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, except: :minutes)
|
130
|
+
=> "1 hour"
|
131
|
+
```
|
93
132
|
|
94
133
|
Culling a whole group of measurements of time:
|
95
134
|
|
96
|
-
|
97
|
-
|
98
|
-
|
135
|
+
```ruby
|
136
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, except: [:minutes, :hours])
|
137
|
+
=> "1 day"
|
138
|
+
```
|
139
|
+
|
99
140
|
#### :highest\_measure\_only
|
100
141
|
|
101
142
|
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.
|
102
143
|
|
103
|
-
|
104
|
-
|
144
|
+
```ruby
|
145
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, highest_measure_only: true)
|
146
|
+
=> "1 hour"
|
147
|
+
```
|
105
148
|
|
106
149
|
Notice how minutes and seconds were removed from the output. Another example:
|
107
150
|
|
108
|
-
|
109
|
-
|
151
|
+
```ruby
|
152
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, highest_measure_only: true)
|
153
|
+
=> "1 minute"
|
154
|
+
```
|
110
155
|
|
111
156
|
Minutes are the highest measure, so seconds were discarded from the output.
|
112
157
|
|
@@ -114,58 +159,81 @@ Minutes are the highest measure, so seconds were discarded from the output.
|
|
114
159
|
|
115
160
|
When you want variable precision from `DOTIW`:
|
116
161
|
|
117
|
-
|
118
|
-
|
162
|
+
```ruby
|
163
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, highest_measures: 2)
|
164
|
+
=> "1 hour and 1 minute"
|
165
|
+
```
|
119
166
|
|
120
167
|
#### :words_connector
|
121
168
|
|
122
|
-
|
169
|
+
This is an option for `to_sentence`, defaults to ', '.
|
123
170
|
|
124
171
|
Using something other than a comma:
|
125
172
|
|
126
|
-
|
127
|
-
|
128
|
-
|
173
|
+
```ruby
|
174
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, words_connector: ' - ')
|
175
|
+
=> "1 hour - 1 minute, and 1 second"
|
176
|
+
```
|
177
|
+
|
129
178
|
#### :two\_words\_connector
|
130
179
|
|
131
|
-
|
180
|
+
This is an option for `to_sentence`, defaults to ' and '.
|
132
181
|
|
133
182
|
Using something other than 'and':
|
134
183
|
|
135
|
-
|
136
|
-
|
184
|
+
```ruby
|
185
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, true, two_words_connector: ' plus ')
|
186
|
+
=> "1 hour plus 1 minute"
|
187
|
+
```
|
137
188
|
|
138
|
-
#### :last\_word\_connector
|
189
|
+
#### :last\_word\_connector
|
139
190
|
|
140
|
-
|
191
|
+
This is an option for `to_sentence`, defaults to ', and '.
|
141
192
|
|
142
193
|
Using something other than ', and':
|
143
194
|
|
144
|
-
|
145
|
-
|
195
|
+
```ruby
|
196
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, last_word_connector: ', finally ')
|
197
|
+
=> "1 hour, 1 minute, finally 1 second"
|
198
|
+
```
|
146
199
|
|
147
200
|
## distance\_of\_time
|
148
201
|
|
149
202
|
If you have simply a number of seconds you can get the "stringified" version of this by using `distance_of_time`:
|
150
203
|
|
151
|
-
|
152
|
-
|
204
|
+
```ruby
|
205
|
+
>> distance_of_time(300)
|
206
|
+
=> "5 minutes"
|
207
|
+
```
|
153
208
|
|
154
209
|
## distance\_of\_time\_in\_words\_hash
|
155
210
|
|
156
211
|
Don't like any format you're given? That's cool too! Here, have an indifferent hash version:
|
157
212
|
|
158
|
-
|
159
|
-
|
213
|
+
```ruby
|
214
|
+
>> distance_of_time_in_words_hash(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds)
|
215
|
+
=> { days: 4, weeks: 3, seconds: 7, minutes: 6, years: 1, hours: 5, months: 2 }
|
216
|
+
```
|
160
217
|
|
161
218
|
Indifferent means that you can access all keys by their `String` or `Symbol` version.
|
162
|
-
|
219
|
+
|
163
220
|
## distance\_of\_time\_in\_percent
|
164
221
|
|
165
|
-
|
222
|
+
This method is only available with Rails ActionView.
|
223
|
+
|
224
|
+
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.
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
>> distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time)
|
228
|
+
=> '15%'
|
229
|
+
```
|
230
|
+
|
231
|
+
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
232
|
|
167
|
-
|
168
|
-
|
233
|
+
```ruby
|
234
|
+
>> distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time, precision: 1)
|
235
|
+
=> '15.3%'
|
236
|
+
```
|
169
237
|
|
170
238
|
## Contributors
|
171
239
|
|
@@ -173,3 +241,4 @@ If you want to calculate a distance of time in percent, use `distance_of_time_in
|
|
173
241
|
* [Derander](http://github.com/derander) - correct Spanish translations
|
174
242
|
* [DBA](http://github.com/dba) - commits leading up to the 0.7 release
|
175
243
|
* [Sija](http://github.com/Sija) - rails 4 support, v2.0 release
|
244
|
+
* [dblock](http://github.com/dblock) - Ruby w/o Rails support
|