since_when 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/NERD_tree_1 +13 -0
- data/lib/since_when/version.rb +1 -1
- data/lib/since_when.rb +79 -2
- metadata +3 -2
data/NERD_tree_1
ADDED
data/lib/since_when/version.rb
CHANGED
data/lib/since_when.rb
CHANGED
@@ -1,7 +1,84 @@
|
|
1
1
|
require "since_when/version"
|
2
2
|
|
3
3
|
module SinceWhen
|
4
|
-
def self.time_since
|
5
|
-
|
4
|
+
def self.time_since date, scope = :month
|
5
|
+
|
6
|
+
days_in_month = [31, date.year%4 == 0 ? 29 : 28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
7
|
+
time_string = ""
|
8
|
+
|
9
|
+
if date.class != Date
|
10
|
+
date = date.to_datetime
|
11
|
+
end
|
12
|
+
|
13
|
+
day_dif = Date.today.day - date.day
|
14
|
+
month_dif = Date.today.month - date.month
|
15
|
+
year_dif = Date.today.year - date.year
|
16
|
+
|
17
|
+
unless scope == :month || scope == :day
|
18
|
+
hour_dif = DateTime.now.hour - date.hour
|
19
|
+
if hour_dif < 0
|
20
|
+
day_dif -= 1
|
21
|
+
hour_dif += 24
|
22
|
+
end
|
23
|
+
unless scope == :hour
|
24
|
+
minute_dif = DateTime.now.minute - date.minute
|
25
|
+
if minute_dif < 0
|
26
|
+
hour_dif -= 1
|
27
|
+
minute_dif += 60
|
28
|
+
end
|
29
|
+
unless scope == :minute
|
30
|
+
second_dif = DateTime.now.second - date.second
|
31
|
+
if second_dif < 0
|
32
|
+
minute_dif -= 1
|
33
|
+
second_dif += 60
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if day_dif < 0
|
40
|
+
month_dif -= 1
|
41
|
+
unless scope == :month
|
42
|
+
day_dif += days_in_month[date.month + 1]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if month_dif < 0
|
47
|
+
year_dif -= 1
|
48
|
+
month_dif += 12
|
49
|
+
end
|
50
|
+
|
51
|
+
if year_dif > 0
|
52
|
+
time_string << "#{year_dif} #{year_dif > 1 ? 'years' : 'year' }"
|
53
|
+
end
|
54
|
+
|
55
|
+
if month_dif > 0
|
56
|
+
time_string << " #{month_dif} #{month_dif > 1 ? 'months' : 'month'}"
|
57
|
+
end
|
58
|
+
|
59
|
+
unless scope == :month
|
60
|
+
if day_dif > 0
|
61
|
+
time_string << " #{day_dif} #{day_dif > 1 ? 'days' : 'day'}"
|
62
|
+
end
|
63
|
+
unless scope == :day
|
64
|
+
if hour_dif > 0
|
65
|
+
time_string << " #{hour_dif} #{hour_dif > 1 ? 'hours' : 'hour'}"
|
66
|
+
end
|
67
|
+
unless scope == :hour
|
68
|
+
if minute_dif > 0
|
69
|
+
time_string << " #{minute_dif} #{minute_dif > 1 ? 'minutes' : 'minute'}"
|
70
|
+
end
|
71
|
+
unless scope == :minute
|
72
|
+
if second_dif > 0
|
73
|
+
time_string << " #{second_dif} #{second_dif > 1 ? 'seconds' : 'second'}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
time_string
|
82
|
+
|
6
83
|
end
|
7
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: since_when
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- .gitignore
|
54
54
|
- Gemfile
|
55
55
|
- LICENSE.txt
|
56
|
+
- NERD_tree_1
|
56
57
|
- README.md
|
57
58
|
- Rakefile
|
58
59
|
- lib/since_when.rb
|