tepoch 0.2.1 → 0.3.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/bin/tepoch +6 -0
- data/lib/tepoch.rb +3 -23
- data/lib/tepoch/clock.rb +11 -0
- data/lib/tepoch/util.rb +27 -0
- data/lib/tepoch/version.rb +2 -2
- data/spec/tepoch/clock_spec.rb +10 -0
- data/spec/tepoch/util_spec.rb +10 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce751a32b46622b7598930e90f09833a2512fa97
|
4
|
+
data.tar.gz: ebc02be103a8e349dfc76953db366b53687c34d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fd0da5a7aaee5c5f9839ec56cb4e37c14132ace50dfd56e7fd0ca2b3ccb4bf83951b9549f96a1bfb679ac9a602daef52320c7d1712d352be676e1488cb161c0
|
7
|
+
data.tar.gz: 95af94938ce751850a8d586e41cc5a3546694f0b9530798c658a41d18cc969d137a40594eaf429694c30fd7f42dca2ed171b2f1f3db4743cec1b782b47810ec6
|
data/bin/tepoch
CHANGED
@@ -24,6 +24,12 @@ if ARGV[1] && arithmetic_symbols.include?(ARGV[1])
|
|
24
24
|
diff = t1.send(ARGV[1], t2)
|
25
25
|
|
26
26
|
puts (options[:keep_as_timestamp]) ? diff : Tepoch::Tepoch.seconds_to_string(diff)
|
27
|
+
elsif ARGV[0] == "clock"
|
28
|
+
clock = Tepoch::Clock.new
|
29
|
+
loop do
|
30
|
+
clock.tick(options[:utc])
|
31
|
+
sleep(1)
|
32
|
+
end
|
27
33
|
else
|
28
34
|
if options[:keep_as_timestamp]
|
29
35
|
puts ARGV
|
data/lib/tepoch.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'tepoch/util'
|
2
|
+
require 'tepoch/clock'
|
3
|
+
|
1
4
|
module Tepoch
|
2
5
|
class Tepoch
|
3
6
|
def self.to_time(timestamp, to_utc = true)
|
@@ -6,29 +9,6 @@ module Tepoch
|
|
6
9
|
to_utc ? new_time.utc : new_time
|
7
10
|
end
|
8
11
|
|
9
|
-
def self.seconds_to_string(s)
|
10
|
-
|
11
|
-
# d = days, h = hours, m = minutes, s = seconds
|
12
|
-
m = (s / 60).floor
|
13
|
-
s = s % 60
|
14
|
-
h = (m / 60).floor
|
15
|
-
m = m % 60
|
16
|
-
d = (h / 24).floor
|
17
|
-
h = h % 24
|
18
|
-
|
19
|
-
output = "#{s} second#{Tepoch.pluralize(s)}" if (s > 0)
|
20
|
-
output = "#{m} minute#{Tepoch.pluralize(m)}, #{s} second#{Tepoch.pluralize(s)}" if (m > 0)
|
21
|
-
output = "#{h} hour#{Tepoch.pluralize(h)}, #{m} minute#{Tepoch.pluralize(m)}, #{s} second#{Tepoch.pluralize(s)}" if (h > 0)
|
22
|
-
output = "#{d} day#{Tepoch.pluralize(d)}, #{h} hour#{Tepoch.pluralize(h)}, #{m} minute#{Tepoch.pluralize(m)}, #{s} second#{Tepoch.pluralize(s)}" if (d > 0)
|
23
|
-
|
24
|
-
return output
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.pluralize number
|
28
|
-
return "s" unless number == 1
|
29
|
-
return ""
|
30
|
-
end
|
31
|
-
|
32
12
|
private
|
33
13
|
|
34
14
|
def self.milliseconds?(timestamp)
|
data/lib/tepoch/clock.rb
ADDED
data/lib/tepoch/util.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Tepoch
|
2
|
+
class Util
|
3
|
+
def self.seconds_to_string(s)
|
4
|
+
|
5
|
+
# d = days, h = hours, m = minutes, s = seconds
|
6
|
+
m = (s / 60).floor
|
7
|
+
s = s % 60
|
8
|
+
h = (m / 60).floor
|
9
|
+
m = m % 60
|
10
|
+
d = (h / 24).floor
|
11
|
+
h = h % 24
|
12
|
+
|
13
|
+
output = "#{s} second#{Util.pluralize(s)}" if (s > 0)
|
14
|
+
output = "#{m} minute#{Util.pluralize(m)}, #{s} second#{Util.pluralize(s)}" if (m > 0)
|
15
|
+
output = "#{h} hour#{Util.pluralize(h)}, #{m} minute#{Util.pluralize(m)}, #{s} second#{Util.pluralize(s)}" if (h > 0)
|
16
|
+
output = "#{d} day#{Util.pluralize(d)}, #{h} hour#{Util.pluralize(h)}, #{m} minute#{Util.pluralize(m)}, #{s} second#{Util.pluralize(s)}" if (d > 0)
|
17
|
+
|
18
|
+
return output
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.pluralize number
|
22
|
+
return "s" unless number == 1
|
23
|
+
return ""
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/tepoch/version.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Tepoch::Util do
|
4
|
+
it 'converts seconds to a human readable string' do
|
5
|
+
Tepoch::Util.seconds_to_string(1).should eq "1 second"
|
6
|
+
Tepoch::Util.seconds_to_string(60).should eq "1 minute, 0 seconds"
|
7
|
+
Tepoch::Util.seconds_to_string(3600).should eq "1 hour, 0 minutes, 0 seconds"
|
8
|
+
Tepoch::Util.seconds_to_string(86400).should eq "1 day, 0 hours, 0 minutes, 0 seconds"
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tepoch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Jorgensen
|
@@ -45,10 +45,14 @@ executables:
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ./lib/tepoch/clock.rb
|
49
|
+
- ./lib/tepoch/util.rb
|
48
50
|
- ./lib/tepoch/version.rb
|
49
51
|
- ./lib/tepoch.rb
|
50
52
|
- ./spec/spec_helper.rb
|
53
|
+
- ./spec/tepoch/clock_spec.rb
|
51
54
|
- ./spec/tepoch/formatter_spec.rb
|
55
|
+
- ./spec/tepoch/util_spec.rb
|
52
56
|
- ./spec/tepoch_spec.rb
|
53
57
|
- bin/tepoch
|
54
58
|
homepage: https://github.com/ajorgensen/tepoch
|