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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ce9f3b81f3058ca271bb33e8aab091a5d936eff
4
- data.tar.gz: 9b245e41282a23f1333cfb80a6d1b1c6beed5953
3
+ metadata.gz: ce751a32b46622b7598930e90f09833a2512fa97
4
+ data.tar.gz: ebc02be103a8e349dfc76953db366b53687c34d2
5
5
  SHA512:
6
- metadata.gz: 6194dac4f69f41b89e8aae585c63dd862449b42fc5f8789aa78ef614eb7f677f376da09c470cbb91339e476d18270c30d1d50ba4b18ec0fc69c50b4fb26b44bf
7
- data.tar.gz: f8756ad6be4616c569f5b14224ad06ef5f6641b07e3af36618e217ae3974adbcd35c13f131e4ae1e92fba414bd63bdc4bc2a1ba48a1a077d5dde10081787c1a7
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)
@@ -0,0 +1,11 @@
1
+ module Tepoch
2
+ class Clock
3
+
4
+ def tick(to_utc = true)
5
+ timestamp = Time.now.to_i
6
+
7
+ print "#{timestamp} | #{Tepoch.to_time(timestamp, to_utc)} | #{Util.seconds_to_string(timestamp)} \r"
8
+ end
9
+
10
+ end
11
+ end
@@ -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
@@ -1,8 +1,8 @@
1
1
  module Tepoch
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 2
5
- PATCH = 1
4
+ MINOR = 3
5
+ PATCH = 0
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].compact.join(".")
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tepoch::Clock do
4
+ it 'doo' do
5
+ loop do
6
+ Tepoch::Clock.new.tick
7
+ sleep(1)
8
+ end
9
+ end
10
+ end
@@ -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.2.1
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