dotiw 3.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aed9b495f66627b6c68f2e8ca572e2958ef44bf8
4
- data.tar.gz: d49193040ff64bb85cd25829666a47268fc9ccc8
2
+ SHA256:
3
+ metadata.gz: 268158a7bbfdd70af4db14b42aa6f0bf24869a4eda6cefd0eb528598e1f0dfbd
4
+ data.tar.gz: 9ee5ba47781f5aa16796641251a02e68997dae148f1b3f4b36f7f7a98a3d7ba6
5
5
  SHA512:
6
- metadata.gz: eb4f3572b53a3a6dad22d64fd9793ce6df58791664b8dc9a3a98e6f7745b1a6fdad38d6b7e9014de30e46f33ad472ea5bc96ab1cc4bd0de97e897ebdc5aad318
7
- data.tar.gz: 6d19cfebf638180ddf0bd8d5f2479df83baeb3426220dd57c645deb40294950f71200ffa5c0199e31ea9905359e2c12f71aac8bd749fdee85a658fc7b658c375
6
+ metadata.gz: 4c376145f1d7e62acb4ed59e2ff6ed0a2fd427507a72c69785fd4d01b6efa6a5269f3d1979ce7b3087608d537bc3857c6298b93beafdbca10c701d870578cb0f
7
+ data.tar.gz: ab46caf7a03f8ccd459948d3102a363eb0a3978b1e9a76c1344682a89f9b3bd5691090024860a58668ccb89e4566c13b996ae56cc9f64fd8e673b8bdce1da9d3
@@ -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
@@ -2,4 +2,5 @@ tmp
2
2
  pkg
3
3
  spec/fixtures/database.yml
4
4
  .rvmrc
5
- Gemfile.lock
5
+ Gemfile.lock
6
+ gemfiles/*.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -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
@@ -0,0 +1,24 @@
1
+ ## 5.0.0 (2020/05/07)
2
+
3
+ * [#105](https://github.com/radar/distance_of_time_in_words/pull/105): Support for Ruby w/o Rails - [@dblock](https://github.com/dblock).
4
+ * [#108](https://github.com/radar/distance_of_time_in_words/pull/108): Fix negative weeks - [@ivanovaleksey](https://github.com/ivanovaleksey).
5
+
6
+ ## 4.0.1 (2018/06/01)
7
+
8
+ ## 3.1.1 (2016/03/08)
9
+
10
+ ## 3.1.0 (2016/03/07)
11
+
12
+ * [#68](https://github.com/radar/dotiw/pull/68): Add support for weeks - [@lauranjansen](https://github.com/lauranjansen).
13
+ * [#69](https://github.com/radar/dotiw/pull/69): Add Indonesian language support - [@avidmaulanas](https://github.com/avidmaulanas).
14
+ * [#70](https://github.com/radar/dotiw/pull/70): Add French language support - [@geo1004](https://github.com/geo1004).
15
+ * [#72](https://github.com/radar/dotiw/pull/72): Add Danish language support - [@kaspernj](https://github.com/kaspernj).
16
+ * [#71](https://github.com/radar/dotiw/pull/71): Update bundler and ruby versions for Travis CI - [@lauranjansen](https://github.com/lauranjansen).
17
+
18
+ ## 3.0.1 (2015/04/09)
19
+
20
+ ## 3.0 (2015/04/09)
21
+
22
+ ## 0.2.4 (2009/10/18)
23
+
24
+ * Initial public release - [@radar](https://github.com/radar).
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Ryan Bigg
1
+ Copyright (c) 2009-2020 Ryan Bigg
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,54 +1,83 @@
1
- # dotiw [![](https://travis-ci.org/radar/dotiw.png)](https://travis-ci.org/radar/dotiw)
1
+ # dotiw ![Ruby](https://github.com/radar/distance_of_time_in_words/workflows/Ruby/badge.svg)
2
2
 
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:
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 4.hours + 5.minutes + 6.seconds, true)
11
- => "1 year, 2 months, 4 hours, 5 minutes, and 6 seconds"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.second, false)
19
- => "1 second"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.year + 1.second, true)
24
- => "1 year, and 1 second"
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
- gem 'dotiw'
76
+ >> time_ago_in_words(Time.now + 3.days + 1.second)
77
+ => "3 days, and 1 second"
45
78
  ```
46
79
 
47
- Or from GitHub:
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, :locale => :es)
60
- => "1 minuto"
61
-
62
- This will also be passed to `to_sentence`
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. Here's a code example:
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
- >> distance_of_time_in_words(Time.now, Time.now + 2.hours + 70.seconds, true, :accumulate_on => :minutes)
73
- => "121 minutes and 10 seconds"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :only => :minutes)
80
- => "1 minute"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :only => [:minutes, :hours])
85
- => "1 hour and 1 minute"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :except => :minutes)
92
- => "1 hour"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :except => [:minutes, :hours])
97
- => "1 day"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :highest_measure_only => true)
104
- => "1 hour"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, :highest_measure_only => true)
109
- => "1 minute"
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
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :highest_measures => 2)
118
- => "1 hour and 1 minute"
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
- **This is an option for `to_sentence`, defaults to ', '**
169
+ This is an option for `to_sentence`, defaults to ', '.
123
170
 
124
171
  Using something other than a comma:
125
172
 
126
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :words_connector => ' - ')
127
- => "1 hour - 1 minute, and 1 second"
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
- **This is an option for `to_sentence`, defaults to ' and '**
180
+ This is an option for `to_sentence`, defaults to ' and '.
132
181
 
133
182
  Using something other than 'and':
134
183
 
135
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, true, :two_words_connector => ' plus ')
136
- => "1 hour plus 1 minute"
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
- **This is an option for `to_sentence`, defaults to ', and '**
191
+ This is an option for `to_sentence`, defaults to ', and '.
141
192
 
142
193
  Using something other than ', and':
143
194
 
144
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :last_word_connector => ', finally ')
145
- => "1 hour, 1 minute, finally 1 second"
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
- >> distance_of_time(300)
152
- => "5 minutes"
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
- >> distance_of_time_in_words_hash(Time.now, Time.now + 1.year + 2.months + 3.days + 4.hours + 5.minutes + 6.seconds)
159
- => {:days => 3, :seconds => 6, :minutes => 5, :years => 1, :hours => 4, :months => 2}
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
- 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).
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
- distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time, options)
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