time_ago_in_words 0.0.1 → 0.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/.travis.yml +0 -1
- data/CHANGELOG.md +12 -1
- data/lib/time_ago_in_words/methods.rb +19 -7
- data/lib/time_ago_in_words/version.rb +1 -1
- data/spec/time_ago_in_words_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3643c74e96a16cf5b7a3052eec2cf8b0041d89c4
|
4
|
+
data.tar.gz: b835b4a256c661bfb5133da03e55cbceccdb6b75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 434184bf95eed3f42cf0cdaf0c04340c35fb9dbe661cf0296e80f819c5aa4b0d48bf70deeba089e4d3cfc3a2e828d2060d77854d818769973116c647a5542c67
|
7
|
+
data.tar.gz: 3cb1145b769db7a50b466c36bf192b47afa12ede96692da37116a2387186306badb6121523e9149fde2e1d884b71ecd43c52238f58ffae5501c4b337e621b4e2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## [In git](https://github.com/elgalu/time_ago_in_words/compare/v0.0
|
1
|
+
## [In git](https://github.com/elgalu/time_ago_in_words/compare/v0.1.0...HEAD)
|
2
2
|
|
3
3
|
### New Features
|
4
4
|
* n/a
|
@@ -9,6 +9,17 @@
|
|
9
9
|
### Chores
|
10
10
|
* n/a
|
11
11
|
|
12
|
+
## [v0.1.0](https://github.com/elgalu/time_ago_in_words/tree/v0.1.0)
|
13
|
+
|
14
|
+
### New Features
|
15
|
+
* n/a
|
16
|
+
|
17
|
+
### Bugfixes
|
18
|
+
* Removed support for ruby 1.8.7 due to 'time ouf of range' errors. (Leo Gallucci)
|
19
|
+
|
20
|
+
### Chores
|
21
|
+
* Applied Extract Method refactor on Time#ago_in_words(). (Leo Gallucci)
|
22
|
+
|
12
23
|
## [v0.0.1](https://github.com/elgalu/time_ago_in_words/tree/v0.0.1)
|
13
24
|
|
14
25
|
## First gem release
|
@@ -20,22 +20,34 @@ module TimeAgoInWords
|
|
20
20
|
#
|
21
21
|
# @note Inspired from http://stackoverflow.com/a/4136485/511069
|
22
22
|
def ago_in_words
|
23
|
+
return 'a very very long time ago' if self.year < 1800
|
23
24
|
secs = Time.now - self
|
24
25
|
return 'just now' if secs > -1 && secs < 1
|
25
26
|
return '' if secs <= -1
|
26
|
-
|
27
|
-
ary =
|
27
|
+
pair = ago_in_words_pair(secs)
|
28
|
+
ary = ago_in_words_singularize(pair)
|
29
|
+
ary.size == 0 ? '' : ary.join(' and ') << ' ago'
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# @private
|
35
|
+
def ago_in_words_pair(secs)
|
36
|
+
[[60, :seconds], [60, :minutes], [24, :hours], [100_000, :days]].map{ |count, name|
|
28
37
|
if secs > 0
|
29
38
|
secs, n = secs.divmod(count)
|
30
39
|
"#{n.to_i} #{name}"
|
31
40
|
end
|
32
41
|
}.compact.reverse[0..1]
|
33
|
-
|
34
|
-
|
42
|
+
end
|
43
|
+
|
44
|
+
# @private
|
45
|
+
def ago_in_words_singularize(pair)
|
46
|
+
if pair.size == 1
|
47
|
+
pair.map! {|part| part[0, 2].to_i == 1 ? part.chomp('s') : part }
|
35
48
|
else
|
36
|
-
|
49
|
+
pair.map! {|part| part[0, 2].to_i == 1 ? part.chomp('s') : part[0, 2].to_i == 0 ? nil : part }
|
37
50
|
end
|
38
|
-
|
39
|
-
ary.size == 0 ? '' : ary.join(' and ') << ' ago'
|
51
|
+
pair.compact
|
40
52
|
end
|
41
53
|
end
|
@@ -16,15 +16,15 @@ describe TimeAgoInWords do
|
|
16
16
|
it "returns empty string on future dates" do
|
17
17
|
(Time.now + 1.6).ago_in_words.should == ''
|
18
18
|
(Time.now + 100).ago_in_words.should == ''
|
19
|
-
(Time.now +
|
19
|
+
(Time.now + 9999).ago_in_words.should == ''
|
20
20
|
end
|
21
21
|
|
22
|
-
it "returns 'a very very long time ago' when more than
|
23
|
-
|
22
|
+
it "returns 'a very very long time ago' when more than 300 years ago" do
|
23
|
+
Time.local(1713,01,01).ago_in_words.should == 'a very very long time ago'
|
24
24
|
end
|
25
25
|
|
26
26
|
it "can handle many days ago" do
|
27
|
-
(Time.now - 60*60*24*
|
27
|
+
(Time.now - 60*60*24*9999).ago_in_words.should == '9999 days ago'
|
28
28
|
end
|
29
29
|
|
30
30
|
it "returns N seconds ago, N seconds ago!" do
|