dotiw 5.3.3 → 5.6.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 +4 -4
- data/.github/workflows/ruby.yml +41 -16
- data/.gitignore +1 -0
- data/Appraisals +25 -4
- data/CHANGELOG.md +26 -0
- data/CODEOWNERS +2 -0
- data/README.markdown +73 -5
- data/RELEASING.md +71 -0
- data/benchmarks/distance_of_time_in_words_bench.rb +38 -0
- data/dotiw.gemspec +4 -1
- data/gemfiles/{rails_4.gemfile → rails_7.0.gemfile} +2 -1
- data/gemfiles/rails_7.1.gemfile +11 -0
- data/gemfiles/rails_7.2.gemfile +11 -0
- data/gemfiles/rails_8.0.gemfile +11 -0
- data/gemfiles/rails_8.1.gemfile +11 -0
- data/gemfiles/rails_8.1_i18n.gemfile +11 -0
- data/lib/dotiw/core.rb +45 -0
- data/lib/dotiw/locale/dz.yml +60 -0
- data/lib/dotiw/locale/ru.yml +9 -9
- data/lib/dotiw/methods.rb +127 -21
- data/lib/dotiw/time_hash.rb +60 -12
- data/lib/dotiw/version.rb +1 -1
- data/lib/dotiw.rb +1 -40
- data/spec/lib/dotiw_module_spec.rb +52 -0
- data/spec/lib/dotiw_spec.rb +225 -14
- data/spec/lib/i18n/dz.yml +21 -0
- data/spec/lib/i18n/ru.yml +18 -0
- data/spec/spec_helper.rb +19 -0
- metadata +65 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b9778f6b8dfb3fa5013f9e365c91be2fcb955f040e19dde50d8f70b1fb28fcd
|
|
4
|
+
data.tar.gz: 5213a53264dd238ea225939d53c40a63523749b92331ef4a899fa3ca190d5bce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2efac079381c10ed7584f921dbeab2c3b4ae96f63a4b32c470a986a2a521f0a91c94e26871e92bcdcd9718d05d2bb6c41bc051155868b9c3684695b5b662d27e
|
|
7
|
+
data.tar.gz: 1506fe3f4715fd1f85b72d8de416d4dfdff144e02bce2837c741ab82d7928b2fed38e6c08fac19e1a5a0e155a9ec4c947407d1878107e5c15cc7947618f731dd
|
data/.github/workflows/ruby.yml
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
name: Ruby
|
|
2
2
|
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
pull_request:
|
|
8
|
-
branches:
|
|
9
|
-
- master
|
|
3
|
+
on: [push, pull_request]
|
|
10
4
|
|
|
11
5
|
jobs:
|
|
12
6
|
build:
|
|
@@ -15,19 +9,33 @@ jobs:
|
|
|
15
9
|
fail-fast: false
|
|
16
10
|
matrix:
|
|
17
11
|
include:
|
|
18
|
-
- ruby-version:
|
|
19
|
-
- ruby-version:
|
|
20
|
-
- ruby-version:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- ruby-version:
|
|
12
|
+
- ruby-version: '4.0'
|
|
13
|
+
- ruby-version: '3.4'
|
|
14
|
+
- ruby-version: '3.3'
|
|
15
|
+
- ruby-version: '3.2'
|
|
16
|
+
- ruby-version: '3.1'
|
|
17
|
+
- ruby-version: '3.0'
|
|
18
|
+
- ruby-version: '2.7'
|
|
19
|
+
- ruby-version: '2.7'
|
|
24
20
|
gemfile: gemfiles/rails_5.0.gemfile
|
|
25
|
-
- ruby-version: 2.
|
|
21
|
+
- ruby-version: '2.7'
|
|
26
22
|
gemfile: gemfiles/rails_5.1.gemfile
|
|
27
|
-
- ruby-version: 2.
|
|
23
|
+
- ruby-version: '2.7'
|
|
28
24
|
gemfile: gemfiles/rails_5.2.gemfile
|
|
29
|
-
- ruby-version:
|
|
25
|
+
- ruby-version: '3.4'
|
|
30
26
|
gemfile: gemfiles/rails_6.0.gemfile
|
|
27
|
+
- ruby-version: '3.4'
|
|
28
|
+
gemfile: gemfiles/rails_7.0.gemfile
|
|
29
|
+
- ruby-version: '3.4'
|
|
30
|
+
gemfile: gemfiles/rails_7.1.gemfile
|
|
31
|
+
- ruby-version: '3.4'
|
|
32
|
+
gemfile: gemfiles/rails_7.2.gemfile
|
|
33
|
+
- ruby-version: '3.4'
|
|
34
|
+
gemfile: gemfiles/rails_8.0.gemfile
|
|
35
|
+
- ruby-version: '3.4'
|
|
36
|
+
gemfile: gemfiles/rails_8.1.gemfile
|
|
37
|
+
- ruby-version: '3.4'
|
|
38
|
+
gemfile: gemfiles/rails_8.1_i18n.gemfile
|
|
31
39
|
steps:
|
|
32
40
|
- uses: actions/checkout@v2
|
|
33
41
|
- name: Set up Ruby
|
|
@@ -43,3 +51,20 @@ jobs:
|
|
|
43
51
|
gem install bundler -v ${BUNDLER:-2.1.4}
|
|
44
52
|
bundle install --jobs 4 --retry 3
|
|
45
53
|
bundle exec rake
|
|
54
|
+
- name: Upload coverage to Coveralls
|
|
55
|
+
if: matrix.ruby-version == '3.4'
|
|
56
|
+
uses: coverallsapp/github-action@v2
|
|
57
|
+
with:
|
|
58
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
59
|
+
flag-name: ruby-${{ matrix.ruby-version }}-${{ matrix.gemfile }}
|
|
60
|
+
parallel: true
|
|
61
|
+
|
|
62
|
+
finish:
|
|
63
|
+
needs: build
|
|
64
|
+
runs-on: ubuntu-latest
|
|
65
|
+
steps:
|
|
66
|
+
- name: Close parallel build
|
|
67
|
+
uses: coverallsapp/github-action@v2
|
|
68
|
+
with:
|
|
69
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
70
|
+
parallel-finished: true
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
appraise 'rails_4' do
|
|
2
|
-
gem 'rails', '~> 4.0'
|
|
3
|
-
end
|
|
4
|
-
|
|
5
1
|
appraise 'rails_5.0' do
|
|
6
2
|
gem 'rails', '~> 5.0.0'
|
|
7
3
|
end
|
|
@@ -17,3 +13,28 @@ end
|
|
|
17
13
|
appraise 'rails_6.0' do
|
|
18
14
|
gem 'rails', '~> 6.0.0'
|
|
19
15
|
end
|
|
16
|
+
|
|
17
|
+
appraise 'rails_7.0' do
|
|
18
|
+
gem 'rails', '~> 7.0.0'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
appraise 'rails_7.1' do
|
|
22
|
+
gem 'rails', '~> 7.1.0'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
appraise 'rails_7.2' do
|
|
26
|
+
gem 'rails', '~> 7.2.0'
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
appraise 'rails_8.0' do
|
|
30
|
+
gem 'rails', '~> 8.0.0'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
appraise 'rails_8.1' do
|
|
34
|
+
gem 'rails', '~> 8.1.0'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
appraise 'rails_8.1_i18n' do
|
|
38
|
+
gem 'rails', '~> 8.1.0'
|
|
39
|
+
gem 'rails-i18n'
|
|
40
|
+
end
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## 5.6.0 (2026/8/28)
|
|
2
|
+
|
|
3
|
+
* [#145](https://github.com/radar/distance_of_time_in_words/pull/145): Add `dotiw/core` require path to use dotiw without overriding the Rails date helpers, `DOTIW.distance_of_time_in_words` shortcut - [@ermolaev](https://github.com/ermolaev).
|
|
4
|
+
* [#146](https://github.com/radar/distance_of_time_in_words/pull/146): Add support for Rails 8 - [@dblock](https://github.com/dblock).
|
|
5
|
+
* [#147](https://github.com/radar/distance_of_time_in_words/pull/147): Add support for Rails 8.1, drop the `tzinfo ~> 1.2.7` development pin - [@ermolaev](https://github.com/ermolaev).
|
|
6
|
+
* [#148](https://github.com/radar/distance_of_time_in_words/pull/148): Add `max_unit` option to express the entire distance as a single number in one unit - [@dblock](https://github.com/dblock).
|
|
7
|
+
* [#79](https://github.com/radar/distance_of_time_in_words/issues/79): Speed up `distance_of_time_in_words` by avoiding `I18n.with_options`/`ActiveSupport::OptionMerger` allocation for translations, using `I18n.translate` directly instead - [@dblock](https://github.com/dblock).
|
|
8
|
+
* [#77](https://github.com/radar/distance_of_time_in_words/issues/77), [#120](https://github.com/radar/distance_of_time_in_words/issues/120): Fix `only`/`except` discarding the duration of excluded fractions instead of folding them into the next smaller included fraction - [@dblock](https://github.com/dblock).
|
|
9
|
+
* [#63](https://github.com/radar/distance_of_time_in_words/issues/63): Fix incorrect DST correction in timezones with an inverted DST scheme (e.g. Europe/Dublin) by comparing `utc_offset` instead of the unreliable `Time#dst?` - [@dblock](https://github.com/dblock).
|
|
10
|
+
* [#153](https://github.com/radar/distance_of_time_in_words/issues/153): Fix leftover hours/minutes leaking a historical UTC offset change (e.g. Pacific/Norfolk's 2015 offset change) into the result instead of folding it into the calendar distance - [@dblock](https://github.com/dblock).
|
|
11
|
+
* [#44](https://github.com/radar/distance_of_time_in_words/issues/44): Document that `vague: true` combined with a non-English `locale:` requires the host application to load Rails' own translations for that locale - [@dblock](https://github.com/dblock).
|
|
12
|
+
* [#156](https://github.com/radar/distance_of_time_in_words/pull/156): Add Ruby 4.0 to the test matrix - [@dblock](https://github.com/dblock).
|
|
13
|
+
* [#158](https://github.com/radar/distance_of_time_in_words/pull/158): Add test coverage reporting with SimpleCov and Coveralls, merged across all Ruby 3.4 CI jobs (default + pinned Rails gemfiles) using parallel builds - [@dblock](https://github.com/dblock).
|
|
14
|
+
|
|
15
|
+
## 5.5.0 (2026/03/15)
|
|
16
|
+
|
|
17
|
+
* [#131](https://github.com/radar/distance_of_time_in_words/pull/131): Deprecates `highest_measure_only`. Adds alternate form of `highest_measures` option to permit rounding up whatever part of the duration was previously silently discarded - [@seansfkelley](https://github.com/seansfkelley).
|
|
18
|
+
* [#133](https://github.com/radar/distance_of_time_in_words/pull/133): Test on Ruby 3.0 and 3.1 - [@dblock](https://github.com/dblock).
|
|
19
|
+
* [#134](https://github.com/radar/distance_of_time_in_words/pull/134): Add support for Dzongkha, the National language of Bhutan - [@KinWang-2013](https://github.com/KinWang-2013).
|
|
20
|
+
* [#135](https://github.com/radar/distance_of_time_in_words/pull/135): Add support for Ruby 2.7 and 3.2, removed support for ruby 2.4, 2.5, 2.6 and Rails 4 - [@KinWang-2013](https://github.com/KinWang-2013).
|
|
21
|
+
* [#136](https://github.com/radar/distance_of_time_in_words/pull/136): Add support for Rails 7 - [@KinWang-2013](https://github.com/KinWang-2013).
|
|
22
|
+
* [#139](https://github.com/radar/distance_of_time_in_words/pull/139): Fix bug with pluralization of Russian translations for numbers ending in 1 - [@bitberry-dev](https://github.com/bitberry-dev).
|
|
23
|
+
* [#140](https://github.com/radar/distance_of_time_in_words/pull/140): Add Ruby 3.3 and 3.4 support, added logger - [@dblock](https://github.com/dblock).
|
|
24
|
+
* [#141](https://github.com/radar/distance_of_time_in_words/pull/141): Fix flaky time calculation test by explicitly setting timezone - [@bitberry-dev](https://github.com/bitberry-dev).
|
|
25
|
+
* Fix bug when accumulating on years - [@radar](https://github.com/radar).
|
|
26
|
+
|
|
1
27
|
## 5.3.3 (2022/04/25)
|
|
2
28
|
|
|
3
29
|
* [#128](https://github.com/radar/distance_of_time_in_words/pull/128): Adds support for numeric values for both the `from_time` and `to_time` arguments in the `#distance_of_time_in_words` helper - [@bjedrocha](https://github.com/bjedrocha).
|
data/CODEOWNERS
ADDED
data/README.markdown
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# dotiw 
|
|
1
|
+
# dotiw  [](https://coveralls.io/github/radar/distance_of_time_in_words?branch=master)
|
|
2
2
|
|
|
3
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
4
|
|
|
@@ -32,6 +32,23 @@ include ActionView::Helpers::TextHelper
|
|
|
32
32
|
include ActionView::Helpers::NumberHelper
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
### Rails, without overriding the built-in helpers
|
|
36
|
+
|
|
37
|
+
Requiring `dotiw` replaces the Rails implementation of `distance_of_time_in_words`
|
|
38
|
+
and `time_ago_in_words`. If you would rather keep the built-in Rails helpers and
|
|
39
|
+
call dotiw explicitly, require `dotiw/core` instead:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
gem 'dotiw', require: 'dotiw/core'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This loads `DOTIW::Methods` and the dotiw translations, but leaves
|
|
46
|
+
`ActionView::Helpers::DateHelper` untouched:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
DOTIW.distance_of_time_in_words(from_time, to_time, highest_measures: 1)
|
|
50
|
+
```
|
|
51
|
+
|
|
35
52
|
## distance\_of\_time\_in\_words
|
|
36
53
|
|
|
37
54
|
Take this for a totally kick-ass example:
|
|
@@ -117,6 +134,8 @@ This will also be passed to `to_sentence`.
|
|
|
117
134
|
|
|
118
135
|
Specify this if you want it to use the old `distance_of_time_in_words`. The value can be anything except `nil` or `false`.
|
|
119
136
|
|
|
137
|
+
Note that `:vague` falls back to Rails/ActionView's own `distance_of_time_in_words`, which looks up its translations under `datetime.distance_in_words`. This namespace is provided by Rails core translations (e.g. via the [rails-i18n](https://github.com/svenfuchs/rails-i18n) gem) for non-English locales, not by dotiw. If you combine `:vague` with a non-English `:locale` and see a "translation missing" error, make sure your application also loads the corresponding Rails translations for that locale (see [#44](https://github.com/radar/distance_of_time_in_words/issues/44)).
|
|
138
|
+
|
|
120
139
|
#### :include_seconds
|
|
121
140
|
|
|
122
141
|
As described above this option is the equivalent to the third argument whether to include seconds.
|
|
@@ -130,40 +149,71 @@ Specifies the maximum output unit which will accumulate all the surplus. Say you
|
|
|
130
149
|
=> "121 minutes and 10 seconds"
|
|
131
150
|
```
|
|
132
151
|
|
|
152
|
+
Note that units below `accumulate_on` are still shown separately. If you want the entire distance expressed as a single number in one unit, use `:max_unit` instead.
|
|
153
|
+
|
|
154
|
+
#### :max_unit
|
|
155
|
+
|
|
156
|
+
Expresses the entire distance as a single number in the given unit, discarding (flooring) any remainder smaller than that unit. Unlike `:accumulate_on`, no other units are shown in the output.
|
|
157
|
+
|
|
158
|
+
```ruby
|
|
159
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.day, true, max_unit: :seconds)
|
|
160
|
+
=> "86400 seconds"
|
|
161
|
+
|
|
162
|
+
>> distance_of_time_in_words(Time.now, Time.now + 3.days + 2.hours, true, max_unit: :hours)
|
|
163
|
+
=> "74 hours"
|
|
164
|
+
|
|
165
|
+
>> distance_of_time_in_words_hash(Time.now, Time.now + 3.days + 2.hours, max_unit: :hours)
|
|
166
|
+
=> {hours: 74}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Valid units are `:seconds`, `:minutes`, `:hours`, `:days`, `:weeks`, `:months` and `:years`.
|
|
170
|
+
|
|
133
171
|
#### :only
|
|
134
172
|
|
|
135
173
|
Only want a specific measurement of time? No problem!
|
|
136
174
|
|
|
137
175
|
```ruby
|
|
138
176
|
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, only: :minutes)
|
|
139
|
-
=> "
|
|
177
|
+
=> "61 minutes"
|
|
140
178
|
```
|
|
141
179
|
|
|
180
|
+
Excluded measurements are folded into the next smaller included measurement instead of being
|
|
181
|
+
discarded, so the returned duration is always accurate (1 hour + 1 minute = 61 minutes, not 1
|
|
182
|
+
minute).
|
|
183
|
+
|
|
142
184
|
You only want some? No problem too!
|
|
143
185
|
|
|
144
186
|
```ruby
|
|
145
187
|
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, only: [:minutes, :hours])
|
|
146
|
-
=> "
|
|
188
|
+
=> "25 hours and 1 minute"
|
|
147
189
|
```
|
|
148
190
|
|
|
191
|
+
Here the excluded day is folded into hours (1 day + 1 hour = 25 hours).
|
|
192
|
+
|
|
149
193
|
#### :except
|
|
150
194
|
|
|
151
195
|
Don't want a measurement of time? No problem!
|
|
152
196
|
|
|
153
197
|
```ruby
|
|
154
198
|
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, except: :minutes)
|
|
155
|
-
=> "1 hour"
|
|
199
|
+
=> "1 hour and 60 seconds"
|
|
156
200
|
```
|
|
157
201
|
|
|
202
|
+
The excluded minute is folded into seconds (1 minute = 60 seconds) rather than discarded.
|
|
203
|
+
|
|
158
204
|
Culling a whole group of measurements of time:
|
|
159
205
|
|
|
160
206
|
```ruby
|
|
161
207
|
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, except: [:minutes, :hours])
|
|
162
|
-
=> "1 day"
|
|
208
|
+
=> "1 day and 3660 seconds"
|
|
163
209
|
```
|
|
164
210
|
|
|
211
|
+
The excluded hour and minute cascade down into seconds (1 hour + 1 minute = 3660 seconds).
|
|
212
|
+
|
|
165
213
|
#### :highest\_measure\_only
|
|
166
214
|
|
|
215
|
+
> **Deprecated**. Use `highest_measures: 1` instead.
|
|
216
|
+
|
|
167
217
|
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.
|
|
168
218
|
|
|
169
219
|
```ruby
|
|
@@ -189,6 +239,24 @@ When you want variable precision from `DOTIW`:
|
|
|
189
239
|
=> "1 hour and 1 minute"
|
|
190
240
|
```
|
|
191
241
|
|
|
242
|
+
You can also specify what to do with the extra time with the `remainder` option:
|
|
243
|
+
|
|
244
|
+
```ruby
|
|
245
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, highest_measures: { max: 2, remainder: :ceiling })
|
|
246
|
+
=> "1 hour and 2 minutes"
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Valid options for `remainder` are `:floor` (default), `:ceiling` and `:round`. Note that `:round` is best-effort and makes some simplifying assumptions:
|
|
250
|
+
|
|
251
|
+
```ruby
|
|
252
|
+
# Only the next-largest unit is examined, which can unexpectedly round down in some situations.
|
|
253
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.week + 3.days + 23.hours, true, highest_measures: { remainder: :round })
|
|
254
|
+
=> "1 week"
|
|
255
|
+
# The variability of some measures (like months) is ignored and the shortest duration of that measure is used.
|
|
256
|
+
>> distance_of_time_in_words(Time.now, Time.now + 1.month + 14.days, true, highest_measures: { remainder: :round })
|
|
257
|
+
=> "2 months"
|
|
258
|
+
```
|
|
259
|
+
|
|
192
260
|
#### :words_connector
|
|
193
261
|
|
|
194
262
|
This is an option for `to_sentence`, defaults to ', '.
|
data/RELEASING.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Releasing DOTIW
|
|
2
|
+
|
|
3
|
+
There are no hard rules about when to release dotiw. Release bug fixes frequently, features not so frequently and breaking API changes rarely.
|
|
4
|
+
|
|
5
|
+
## Release
|
|
6
|
+
|
|
7
|
+
Run tests, check that all tests succeed locally.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
bundle install
|
|
11
|
+
rake
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Check that the last build succeeded in [GitHub Actions](https://github.com/radar/distance_of_time_in_words/actions) for all supported platforms.
|
|
15
|
+
|
|
16
|
+
Add a date to this release in [CHANGELOG.md](CHANGELOG.md).
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
## 5.5.1 (2026/03/28)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
|
23
|
+
|
|
24
|
+
Commit your changes.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
git add CHANGELOG.md lib/dotiw/version.rb
|
|
28
|
+
git commit -m "Preparing for release, 5.5.1."
|
|
29
|
+
git push origin master
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Release.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
rake release
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This builds the gem, creates and pushes a git tag, and pushes the gem to [RubyGems](https://rubygems.org/gems/dotiw).
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
dotiw 5.5.1 built to pkg/dotiw-5.5.1.gem.
|
|
42
|
+
Tagged v5.5.1.
|
|
43
|
+
Pushed git commits and tags.
|
|
44
|
+
Pushed dotiw 5.5.1 to rubygems.org.
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Create a GitHub release for the tag using the `gh` CLI, passing the CHANGELOG entries for this version as the release notes.
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
gh release create v5.5.1 --title "5.5.1" --notes "$(sed -n '/^## 5.5.1/,/^## /p' CHANGELOG.md | sed '$d')"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Prepare for the Next Version
|
|
54
|
+
|
|
55
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
## 5.5.2 (Next)
|
|
59
|
+
|
|
60
|
+
* Your contribution here.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Increment the patch version number in [lib/dotiw/version.rb](lib/dotiw/version.rb).
|
|
64
|
+
|
|
65
|
+
Commit your changes.
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
git add CHANGELOG.md lib/dotiw/version.rb
|
|
69
|
+
git commit -m "Preparing for next developer iteration, 5.5.2."
|
|
70
|
+
git push origin master
|
|
71
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Benchmark for https://github.com/radar/distance_of_time_in_words/issues/79
|
|
4
|
+
#
|
|
5
|
+
# Compares dotiw's distance_of_time_in_words against Rails' original
|
|
6
|
+
# ActionView::Helpers::DateHelper#distance_of_time_in_words, using the
|
|
7
|
+
# scenario from the issue and its follow-up comments.
|
|
8
|
+
#
|
|
9
|
+
# Run with `ruby benchmarks/distance_of_time_in_words_bench.rb` after
|
|
10
|
+
# `gem install benchmark-ips benchmark-memory actionview`.
|
|
11
|
+
|
|
12
|
+
require 'active_support'
|
|
13
|
+
require 'active_support/core_ext'
|
|
14
|
+
require 'benchmark/ips'
|
|
15
|
+
require 'benchmark/memory'
|
|
16
|
+
|
|
17
|
+
require_relative '../lib/dotiw'
|
|
18
|
+
|
|
19
|
+
begin
|
|
20
|
+
require 'action_view'
|
|
21
|
+
rescue LoadError
|
|
22
|
+
warn "This benchmark requires actionview: gem install actionview"
|
|
23
|
+
exit 1
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
include ActionView::Helpers::DateHelper
|
|
27
|
+
|
|
28
|
+
now = Time.now
|
|
29
|
+
future_time = Time.now + 100.years + 30.days + 50.seconds
|
|
30
|
+
|
|
31
|
+
%i[ips memory].each do |type|
|
|
32
|
+
Benchmark.public_send(type) do |x|
|
|
33
|
+
x.report('dotiw') { DOTIW.distance_of_time_in_words(now, future_time) }
|
|
34
|
+
x.report('rails') { distance_of_time_in_words(now, future_time, include_seconds: true) }
|
|
35
|
+
|
|
36
|
+
x.compare!
|
|
37
|
+
end
|
|
38
|
+
end
|
data/dotiw.gemspec
CHANGED
|
@@ -26,7 +26,10 @@ Gem::Specification.new do |s|
|
|
|
26
26
|
s.add_development_dependency 'pry'
|
|
27
27
|
s.add_development_dependency 'rake'
|
|
28
28
|
s.add_development_dependency 'rspec', '~> 3.0'
|
|
29
|
-
s.add_development_dependency '
|
|
29
|
+
s.add_development_dependency 'mutex_m'
|
|
30
|
+
s.add_development_dependency 'base64'
|
|
31
|
+
s.add_development_dependency 'bigdecimal'
|
|
32
|
+
s.add_development_dependency 'simplecov'
|
|
30
33
|
|
|
31
34
|
s.files = `git ls-files`.split("\n")
|
|
32
35
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/dotiw/core.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'i18n'
|
|
4
|
+
require 'logger'
|
|
5
|
+
require 'active_support'
|
|
6
|
+
require 'active_support/core_ext'
|
|
7
|
+
|
|
8
|
+
module DOTIW
|
|
9
|
+
extend ActiveSupport::Autoload
|
|
10
|
+
|
|
11
|
+
eager_autoload do
|
|
12
|
+
autoload :VERSION, 'dotiw/version'
|
|
13
|
+
autoload :TimeHash, 'dotiw/time_hash'
|
|
14
|
+
autoload :Methods, 'dotiw/methods'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
extend self
|
|
18
|
+
|
|
19
|
+
DEFAULT_I18N_SCOPE = :'datetime.dotiw'
|
|
20
|
+
DEFAULT_I18N_SCOPE_COMPACT = :'datetime.dotiw_compact'
|
|
21
|
+
|
|
22
|
+
# DOTIW.distance_of_time_in_words(...), DOTIW.time_ago_in_words(...), etc.
|
|
23
|
+
extend Methods
|
|
24
|
+
|
|
25
|
+
def init_i18n!
|
|
26
|
+
I18n.load_path.unshift(*locale_files)
|
|
27
|
+
I18n.reload!
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def languages
|
|
31
|
+
@languages ||= (locale_files.map { |path| path.split(%r{[/.]})[-2].to_sym })
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def locale_files
|
|
35
|
+
files 'locale', '*.yml'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
protected
|
|
39
|
+
|
|
40
|
+
def files(directory, ext)
|
|
41
|
+
Dir[File.join File.dirname(__FILE__), directory, ext]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
DOTIW.init_i18n!
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
dz:
|
|
2
|
+
datetime:
|
|
3
|
+
dotiw:
|
|
4
|
+
seconds:
|
|
5
|
+
one: སྐར་ཆ་ ༡
|
|
6
|
+
other: "སྐར་ཆ་ %{count}"
|
|
7
|
+
minutes:
|
|
8
|
+
one: སྐར་མ་ ༡
|
|
9
|
+
other: "སྐར་མ་ %{count}"
|
|
10
|
+
hours:
|
|
11
|
+
one: ཆུ་ཚོད་ ༡
|
|
12
|
+
other: "ཆུ་ཚོད་ %{count}"
|
|
13
|
+
days:
|
|
14
|
+
one: ཉིནམ་ ༡
|
|
15
|
+
other: "ཉིནམ་ %{count}"
|
|
16
|
+
weeks:
|
|
17
|
+
one: བདུན༌ཕྲག་ ༡
|
|
18
|
+
other: "བདུན༌ཕྲག་ %{count}"
|
|
19
|
+
months:
|
|
20
|
+
one: ཟླཝ་ ༡
|
|
21
|
+
other: "ཟླཝ་ %{count}"
|
|
22
|
+
years:
|
|
23
|
+
one: ལོ་ ༡
|
|
24
|
+
other: "ལོ་ %{count}"
|
|
25
|
+
less_than_x: "%{distance} ་ལས་ཉུངམ་"
|
|
26
|
+
dotiw_compact:
|
|
27
|
+
seconds:
|
|
28
|
+
one: སྐར་ཆ་ ༡
|
|
29
|
+
other: "སྐར་ཆ་ %{count}"
|
|
30
|
+
minutes:
|
|
31
|
+
one: སྐར་མ་ ༡
|
|
32
|
+
other: "སྐར་མ་ %{count}"
|
|
33
|
+
hours:
|
|
34
|
+
one: ཆུ་ཚོད་ ༡
|
|
35
|
+
other: "ཆུ་ཚོད་ %{count}"
|
|
36
|
+
days:
|
|
37
|
+
one: ཉིནམ་ ༡
|
|
38
|
+
other: "ཉིནམ་ %{count}"
|
|
39
|
+
weeks:
|
|
40
|
+
one: བདུན༌ཕྲག་ ༡
|
|
41
|
+
other: "བདུན༌ཕྲག་ %{count}"
|
|
42
|
+
months:
|
|
43
|
+
one: ཟླཝ་ ༡
|
|
44
|
+
other: "ཟླཝ་ %{count}"
|
|
45
|
+
years:
|
|
46
|
+
one: ལོ་ ༡
|
|
47
|
+
other: "ལོ་ %{count}"
|
|
48
|
+
less_than_x: "%{distance} ་ལས་ཉུངམ"
|
|
49
|
+
words_connector: ""
|
|
50
|
+
two_words_connector: " དང་ "
|
|
51
|
+
last_word_connector: " དང་ "
|
|
52
|
+
about_x_years:
|
|
53
|
+
one: ལོ་ ༡ ་དེ་ཅིག
|
|
54
|
+
any: "ལོ་ %{count} ་དེ་ཅིག"
|
|
55
|
+
over_x_years:
|
|
56
|
+
one: "ལོ་ ༡ ་ལས་ལྷགཔ་ཅིག"
|
|
57
|
+
other: "ལོ་ %{count} ་ལས་ལྷགཔ་ཅིག"
|
|
58
|
+
almost_x_years:
|
|
59
|
+
one: ལོ་ ༡ ་མ་ལྷགཔ་ཅིག
|
|
60
|
+
any: "ལོ་ %{count} ་མ་ལྷགཔ་ཅིག"
|
data/lib/dotiw/locale/ru.yml
CHANGED
|
@@ -39,22 +39,22 @@ ru:
|
|
|
39
39
|
less_than_x: "меньше, чем %{distance}"
|
|
40
40
|
dotiw_compact:
|
|
41
41
|
seconds:
|
|
42
|
-
one:
|
|
42
|
+
one: "%{count}с"
|
|
43
43
|
other: "%{count}с"
|
|
44
44
|
minutes:
|
|
45
|
-
one:
|
|
45
|
+
one: "%{count}м"
|
|
46
46
|
other: "%{count}м"
|
|
47
47
|
hours:
|
|
48
|
-
one:
|
|
48
|
+
one: "%{count}ч"
|
|
49
49
|
other: "%{count}ч"
|
|
50
50
|
days:
|
|
51
|
-
one:
|
|
51
|
+
one: "%{count}д"
|
|
52
52
|
other: "%{count}д"
|
|
53
53
|
weeks:
|
|
54
|
-
one:
|
|
54
|
+
one: "%{count}н"
|
|
55
55
|
other: "%{count}н"
|
|
56
56
|
months:
|
|
57
|
-
one:
|
|
57
|
+
one: "%{count}ме"
|
|
58
58
|
other: "%{count}ме"
|
|
59
59
|
years:
|
|
60
60
|
one: "%{count}г"
|
|
@@ -66,11 +66,11 @@ ru:
|
|
|
66
66
|
two_words_connector: ""
|
|
67
67
|
last_word_connector: ""
|
|
68
68
|
about_x_years:
|
|
69
|
-
one:
|
|
69
|
+
one: "~%{count}г"
|
|
70
70
|
any: "~%{count}г"
|
|
71
71
|
over_x_years:
|
|
72
|
-
one: "
|
|
72
|
+
one: ">%{count}г"
|
|
73
73
|
other: ">%{count}г"
|
|
74
74
|
almost_x_years:
|
|
75
|
-
one:
|
|
75
|
+
one: "~%{count}г"
|
|
76
76
|
any: "~%{count}г"
|