tepoch 0.1.0 → 0.2.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: e0fd0497d83adc7ee28992537b7fc897f1aff495
4
- data.tar.gz: 4f211fd3ec23fd5539d12df804e363ff6e0f247e
3
+ metadata.gz: e0f14e563cc475a7aaa54329b7828626d34cd86b
4
+ data.tar.gz: 13316e185d45ec84ed9a9be5e1c3010c010b6c0e
5
5
  SHA512:
6
- metadata.gz: 1f34907b3f5289cbc5dee20d58bd58ce9795c5c1dff14022461303c7125e9fa45da30f10108f7e261181377a608f1e3b51742d59703200b891fa5cd75cb9cd09
7
- data.tar.gz: 78d6333a185f8062e562919a6f957ae42aa7e89b4e7caec8df35cbca27a9eef582423fbbb59cd4090142a7849c0deeba0dfac3b9d63b487bd5120f6fc0694ad3
6
+ metadata.gz: ea1d2297366ea4837c9465889aef16ac3fd93686b78544e4ca20193698c7fafd567e5c41604c22118c1cac8367c4a3d713833041668853d85c7847b941cc4a8c
7
+ data.tar.gz: b81d7eee040dd2bb8889de9ef1594436f7bfcb8a4584c9f26ab308f715d510e5ba6c32b8c7fc3cb3a45a01b9f1e3dec9b6eb3aecc29f0ef811c3ccbda8f6087a
data/bin/tepoch CHANGED
@@ -3,13 +3,36 @@
3
3
  require 'tepoch'
4
4
  require 'optparse'
5
5
 
6
- options = { :utc => true }
6
+ options = { :utc => true, :keep_as_timestamp => false }
7
7
  OptionParser.new do |opts|
8
8
  opts.banner = "Usage: tepoch [options"
9
9
 
10
- opts.on("-local", "Convert to local time") do |v|
10
+ opts.on("--local", "Convert to local time") do |v|
11
11
  options[:utc] = false
12
12
  end
13
+
14
+ opts.on("--timestamp", "Keep as timestamp") do |v|
15
+ options[:keep_as_timestamp] = true
16
+ end
13
17
  end.parse!
14
18
 
15
- puts ARGV.map { |timestamp| Tepoch::Tepoch.to_time(timestamp.to_i, options[:utc]) }
19
+ arithmetic_symbols = %w(- +)
20
+ if ARGV[1] && arithmetic_symbols.include?(ARGV[1])
21
+ t1 = ARGV[0].to_i
22
+ t2 = ARGV[2].to_i
23
+
24
+ diff = t1.send(ARGV[1], t2)
25
+
26
+ if ARGV[1] == "-"
27
+ puts Tepoch::Tepoch.seconds_to_string(diff)
28
+ else
29
+ puts options[:keep_as_timestamp] ? diff.to_i : Tepoch::Tepoch.to_time(diff, options[:utc])
30
+ end
31
+
32
+ else
33
+ if options[:keep_as_timestamp]
34
+ puts ARGV
35
+ else
36
+ puts ARGV.map { |timestamp| Tepoch::Tepoch.to_time(timestamp.to_i, options[:utc]) }
37
+ end
38
+ end
@@ -1,7 +1,7 @@
1
1
  module Tepoch
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
 
7
7
  def self.to_s
data/lib/tepoch.rb CHANGED
@@ -6,6 +6,29 @@ module Tepoch
6
6
  to_utc ? new_time.utc : new_time
7
7
  end
8
8
 
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
+
9
32
  private
10
33
 
11
34
  def self.milliseconds?(timestamp)
@@ -13,4 +13,5 @@ describe Tepoch::Tepoch do
13
13
  it 'convert can convert to utc' do
14
14
  Tepoch::Tepoch.to_time(timestamp, true).should be_utc
15
15
  end
16
+
16
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tepoch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Jorgensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Easy way to convert and interactive with epoch timestamps in the terminal
41
+ description: Easy way to convert and interact with epoch timestamps in the terminal
42
42
  email: andrew@andrewjorgensen.com
43
43
  executables:
44
44
  - tepoch
@@ -51,7 +51,7 @@ files:
51
51
  - ./spec/tepoch/formatter_spec.rb
52
52
  - ./spec/tepoch_spec.rb
53
53
  - bin/tepoch
54
- homepage: http://rubygems.org/gems/hola
54
+ homepage: https://github.com/ajorgensen/tepoch
55
55
  licenses:
56
56
  - MIT
57
57
  metadata: {}