jekyll-timeago 0.15.0 → 1.1.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/ci.yml +6 -2
- data/.gitignore +3 -1
- data/README.md +81 -14
- data/bin/timeago +74 -0
- data/lib/jekyll-timeago/core.rb +173 -36
- data/lib/jekyll-timeago/version.rb +1 -1
- data/lib/locales/ca.yml +4 -0
- data/lib/locales/de.yml +4 -0
- data/lib/locales/en.yml +4 -0
- data/lib/locales/es.yml +4 -0
- data/lib/locales/fr.yml +4 -0
- data/lib/locales/it.yml +4 -0
- data/lib/locales/{ja.yaml → ja.yml} +5 -1
- data/lib/locales/pt.yml +4 -0
- data/lib/locales/ru.yml +4 -0
- data/lib/locales/tr.yml +24 -0
- data/lib/locales/zh_hans.yml +4 -0
- data/spec/jekyll-timeago_spec.rb +152 -16
- metadata +10 -9
- data/bin/jekyll-timeago +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f8ae690f6686791715f0397fd0c38f6284c5857e78d9cc7669d437d402ce838
|
4
|
+
data.tar.gz: '083e7d05d403c01c22dac5f5f2bc5b832279dd5a7fb65a049e497939078ed0e9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1184731bf638031b1ab559e9fc26c0e98a641d33a4e71b5ae7fb88c5a6c6982975de6f6d0c311daf88f76de4c1fdb6931acc54241cb8b860b4bb4b8621e45ed
|
7
|
+
data.tar.gz: 3c03eebcd1100a75059fc96f11987204c7fe08acf6879da4ea35d4a451f9902952b3932915e3a79d8ee532b2bd21dd1a6f7fa64db984d91af2ca57fa8261b649
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
name: CI
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
4
8
|
|
5
9
|
jobs:
|
6
10
|
test:
|
@@ -11,7 +15,7 @@ jobs:
|
|
11
15
|
strategy:
|
12
16
|
fail-fast: false
|
13
17
|
matrix:
|
14
|
-
ruby: ['2.
|
18
|
+
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', 'head']
|
15
19
|
gemfile: ['jekyll_v3', 'jekyll_v4']
|
16
20
|
steps:
|
17
21
|
- uses: actions/checkout@v3
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -8,15 +8,16 @@
|
|
8
8
|
|
9
9
|
Main features:
|
10
10
|
|
11
|
-
- Compute distance of dates, in words
|
12
|
-
- Future times
|
11
|
+
- Compute distance of dates, in words: `1 week and 2 days ago`, `5 months ago`
|
12
|
+
- Future times: `in 1 year`
|
13
|
+
- Alternative formats: short (`2y and 1mo ago`), array (`['2 years', '1 month']`), and hash (`{years: 2, months: 1}`)
|
13
14
|
- Out of the box support for `Jekyll` projects, available as a Liquid Filter and as a Liquid Tag
|
14
|
-
- Localization
|
15
|
+
- Localization: `hace 3 semanas`, `3週間前`, `il y a environ 3 semaines`
|
15
16
|
- Level of detail customization
|
16
|
-
-
|
17
|
-
- Approximate distance, with customizable threshold
|
17
|
+
- CLI
|
18
|
+
- Approximate distance, with customizable threshold: `366 days` becomes `1 year ago` instead of `1 year and 1 day ago`
|
18
19
|
|
19
|
-
In fact, `jekyll-timeago` started as an extension for the [Liquid](https://github.com/Shopify/liquid) template engine, to be used in Jekyll
|
20
|
+
In fact, `jekyll-timeago` started as an extension for the [Liquid](https://github.com/Shopify/liquid) template engine, to be used in Jekyll backed sites. But actually, you can use it easily on any Ruby project and even as a tool from the [terminal](#cli)!
|
20
21
|
|
21
22
|
Read more about the `Jekyll` integration [in this section](#jekyll-integration).
|
22
23
|
|
@@ -73,7 +74,7 @@ Examples:
|
|
73
74
|
=> "in 2 years and 8 months"
|
74
75
|
```
|
75
76
|
|
76
|
-
**NOTE** If you have the gem installed in your system globally, and you're not using Bundler (probably because you're are writing a
|
77
|
+
**NOTE** If you have the gem installed in your system globally, and you're not using Bundler (probably because you're are writing a small script), don't forget to require the library first:
|
77
78
|
|
78
79
|
```ruby
|
79
80
|
require 'jekyll-timeago'
|
@@ -84,7 +85,7 @@ puts timeago('2030-1-1')
|
|
84
85
|
|
85
86
|
### Options
|
86
87
|
|
87
|
-
|
88
|
+
#### `locale`
|
88
89
|
|
89
90
|
To use a different language:
|
90
91
|
|
@@ -97,7 +98,7 @@ To use a different language:
|
|
97
98
|
|
98
99
|
Read more about the localization options [here](#localization).
|
99
100
|
|
100
|
-
|
101
|
+
#### `depth`
|
101
102
|
|
102
103
|
You are able to change the level of detail (from 1 up to 4, 2 by default) to get higher or lower granularity:
|
103
104
|
|
@@ -108,7 +109,7 @@ You are able to change the level of detail (from 1 up to 4, 2 by default) to get
|
|
108
109
|
=> "5 years, 5 months, 3 weeks and 4 days ago"
|
109
110
|
```
|
110
111
|
|
111
|
-
|
112
|
+
#### `threshold`
|
112
113
|
|
113
114
|
The next component in the time must at least match this threshold to be picked. Set to 0 by default, so you don't get any approximations. Can be used to drop "straggling" values which are too low to be of any use (`in 7 months and 2 days` is as good as saying `in 7 months`).
|
114
115
|
|
@@ -117,6 +118,62 @@ The next component in the time must at least match this threshold to be picked.
|
|
117
118
|
=> "1 year ago"
|
118
119
|
```
|
119
120
|
|
121
|
+
#### `style`
|
122
|
+
|
123
|
+
Use `:short` style for abbreviated time formats:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
>> timeago(Date.today.prev_day(365), style: :short)
|
127
|
+
=> "1y ago"
|
128
|
+
>> timeago(Date.today.prev_day(30), style: :short)
|
129
|
+
=> "1mo ago"
|
130
|
+
>> timeago(Date.today.prev_day(7), style: :short)
|
131
|
+
=> "1w ago"
|
132
|
+
```
|
133
|
+
|
134
|
+
Use `:array` style for structured data:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
>> timeago(Date.today.prev_day(365), style: :array)
|
138
|
+
=> ["1 year"]
|
139
|
+
>> timeago(Date.today.prev_day(160), style: :array)
|
140
|
+
=> ["5 months", "1 week"]
|
141
|
+
>> timeago(Date.today.prev_day(160), style: :array, locale: :es)
|
142
|
+
=> ["5 meses", "1 semana"]
|
143
|
+
```
|
144
|
+
|
145
|
+
Use `:hash` style for structured hash data:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
>> timeago(Date.today.prev_day(365), style: :hash)
|
149
|
+
=> {:years=>1}
|
150
|
+
>> timeago(Date.today.prev_day(160), style: :hash)
|
151
|
+
=> {:months=>5, :weeks=>1}
|
152
|
+
>> timeago(Date.today.prev_day(160), style: :hash, locale: :es)
|
153
|
+
=> {:meses=>5, :semanas=>1}
|
154
|
+
```
|
155
|
+
|
156
|
+
#### `only`
|
157
|
+
|
158
|
+
Use the `only` option to accumulate all time into a single unit. Supported values are `:years`, `:months`, `:weeks`, and `:days`:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
>> timeago(Date.today.prev_day(365), only: :weeks)
|
162
|
+
=> "52 weeks ago"
|
163
|
+
>> timeago(Date.today.prev_day(365), only: :months)
|
164
|
+
=> "12 months ago"
|
165
|
+
>> timeago(Date.today.prev_day(100), only: :weeks)
|
166
|
+
=> "14 weeks ago"
|
167
|
+
>> timeago(Date.today.prev_day(500), only: :days)
|
168
|
+
=> "500 days ago"
|
169
|
+
>> timeago(Date.today.prev_day(365), only: :weeks, style: :short)
|
170
|
+
=> "52w ago"
|
171
|
+
>> timeago(Date.today.prev_day(365), only: :months, locale: :es)
|
172
|
+
=> "hace 12 meses"
|
173
|
+
>> timeago(Date.today.prev_day(365), only: :months, style: :hash)
|
174
|
+
=> {:months=>12}
|
175
|
+
```
|
176
|
+
|
120
177
|
## Localization
|
121
178
|
|
122
179
|
By default, `jekyll-timego` already provides translations for some languages. You can check the list [here](lib/locales/). However, you are able to provide your own translations, or even override the originals, easily.
|
@@ -137,11 +194,21 @@ If you want to contribute and support more default languages, please feel free t
|
|
137
194
|
You can also use `jekyll-timeago` from the command line:
|
138
195
|
|
139
196
|
```
|
140
|
-
>
|
141
|
-
>
|
197
|
+
> timeago --help
|
198
|
+
> timeago 2016-1-1
|
142
199
|
2 years and 6 months ago
|
143
|
-
>
|
200
|
+
> timeago 2016-1-1 --locale fr
|
144
201
|
il y a environ 2 années et 6 mois
|
202
|
+
> timeago 2016-1-1 2018-1-1 --style short
|
203
|
+
2y ago
|
204
|
+
> timeago 2016-1-1 2018-1-1 -l es -s short
|
205
|
+
hace 2a y 1d
|
206
|
+
> timeago 2016-1-1 2018-1-1 --style hash
|
207
|
+
{:years=>2, :days=>1}
|
208
|
+
> timeago 2016-1-1 2018-1-1 --only weeks
|
209
|
+
104 weeks ago
|
210
|
+
> timeago 2016-1-1 2018-1-1 --only months -s short
|
211
|
+
24mo ago
|
145
212
|
```
|
146
213
|
|
147
214
|
### Console
|
@@ -149,7 +216,7 @@ il y a environ 2 années et 6 mois
|
|
149
216
|
Starts a custom IRB session with the `timeago` method included:
|
150
217
|
|
151
218
|
```
|
152
|
-
>
|
219
|
+
> timeago --console
|
153
220
|
>> timeago(Date.today)
|
154
221
|
=> "today"
|
155
222
|
```
|
data/bin/timeago
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative "../lib/jekyll-timeago"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
show_help = false
|
8
|
+
show_version = false
|
9
|
+
start_console = false
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = <<~HELP_MESSAGE
|
13
|
+
Usage:
|
14
|
+
|
15
|
+
timeago <from_date> [to_date]
|
16
|
+
|
17
|
+
Notes:
|
18
|
+
[to_date] Optional, defaults to current date
|
19
|
+
|
20
|
+
Options:
|
21
|
+
HELP_MESSAGE
|
22
|
+
|
23
|
+
opts.on("-h", "--help", "Prints this message") do
|
24
|
+
show_help = true
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-v", "--version", "Prints the current version") do
|
28
|
+
show_version = true
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-c", "--console", "Starts an interactive IRB session with jekyll-timeago included") do
|
32
|
+
start_console = true
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-l", "--locale LOCALE", "Uses the provided locale") do |locale|
|
36
|
+
options[:locale] = locale
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-s", "--style STYLE", "Uses the provided style (short, array, hash)") do |style|
|
40
|
+
options[:style] = style
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on("-o", "--only UNIT", "Accumulates time in specified unit (years, months, weeks, days)") do |unit|
|
44
|
+
options[:only] = unit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
parser.parse!
|
50
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
51
|
+
puts "Error! #{e}"
|
52
|
+
puts parser
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
|
56
|
+
if show_help
|
57
|
+
puts parser
|
58
|
+
elsif show_version
|
59
|
+
puts "v#{Jekyll::Timeago::VERSION}"
|
60
|
+
elsif start_console
|
61
|
+
require "irb"
|
62
|
+
include Jekyll::Timeago
|
63
|
+
IRB.start
|
64
|
+
elsif ARGV.empty?
|
65
|
+
puts parser
|
66
|
+
else
|
67
|
+
ARGV << options if !options.empty?
|
68
|
+
|
69
|
+
begin
|
70
|
+
puts Jekyll::Timeago.timeago *ARGV
|
71
|
+
rescue ArgumentError => e
|
72
|
+
puts "Error! #{e}"
|
73
|
+
end
|
74
|
+
end
|
data/lib/jekyll-timeago/core.rb
CHANGED
@@ -14,6 +14,12 @@ module Jekyll
|
|
14
14
|
# Default threshold
|
15
15
|
DEFAULT_THRESHOLD = 0
|
16
16
|
|
17
|
+
# Available styles
|
18
|
+
STYLES = %w(short array hash)
|
19
|
+
|
20
|
+
# Available "only" options
|
21
|
+
ONLY_OPTIONS = %w(years months weeks days)
|
22
|
+
|
17
23
|
def timeago(from, to = Date.today, options = {})
|
18
24
|
if to.is_a?(Hash)
|
19
25
|
options = to
|
@@ -22,12 +28,14 @@ module Jekyll
|
|
22
28
|
|
23
29
|
@options = options
|
24
30
|
|
25
|
-
from = validate_date(from)
|
26
|
-
to = validate_date(to)
|
27
|
-
depth = validate_depth(@options[:depth] || @options["depth"])
|
28
|
-
|
31
|
+
@from = validate_date(from)
|
32
|
+
@to = validate_date(to)
|
33
|
+
@depth = validate_depth(@options[:depth] || @options["depth"])
|
34
|
+
@style = validate_style(@options[:style] || @options["style"])
|
35
|
+
@threshold = validate_threshold(@options[:threshold] || @options["threshold"])
|
36
|
+
@only = validate_only(@options[:only] || @options["only"])
|
29
37
|
|
30
|
-
time_ago_to_now
|
38
|
+
time_ago_to_now
|
31
39
|
end
|
32
40
|
|
33
41
|
private
|
@@ -44,52 +52,181 @@ module Jekyll
|
|
44
52
|
(1..MAX_DEPTH_LEVEL).include?(depth) ? depth : DEFAULT_DEPTH_LEVEL
|
45
53
|
end
|
46
54
|
|
47
|
-
def
|
48
|
-
|
55
|
+
def validate_style(style)
|
56
|
+
style = style.to_s
|
57
|
+
STYLES.include?(style) ? style : nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_only(only)
|
61
|
+
only = only.to_s
|
62
|
+
ONLY_OPTIONS.include?(only) ? only : nil
|
63
|
+
end
|
49
64
|
|
50
|
-
|
51
|
-
|
52
|
-
|
65
|
+
def time_ago_to_now
|
66
|
+
days_passed = (@to - @from).to_i
|
67
|
+
|
68
|
+
if @style == "hash"
|
69
|
+
return { localized_unit_name(:days) => 0 } if days_passed == 0
|
70
|
+
return { localized_unit_name(:days) => 1 } if days_passed == 1
|
71
|
+
return { localized_unit_name(:days) => -1 } if days_passed == -1
|
72
|
+
elsif @style == "array"
|
73
|
+
return [t(:today)] if days_passed == 0
|
74
|
+
return [t(:yesterday)] if days_passed == 1
|
75
|
+
return [t(:tomorrow)] if days_passed == -1
|
76
|
+
else
|
77
|
+
return t(:today) if days_passed == 0
|
78
|
+
return t(:yesterday) if days_passed == 1
|
79
|
+
return t(:tomorrow) if days_passed == -1
|
80
|
+
end
|
53
81
|
|
54
|
-
past_or_future = from < to ? :past : :future
|
55
|
-
slots = build_time_ago_slots(days_passed.abs
|
82
|
+
past_or_future = @from < @to ? :past : :future
|
83
|
+
slots = build_time_ago_slots(days_passed.abs)
|
56
84
|
|
57
|
-
|
85
|
+
if @style == "array" || @style == "hash"
|
86
|
+
slots
|
87
|
+
else
|
88
|
+
t(past_or_future, date_range: to_sentence(slots))
|
89
|
+
end
|
58
90
|
end
|
59
91
|
|
60
92
|
def t(key, options = {})
|
61
93
|
MiniI18n.t(key, @options.merge(options))
|
62
94
|
end
|
63
95
|
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
range = days_to_range(days_passed)
|
73
|
-
days = days_in(range)
|
74
|
-
num_elems = (days_passed / days).to_i
|
96
|
+
# Translate a time unit, using short form if style is :short
|
97
|
+
def translate_unit(unit, count)
|
98
|
+
if @style == "short"
|
99
|
+
t("#{unit}_short", count: count)
|
100
|
+
else
|
101
|
+
t(unit, count: count)
|
102
|
+
end
|
103
|
+
end
|
75
104
|
|
76
|
-
|
105
|
+
# Get localized unit name for hash keys (always plural form)
|
106
|
+
def localized_unit_name(unit)
|
107
|
+
# Extract the unit name from the plural form translation
|
108
|
+
translated = t(unit, count: 2)
|
109
|
+
# Remove any count prefix (e.g. "2 años" -> "años")
|
110
|
+
translated.gsub(/^\d+\s+/, '').to_sym
|
111
|
+
end
|
77
112
|
|
78
|
-
|
113
|
+
# Builds time ranges with natural unit conversions: ['1 month', '5 days'] or {:months => 1, :days => 5}
|
114
|
+
def build_time_ago_slots(days_passed)
|
115
|
+
# If "only" option is specified, calculate total time in that unit
|
116
|
+
return build_only_slots(days_passed) if @only
|
117
|
+
|
118
|
+
# Calculate components with natural unit conversions
|
119
|
+
components = calculate_natural_components(days_passed)
|
120
|
+
|
121
|
+
# Select components based on depth and threshold
|
122
|
+
selected = select_components(components, days_passed)
|
123
|
+
|
124
|
+
# Format output based on current style
|
125
|
+
if @style == "hash"
|
126
|
+
result = {}
|
127
|
+
selected.each { |unit, count| result[localized_unit_name(unit)] = count }
|
128
|
+
result
|
129
|
+
else
|
130
|
+
selected.map { |unit, count| translate_unit(unit, count) }
|
131
|
+
end
|
132
|
+
end
|
79
133
|
|
80
|
-
|
81
|
-
|
134
|
+
# Build time slots when "only" option is specified
|
135
|
+
def build_only_slots(days_passed)
|
136
|
+
unit = @only.to_sym
|
137
|
+
count = calculate_total_in_unit(days_passed, unit)
|
138
|
+
|
139
|
+
if @style == "hash"
|
140
|
+
{ localized_unit_name(unit) => count }
|
82
141
|
else
|
83
|
-
|
142
|
+
[translate_unit(unit, count)]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Calculate total time in specified unit
|
147
|
+
def calculate_total_in_unit(days_passed, unit)
|
148
|
+
case unit
|
149
|
+
when :days
|
150
|
+
days_passed
|
151
|
+
when :weeks
|
152
|
+
# Ensure minimum of 1 week if days_passed > 0
|
153
|
+
return 1 if days_passed > 0 && days_passed < 7
|
154
|
+
(days_passed / 7.0).round
|
155
|
+
when :months
|
156
|
+
# Ensure minimum of 1 month if days_passed > 0
|
157
|
+
return 1 if days_passed > 0 && days_passed < 30
|
158
|
+
(days_passed / 30.0).round
|
159
|
+
when :years
|
160
|
+
# Ensure minimum of 1 year if days_passed > 0
|
161
|
+
return 1 if days_passed > 0 && days_passed < 365
|
162
|
+
(days_passed / 365.0).round
|
84
163
|
end
|
85
164
|
end
|
86
165
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
166
|
+
def calculate_natural_components(days_passed)
|
167
|
+
years = days_passed / 365
|
168
|
+
remaining_days = days_passed % 365
|
169
|
+
|
170
|
+
months = remaining_days / 30
|
171
|
+
remaining_days = remaining_days % 30
|
172
|
+
|
173
|
+
weeks = remaining_days / 7
|
174
|
+
days = remaining_days % 7
|
175
|
+
|
176
|
+
normalize_units({ years: years, months: months, weeks: weeks, days: days })
|
177
|
+
end
|
178
|
+
|
179
|
+
def normalize_units(components)
|
180
|
+
# Convert 12+ months to years (handles any multiple: 12 → 1yr, 24 → 2yr, 36 → 3yr, etc.)
|
181
|
+
if components[:months] >= 12
|
182
|
+
additional_years = components[:months] / 12
|
183
|
+
components[:years] += additional_years
|
184
|
+
components[:months] = components[:months] % 12
|
185
|
+
end
|
186
|
+
|
187
|
+
# Convert 4+ weeks to months (proportional conversion)
|
188
|
+
if components[:weeks] >= 4
|
189
|
+
additional_months = components[:weeks] / 4
|
190
|
+
components[:months] += additional_months
|
191
|
+
components[:weeks] = components[:weeks] % 4
|
192
|
+
end
|
193
|
+
|
194
|
+
# After adding months, check again for year conversion (handles cascading)
|
195
|
+
if components[:months] >= 12
|
196
|
+
additional_years = components[:months] / 12
|
197
|
+
components[:years] += additional_years
|
198
|
+
components[:months] = components[:months] % 12
|
199
|
+
end
|
200
|
+
|
201
|
+
components
|
202
|
+
end
|
203
|
+
|
204
|
+
# Select components based on depth and apply threshold filtering
|
205
|
+
def select_components(components, total_days)
|
206
|
+
result = []
|
207
|
+
|
208
|
+
[:years, :months, :weeks, :days].each do |unit|
|
209
|
+
count = components[unit]
|
210
|
+
if count > 0 && result.length < @depth
|
211
|
+
result << [unit, count]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
apply_threshold_filtering(result, total_days)
|
216
|
+
end
|
217
|
+
|
218
|
+
# Filter out components that don't meet the threshold
|
219
|
+
def apply_threshold_filtering(components, total_days)
|
220
|
+
return components if @threshold == 0 || components.length <= 1
|
221
|
+
|
222
|
+
# Calculate if smallest component meets threshold
|
223
|
+
last_unit, last_count = components.last
|
224
|
+
last_unit_days = last_count * days_in(last_unit)
|
225
|
+
|
226
|
+
if last_unit_days < (total_days * @threshold).floor
|
227
|
+
components[0...-1] # Remove last component
|
228
|
+
else
|
229
|
+
components
|
93
230
|
end
|
94
231
|
end
|
95
232
|
|
@@ -112,4 +249,4 @@ module Jekyll
|
|
112
249
|
end
|
113
250
|
end
|
114
251
|
end
|
115
|
-
end
|
252
|
+
end
|
data/lib/locales/ca.yml
CHANGED
@@ -9,12 +9,16 @@ ca:
|
|
9
9
|
years:
|
10
10
|
one: '1 any'
|
11
11
|
other: '%{count} anys'
|
12
|
+
years_short: '%{count}a'
|
12
13
|
months:
|
13
14
|
one: '1 mes'
|
14
15
|
other: '%{count} mesos'
|
16
|
+
months_short: '%{count}m'
|
15
17
|
weeks:
|
16
18
|
one: '1 setmana'
|
17
19
|
other: '%{count} setmanes'
|
20
|
+
weeks_short: '%{count}s'
|
18
21
|
days:
|
19
22
|
one: '1 dia'
|
20
23
|
other: '%{count} dies'
|
24
|
+
days_short: '%{count}d'
|
data/lib/locales/de.yml
CHANGED
@@ -9,12 +9,16 @@ de:
|
|
9
9
|
years:
|
10
10
|
one: '1 Jahr'
|
11
11
|
other: '%{count} Jahren'
|
12
|
+
years_short: '%{count}j'
|
12
13
|
months:
|
13
14
|
one: '1 Monat'
|
14
15
|
other: '%{count} Monaten'
|
16
|
+
months_short: '%{count}mo'
|
15
17
|
weeks:
|
16
18
|
one: '1 Woche'
|
17
19
|
other: '%{count} Wochen'
|
20
|
+
weeks_short: '%{count}w'
|
18
21
|
days:
|
19
22
|
one: '1 Tag'
|
20
23
|
other: '%{count} Tage'
|
24
|
+
days_short: '%{count}d'
|
data/lib/locales/en.yml
CHANGED
@@ -9,12 +9,16 @@ en:
|
|
9
9
|
years:
|
10
10
|
one: '1 year'
|
11
11
|
other: '%{count} years'
|
12
|
+
years_short: '%{count}y'
|
12
13
|
months:
|
13
14
|
one: '1 month'
|
14
15
|
other: '%{count} months'
|
16
|
+
months_short: '%{count}mo'
|
15
17
|
weeks:
|
16
18
|
one: '1 week'
|
17
19
|
other: '%{count} weeks'
|
20
|
+
weeks_short: '%{count}w'
|
18
21
|
days:
|
19
22
|
one: '1 day'
|
20
23
|
other: '%{count} days'
|
24
|
+
days_short: '%{count}d'
|
data/lib/locales/es.yml
CHANGED
@@ -9,12 +9,16 @@ es:
|
|
9
9
|
years:
|
10
10
|
one: '1 año'
|
11
11
|
other: '%{count} años'
|
12
|
+
years_short: '%{count}a'
|
12
13
|
months:
|
13
14
|
one: '1 mes'
|
14
15
|
other: '%{count} meses'
|
16
|
+
months_short: '%{count}m'
|
15
17
|
weeks:
|
16
18
|
one: '1 semana'
|
17
19
|
other: '%{count} semanas'
|
20
|
+
weeks_short: '%{count}s'
|
18
21
|
days:
|
19
22
|
one: '1 día'
|
20
23
|
other: '%{count} días'
|
24
|
+
days_short: '%{count}d'
|
data/lib/locales/fr.yml
CHANGED
@@ -9,12 +9,16 @@ fr:
|
|
9
9
|
years:
|
10
10
|
one: '1 année'
|
11
11
|
other: '%{count} années'
|
12
|
+
years_short: '%{count}a'
|
12
13
|
months:
|
13
14
|
one: '1 mois'
|
14
15
|
other: '%{count} mois'
|
16
|
+
months_short: '%{count}mo'
|
15
17
|
weeks:
|
16
18
|
one: '1 semaine'
|
17
19
|
other: '%{count} semaines'
|
20
|
+
weeks_short: '%{count}s'
|
18
21
|
days:
|
19
22
|
one: '1 jour'
|
20
23
|
other: '%{count} jours'
|
24
|
+
days_short: '%{count}j'
|
data/lib/locales/it.yml
CHANGED
@@ -9,12 +9,16 @@ it:
|
|
9
9
|
years:
|
10
10
|
one: '1 anno'
|
11
11
|
other: '%{count} anni'
|
12
|
+
years_short: '%{count}a'
|
12
13
|
months:
|
13
14
|
one: '1 mese'
|
14
15
|
other: '%{count} mesi'
|
16
|
+
months_short: '%{count}m'
|
15
17
|
weeks:
|
16
18
|
one: '1 settimana'
|
17
19
|
other: '%{count} settimane'
|
20
|
+
weeks_short: '%{count}s'
|
18
21
|
days:
|
19
22
|
one: '1 giorno'
|
20
23
|
other: '%{count} giorni'
|
24
|
+
days_short: '%{count}g'
|
@@ -9,12 +9,16 @@ ja:
|
|
9
9
|
years:
|
10
10
|
one: '1年'
|
11
11
|
other: '%{count}年'
|
12
|
+
years_short: '%{count}年'
|
12
13
|
months:
|
13
14
|
one: '1ヶ月'
|
14
|
-
other: '%{count}
|
15
|
+
other: '%{count}ヵ月'
|
16
|
+
months_short: '%{count}月'
|
15
17
|
weeks:
|
16
18
|
one: '1週間'
|
17
19
|
other: '%{count}週間'
|
20
|
+
weeks_short: '%{count}週'
|
18
21
|
days:
|
19
22
|
one: '1日'
|
20
23
|
other: '%{count}日'
|
24
|
+
days_short: '%{count}日'
|
data/lib/locales/pt.yml
CHANGED
@@ -9,12 +9,16 @@ pt:
|
|
9
9
|
years:
|
10
10
|
one: '1 ano'
|
11
11
|
other: '%{count} anos'
|
12
|
+
years_short: '%{count}a'
|
12
13
|
months:
|
13
14
|
one: '1 mês'
|
14
15
|
other: '%{count} meses'
|
16
|
+
months_short: '%{count}m'
|
15
17
|
weeks:
|
16
18
|
one: '1 semana'
|
17
19
|
other: '%{count} semanas'
|
20
|
+
weeks_short: '%{count}s'
|
18
21
|
days:
|
19
22
|
one: '1 dia'
|
20
23
|
other: '%{count} dias'
|
24
|
+
days_short: '%{count}d'
|
data/lib/locales/ru.yml
CHANGED
@@ -10,15 +10,19 @@ ru:
|
|
10
10
|
one: 'год'
|
11
11
|
few: '%{count} года'
|
12
12
|
other: '%{count} лет'
|
13
|
+
years_short: '%{count}г'
|
13
14
|
months:
|
14
15
|
one: 'месяц'
|
15
16
|
few: '%{count} месяца'
|
16
17
|
other: '%{count} месяцев'
|
18
|
+
months_short: '%{count}м'
|
17
19
|
weeks:
|
18
20
|
one: 'неделю'
|
19
21
|
few: '%{count} недели'
|
20
22
|
other: '%{count} недель'
|
23
|
+
weeks_short: '%{count}н'
|
21
24
|
days:
|
22
25
|
one: 'день'
|
23
26
|
few: '%{count} дня'
|
24
27
|
other: '%{count} дней'
|
28
|
+
days_short: '%{count}д'
|
data/lib/locales/tr.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
tr:
|
2
|
+
today: 'bugün'
|
3
|
+
yesterday: 'dün'
|
4
|
+
tomorrow: 'yarın'
|
5
|
+
past: '%{date_range} önce'
|
6
|
+
future: '%{date_range} içinde'
|
7
|
+
last_word_connector: ', '
|
8
|
+
words_connector: ', '
|
9
|
+
years:
|
10
|
+
one: '1 yıl'
|
11
|
+
other: '%{count} yıl'
|
12
|
+
years_short: '%{count}y'
|
13
|
+
months:
|
14
|
+
one: '1 ay'
|
15
|
+
other: '%{count} ay'
|
16
|
+
months_short: '%{count}a'
|
17
|
+
weeks:
|
18
|
+
one: '1 hafta'
|
19
|
+
other: '%{count} hafta'
|
20
|
+
weeks_short: '%{count}h'
|
21
|
+
days:
|
22
|
+
one: '1 gün'
|
23
|
+
other: '%{count} gün'
|
24
|
+
days_short: '%{count}g'
|
data/lib/locales/zh_hans.yml
CHANGED
@@ -9,12 +9,16 @@ zh_hans:
|
|
9
9
|
years:
|
10
10
|
one: '1年'
|
11
11
|
other: '%{count}年'
|
12
|
+
years_short: '%{count}年'
|
12
13
|
months:
|
13
14
|
one: '1个月'
|
14
15
|
other: '%{count}个月'
|
16
|
+
months_short: '%{count}月'
|
15
17
|
weeks:
|
16
18
|
one: '1周'
|
17
19
|
other: '%{count}周'
|
20
|
+
weeks_short: '%{count}周'
|
18
21
|
days:
|
19
22
|
one: '1天'
|
20
23
|
other: '%{count}天'
|
24
|
+
days_short: '%{count}天'
|
data/spec/jekyll-timeago_spec.rb
CHANGED
@@ -23,8 +23,8 @@ describe Jekyll::Timeago do
|
|
23
23
|
|
24
24
|
expected =
|
25
25
|
"<p>2 años</p>\n"\
|
26
|
-
"<p>
|
27
|
-
"<p>
|
26
|
+
"<p>1 año</p>\n"\
|
27
|
+
"<p>1 año</p>\n"\
|
28
28
|
"<p>2 años</p>\n"\
|
29
29
|
"<p>en 1 año</p>\n"
|
30
30
|
|
@@ -36,6 +36,11 @@ describe Jekyll::Timeago do
|
|
36
36
|
let (:sample_date) { Date.new(2014, 7, 30) }
|
37
37
|
let (:today) { Date.today }
|
38
38
|
|
39
|
+
before(:all) do
|
40
|
+
# Reset original translations
|
41
|
+
MiniI18n.configure { |config| config.load_translations(Pathname(__dir__).join("../lib/locales/*.yml")) }
|
42
|
+
end
|
43
|
+
|
39
44
|
it 'yesterday, today and tomorrow' do
|
40
45
|
expect(timeago(today.prev_day)).to eq("yesterday")
|
41
46
|
expect(timeago(today)).to eq("today")
|
@@ -55,7 +60,7 @@ describe Jekyll::Timeago do
|
|
55
60
|
expect(timeago(sample_date.next_day(1000), sample_date, locale: :ru)).to eq('через 2 года и 9 месяцев')
|
56
61
|
end
|
57
62
|
|
58
|
-
it '
|
63
|
+
it 'allows different date formats' do
|
59
64
|
expect(timeago('2010-1-1', '2012-1-1')).to eq('2 years ago')
|
60
65
|
expect(timeago('2010/1/1', '2012/1/1')).to eq('2 years ago')
|
61
66
|
expect(timeago('Jan 2010, 1', 'Jan 2012, 1')).to eq('2 years ago')
|
@@ -63,7 +68,7 @@ describe Jekyll::Timeago do
|
|
63
68
|
expect(timeago('2014-10-06 20:00:00', '2014-10-07 20:00:00')).to eq('yesterday')
|
64
69
|
end
|
65
70
|
|
66
|
-
it '
|
71
|
+
it 'allows to change level of detail' do
|
67
72
|
expect(timeago(sample_date.prev_day(500), sample_date, depth: 1)).to eq('1 year ago')
|
68
73
|
expect(timeago(sample_date.prev_day(500), sample_date, "depth" => 1)).to eq('1 year ago')
|
69
74
|
expect(timeago(sample_date.prev_day(500), sample_date, depth: 2)).to eq('1 year and 4 months ago')
|
@@ -72,39 +77,170 @@ describe Jekyll::Timeago do
|
|
72
77
|
expect(timeago(sample_date.prev_day(500), sample_date, depth: 5)).to eq('1 year and 4 months ago')
|
73
78
|
end
|
74
79
|
|
75
|
-
it '
|
76
|
-
expect(timeago(sample_date.prev_day(366), sample_date, threshold: 0.
|
80
|
+
it 'allows threshold configuration' do
|
81
|
+
expect(timeago(sample_date.prev_day(366), sample_date, threshold: 0.1)).to eq('1 year ago')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'applies rounding rules for natural language' do
|
85
|
+
expect(timeago(sample_date.prev_day(58), sample_date)).to eq('2 months ago')
|
86
|
+
expect(timeago(sample_date.prev_day(360), sample_date)).to eq('1 year ago')
|
87
|
+
expect(timeago(sample_date.prev_day(725), sample_date)).to eq('2 years ago')
|
88
|
+
expect(timeago(sample_date.next_day(58), sample_date)).to eq('in 2 months')
|
89
|
+
expect(timeago(sample_date.next_day(360), sample_date)).to eq('in 1 year')
|
90
|
+
expect(timeago(sample_date.next_day(725), sample_date)).to eq('in 2 years')
|
91
|
+
|
92
|
+
# Test cases that should NOT round up
|
93
|
+
expect(timeago(sample_date.prev_day(44), sample_date)).to eq('1 month and 2 weeks ago')
|
94
|
+
expect(timeago(sample_date.prev_day(545), sample_date)).to eq('1 year and 6 months ago')
|
77
95
|
end
|
78
96
|
|
79
|
-
it '
|
97
|
+
it 'allows localization' do
|
80
98
|
expect(timeago(sample_date.prev_day(100), sample_date, locale: :fr)).to eq('il y a environ 3 mois et 1 semaine')
|
81
99
|
expect(timeago(sample_date.prev_day(100), sample_date, locale: :ru)).to eq('3 месяца и неделю назад')
|
100
|
+
expect(timeago(sample_date.prev_day(100), sample_date, locale: :it)).to eq('3 mesi e 1 settimana fa')
|
101
|
+
expect(timeago(sample_date.prev_day(100), sample_date, locale: :pt)).to eq('3 meses e 1 semana atrás')
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'allows short style formatting' do
|
105
|
+
expect(timeago(sample_date.prev_day(365), sample_date, style: :short)).to eq('1y ago')
|
106
|
+
expect(timeago(sample_date.prev_day(365), sample_date, "style" => "short")).to eq('1y ago')
|
107
|
+
expect(timeago(sample_date.prev_day(730), sample_date, style: :short)).to eq('2y ago')
|
108
|
+
expect(timeago(sample_date.prev_day(30), sample_date, style: :short)).to eq('1mo ago')
|
109
|
+
expect(timeago(sample_date.prev_day(60), sample_date, style: :short)).to eq('2mo ago')
|
110
|
+
expect(timeago(sample_date.prev_day(7), sample_date, style: :short)).to eq('1w ago')
|
111
|
+
expect(timeago(sample_date.prev_day(14), sample_date, style: :short)).to eq('2w ago')
|
112
|
+
expect(timeago(sample_date.prev_day(1), sample_date, style: :short)).to eq('yesterday')
|
113
|
+
expect(timeago(sample_date.prev_day(2), sample_date, style: :short)).to eq('2d ago')
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'allows short style with different locales' do
|
117
|
+
expect(timeago(sample_date.prev_day(365), sample_date, locale: :fr, style: :short)).to eq('il y a environ 1a')
|
118
|
+
expect(timeago(sample_date.prev_day(365), sample_date, locale: :ru, style: :short)).to eq('1г назад')
|
119
|
+
expect(timeago(sample_date.prev_day(365), sample_date, locale: :es, style: :short)).to eq('hace 1a')
|
120
|
+
expect(timeago(sample_date.prev_day(30), sample_date, locale: :de, style: :short)).to eq('vor 1mo')
|
121
|
+
expect(timeago(sample_date.prev_day(120), sample_date, locale: :ca, style: :short)).to eq('fa 4m')
|
122
|
+
expect(timeago(sample_date.prev_day(120), sample_date, locale: :ja, style: :short)).to eq('4月前')
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'allows complex combinations with short style' do
|
126
|
+
expect(timeago(sample_date.prev_day(400), sample_date, style: :short)).to eq('1y and 1mo ago')
|
127
|
+
expect(timeago(sample_date.prev_day(100), sample_date, style: :short, depth: 1)).to eq('3mo ago')
|
128
|
+
expect(timeago(sample_date.prev_day(100), sample_date, style: :short, depth: 3)).to eq('3mo, 1w and 3d ago')
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'allows array style formatting' do
|
132
|
+
expect(timeago(sample_date, sample_date, style: :array)).to eq(['today'])
|
133
|
+
expect(timeago(sample_date.prev_day(365), sample_date, style: :array)).to eq(['1 year'])
|
134
|
+
expect(timeago(sample_date.prev_day(365), sample_date, "style" => "array")).to eq(['1 year'])
|
135
|
+
expect(timeago(sample_date.prev_day(160), sample_date, style: :array)).to eq(['5 months', '1 week'])
|
136
|
+
expect(timeago(sample_date.prev_day(160), sample_date, style: :array, locale: :es)).to eq(['5 meses', '1 semana'])
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'allows hash style formatting' do
|
140
|
+
expect(timeago(sample_date, sample_date, style: :hash)).to eq({days: 0})
|
141
|
+
expect(timeago(sample_date, sample_date, style: :hash, locale: :es)).to eq({días: 0})
|
142
|
+
expect(timeago(sample_date.prev_day(365), sample_date, style: :hash)).to eq({years: 1})
|
143
|
+
expect(timeago(sample_date.prev_day(365), sample_date, "style" => "hash")).to eq({years: 1})
|
144
|
+
expect(timeago(sample_date.prev_day(160), sample_date, style: :hash)).to eq({months: 5, weeks: 1})
|
145
|
+
expect(timeago(sample_date.prev_day(500), sample_date, style: :hash)).to eq({years: 1, months: 4})
|
146
|
+
expect(timeago(sample_date.prev_day(10), sample_date, style: :hash)).to eq({weeks: 1, days: 3})
|
147
|
+
expect(timeago(sample_date.prev_day(160), sample_date, style: :hash, locale: :es)).to eq({meses: 5, semanas: 1})
|
148
|
+
expect(timeago(sample_date.prev_day(500), sample_date, style: :hash, locale: :fr)).to eq({années: 1, mois: 4})
|
149
|
+
expect(timeago(sample_date.prev_day(500), sample_date, style: :hash, depth: 4)).to eq({years: 1, months: 4, weeks: 2, days: 1})
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'allows "only" option to accumulate time into single unit' do
|
153
|
+
# Test "only: :days"
|
154
|
+
expect(timeago(sample_date.prev_day(7), sample_date, only: :days)).to eq('7 days ago')
|
155
|
+
expect(timeago(sample_date.prev_day(7), sample_date, "only" => "days")).to eq('7 days ago')
|
156
|
+
expect(timeago(sample_date.prev_day(30), sample_date, only: :days)).to eq('30 days ago')
|
157
|
+
|
158
|
+
# Test "only: :weeks"
|
159
|
+
expect(timeago(sample_date.prev_day(7), sample_date, only: :weeks)).to eq('1 week ago')
|
160
|
+
expect(timeago(sample_date.prev_day(14), sample_date, only: :weeks)).to eq('2 weeks ago')
|
161
|
+
expect(timeago(sample_date.prev_day(30), sample_date, only: :weeks)).to eq('4 weeks ago')
|
162
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :weeks)).to eq('52 weeks ago')
|
163
|
+
|
164
|
+
# Test "only: :months"
|
165
|
+
expect(timeago(sample_date.prev_day(30), sample_date, only: :months)).to eq('1 month ago')
|
166
|
+
expect(timeago(sample_date.prev_day(60), sample_date, only: :months)).to eq('2 months ago')
|
167
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :months)).to eq('12 months ago')
|
168
|
+
|
169
|
+
# Test "only: :years"
|
170
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :years)).to eq('1 year ago')
|
171
|
+
expect(timeago(sample_date.prev_day(730), sample_date, only: :years)).to eq('2 years ago')
|
172
|
+
expect(timeago(sample_date.prev_day(1000), sample_date, only: :years)).to eq('3 years ago')
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'allows "only" option with different styles' do
|
176
|
+
# Test with short style
|
177
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :weeks, style: :short)).to eq('52w ago')
|
178
|
+
expect(timeago(sample_date.prev_day(30), sample_date, only: :months, style: :short)).to eq('1mo ago')
|
179
|
+
|
180
|
+
# Test with array style
|
181
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :weeks, style: :array)).to eq(['52 weeks'])
|
182
|
+
expect(timeago(sample_date.prev_day(30), sample_date, only: :months, style: :array)).to eq(['1 month'])
|
183
|
+
|
184
|
+
# Test with hash style
|
185
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :weeks, style: :hash)).to eq({weeks: 52})
|
186
|
+
expect(timeago(sample_date.prev_day(30), sample_date, only: :months, style: :hash)).to eq({months: 1})
|
187
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :days, style: :hash)).to eq({days: 365})
|
188
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :years, style: :hash)).to eq({years: 1})
|
189
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :weeks, style: :hash, locale: :es)).to eq({semanas: 52})
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'allows "only" option with different locales' do
|
193
|
+
expect(timeago(sample_date.prev_day(30), sample_date, only: :weeks, locale: :es)).to eq('hace 4 semanas')
|
194
|
+
expect(timeago(sample_date.prev_day(365), sample_date, only: :months, locale: :fr)).to eq('il y a environ 12 mois')
|
82
195
|
end
|
83
196
|
end
|
84
197
|
|
85
198
|
context 'CLI' do
|
86
199
|
it 'prints help message if called with no params or --help' do
|
87
|
-
expect(`bin/
|
88
|
-
expect(`bin/
|
200
|
+
expect(`bin/timeago`).to match("Usage")
|
201
|
+
expect(`bin/timeago --help`).to match("Usage")
|
89
202
|
end
|
90
203
|
|
91
204
|
it 'prints current version' do
|
92
|
-
expect(`bin/
|
93
|
-
expect(`bin/
|
205
|
+
expect(`bin/timeago -v`).to match("v#{Jekyll::Timeago::VERSION}")
|
206
|
+
expect(`bin/timeago --version`).to match("v#{Jekyll::Timeago::VERSION}")
|
94
207
|
end
|
95
208
|
|
96
209
|
it 'computes distance of dates' do
|
97
|
-
expect(`bin/
|
210
|
+
expect(`bin/timeago 2016-1-1 2016-1-5`).to match("4 days ago")
|
98
211
|
end
|
99
212
|
|
100
213
|
it 'prints error with invalid date' do
|
101
|
-
expect(`bin/
|
214
|
+
expect(`bin/timeago 0`).to match("Error!")
|
102
215
|
end
|
103
216
|
|
104
217
|
it 'with custom locale' do
|
105
|
-
expect(`bin/
|
106
|
-
expect(`bin/
|
107
|
-
expect(`bin/
|
218
|
+
expect(`bin/timeago 2016-1-1 2016-1-5 -l fr`).to match("il y a environ 4 jours")
|
219
|
+
expect(`bin/timeago 2016-1-1 2016-1-5 --locale fr`).to match("il y a environ 4 jours")
|
220
|
+
expect(`bin/timeago 2016-1-1 2016-1-5 --locale ru`).to match("4 дня назад")
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'with short style' do
|
224
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 -s short`).to match("2y and 1d ago")
|
225
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 --style short`).to match("2y and 1d ago")
|
226
|
+
expect(`bin/timeago 2016-1-1 2016-2-1 -s short`).to match("1mo and 1d ago")
|
227
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 -l fr -s short`).to match("il y a environ 2a")
|
228
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 --locale ru --style short`).to match("2г и 1д назад")
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'with hash style' do
|
232
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 --style hash`).to match("{:years=>2, :days=>1}")
|
233
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 -s hash`).to match("{:years=>2, :days=>1}")
|
234
|
+
expect(`bin/timeago 2016-1-1 2016-2-1 --style hash`).to match("{:months=>1, :days=>1}")
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'with only option' do
|
238
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 --only weeks`).to match("104 weeks ago")
|
239
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 -o months`).to match("24 months ago")
|
240
|
+
expect(`bin/timeago 2016-1-1 2016-2-1 --only days`).to match("31 days ago")
|
241
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 -l fr --only months`).to match("il y a environ 24 mois")
|
242
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 --only weeks -s short`).to match("104w ago")
|
243
|
+
expect(`bin/timeago 2016-1-1 2018-1-1 --only weeks --style hash`).to match("{:weeks=>104}")
|
108
244
|
end
|
109
245
|
end
|
110
246
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-timeago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markets
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mini_i18n
|
@@ -85,7 +85,7 @@ description: A Ruby library to compute distance of dates in words. Originally bu
|
|
85
85
|
email:
|
86
86
|
- srmarc.ai@gmail.com
|
87
87
|
executables:
|
88
|
-
-
|
88
|
+
- timeago
|
89
89
|
extensions: []
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
@@ -96,7 +96,7 @@ files:
|
|
96
96
|
- LICENSE
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
|
-
- bin/
|
99
|
+
- bin/timeago
|
100
100
|
- gemfiles/jekyll_v3.gemfile
|
101
101
|
- gemfiles/jekyll_v4.gemfile
|
102
102
|
- jekyll-timeago.gemspec
|
@@ -110,9 +110,10 @@ files:
|
|
110
110
|
- lib/locales/es.yml
|
111
111
|
- lib/locales/fr.yml
|
112
112
|
- lib/locales/it.yml
|
113
|
-
- lib/locales/ja.
|
113
|
+
- lib/locales/ja.yml
|
114
114
|
- lib/locales/pt.yml
|
115
115
|
- lib/locales/ru.yml
|
116
|
+
- lib/locales/tr.yml
|
116
117
|
- lib/locales/zh_hans.yml
|
117
118
|
- spec/jekyll-timeago_spec.rb
|
118
119
|
- spec/source/_config.yml
|
@@ -123,7 +124,7 @@ homepage: https://github.com/markets/jekyll-timeago
|
|
123
124
|
licenses:
|
124
125
|
- MIT
|
125
126
|
metadata: {}
|
126
|
-
post_install_message:
|
127
|
+
post_install_message:
|
127
128
|
rdoc_options: []
|
128
129
|
require_paths:
|
129
130
|
- lib
|
@@ -138,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
- !ruby/object:Gem::Version
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
|
-
rubygems_version: 3.
|
142
|
-
signing_key:
|
142
|
+
rubygems_version: 3.4.10
|
143
|
+
signing_key:
|
143
144
|
specification_version: 4
|
144
145
|
summary: A date helper to compute distance of dates in words.
|
145
146
|
test_files:
|
data/bin/jekyll-timeago
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require_relative "../lib/jekyll-timeago"
|
4
|
-
|
5
|
-
help_message = <<~HELP_MESSAGE
|
6
|
-
Usage:
|
7
|
-
|
8
|
-
jekyll-timeago <from_date> [to_date]
|
9
|
-
|
10
|
-
Notes:
|
11
|
-
[to_date] Optional, defaults to current date
|
12
|
-
|
13
|
-
Options:
|
14
|
-
--help, -h Prints this message
|
15
|
-
--version, -v Prints the current version
|
16
|
-
--console, -c Starts an interactive IRB session with jekyll-timeago included
|
17
|
-
--locale, -l Uses the provided locale
|
18
|
-
HELP_MESSAGE
|
19
|
-
|
20
|
-
if ARGV.empty? || ARGV.include?("--help") || ARGV.include?("-h")
|
21
|
-
puts help_message
|
22
|
-
elsif ARGV.include?("--version") || ARGV.include?("-v")
|
23
|
-
puts "v#{Jekyll::Timeago::VERSION}"
|
24
|
-
elsif ARGV.include?("--console") || ARGV.include?("-c")
|
25
|
-
require "irb"
|
26
|
-
include Jekyll::Timeago
|
27
|
-
|
28
|
-
ARGV.clear
|
29
|
-
IRB.start
|
30
|
-
else
|
31
|
-
custom_locale = "--locale" if ARGV.include?("--locale")
|
32
|
-
custom_locale = "-l" if ARGV.include?("-l")
|
33
|
-
|
34
|
-
if custom_locale
|
35
|
-
index = ARGV.index(custom_locale)
|
36
|
-
locale = ARGV.delete_at(index + 1)
|
37
|
-
ARGV.delete_at(index)
|
38
|
-
|
39
|
-
options = { locale: locale }
|
40
|
-
ARGV << options
|
41
|
-
end
|
42
|
-
|
43
|
-
begin
|
44
|
-
puts Jekyll::Timeago.timeago *ARGV
|
45
|
-
rescue ArgumentError => e
|
46
|
-
puts "Error! #{e}"
|
47
|
-
end
|
48
|
-
end
|