describe_time 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/describe_time.rb +28 -8
- metadata +4 -4
data/lib/describe_time.rb
CHANGED
@@ -1,13 +1,33 @@
|
|
1
1
|
module DescribeTime
|
2
|
-
def self.
|
3
|
-
if
|
4
|
-
|
2
|
+
def self.time_or_date(tm = Time.now, now = Time.now, time_fmt = '%H:%M', date_fmt = '%Y-%m-%d')
|
3
|
+
if tm.year == now.year && tm.yday == now.yday then
|
4
|
+
tm.strftime(time_fmt)
|
5
5
|
else
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
tm.strftime(date_fmt)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.approximate(the_time = Time.now, current_time = Time.now)
|
11
|
+
ts = current_time - the_time
|
12
|
+
|
13
|
+
if ts < 0
|
14
|
+
"time in the future"
|
15
|
+
elsif ts < 5 # <- Five seconds
|
16
|
+
"a few seconds ago"
|
17
|
+
elsif ts < 60 # <- One minute
|
18
|
+
"less than a minute ago"
|
19
|
+
elsif ts < 180 # <- Three minutes
|
20
|
+
"a few minutes ago"
|
21
|
+
elsif ts < 60 * 60 # <- One hour
|
22
|
+
"%d minutes ago" % (ts / 60).to_i
|
23
|
+
elsif ts < 2*60*60 # <- Two hours
|
24
|
+
"one hour and %d minutes ago" % ((ts - 60*60) / 60).to_i
|
25
|
+
elsif ts < 48*60*60 # <- Two days (48 hours)
|
26
|
+
"%d hours ago" % (ts / 60*60).to_i
|
27
|
+
elsif ts < 2*7*24*60*60 # <- Two weeks (14 days)
|
28
|
+
"%d days ago" % (ts / 24*60*60).to_i
|
29
|
+
else
|
30
|
+
"%d weeks ago" % (ts / 7*24*60*60).to_i
|
11
31
|
end
|
12
32
|
end
|
13
33
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: describe_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonatan Magnusson
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
requirements: []
|
58
58
|
|
59
59
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.8.
|
60
|
+
rubygems_version: 1.8.24
|
61
61
|
signing_key:
|
62
62
|
specification_version: 3
|
63
63
|
summary: Format date and time as readable strings
|