describe_time 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. data/lib/describe_time.rb +28 -8
  2. metadata +4 -4
data/lib/describe_time.rb CHANGED
@@ -1,13 +1,33 @@
1
1
  module DescribeTime
2
- def self.describe_time(the_time = Time.now, current_time = Time.now)
3
- if current_time - the_time < 0
4
- puts "Time in the future"
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
- if current_time - the_time < 5
7
- puts "Seconds ago"
8
- else
9
- puts the_time
10
- end
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
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.17
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