tepoch 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e0fd0497d83adc7ee28992537b7fc897f1aff495
4
+ data.tar.gz: 4f211fd3ec23fd5539d12df804e363ff6e0f247e
5
+ SHA512:
6
+ metadata.gz: 1f34907b3f5289cbc5dee20d58bd58ce9795c5c1dff14022461303c7125e9fa45da30f10108f7e261181377a608f1e3b51742d59703200b891fa5cd75cb9cd09
7
+ data.tar.gz: 78d6333a185f8062e562919a6f957ae42aa7e89b4e7caec8df35cbca27a9eef582423fbbb59cd4090142a7849c0deeba0dfac3b9d63b487bd5120f6fc0694ad3
data/bin/tepoch ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tepoch'
4
+ require 'optparse'
5
+
6
+ options = { :utc => true }
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: tepoch [options"
9
+
10
+ opts.on("-local", "Convert to local time") do |v|
11
+ options[:utc] = false
12
+ end
13
+ end.parse!
14
+
15
+ puts ARGV.map { |timestamp| Tepoch::Tepoch.to_time(timestamp.to_i, options[:utc]) }
data/lib/tepoch.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Tepoch
2
+ class Tepoch
3
+ def self.to_time(timestamp, to_utc = true)
4
+ new_time = milliseconds?(timestamp) ? Time.at(timestamp / 1000) : Time.at(timestamp)
5
+
6
+ to_utc ? new_time.utc : new_time
7
+ end
8
+
9
+ private
10
+
11
+ def self.milliseconds?(timestamp)
12
+ timestamp > 2147483648
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Tepoch
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 0
6
+
7
+ def self.to_s
8
+ [MAJOR, MINOR, PATCH].compact.join(".")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'tepoch'
2
+ require 'pry'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tepoch::Tepoch do
4
+ let(:timestamp) { 1394483688}
5
+ it 'should conver a unix timestamp into a time object' do
6
+ Tepoch::Tepoch.to_time(timestamp).should eq Time.at(timestamp)
7
+ end
8
+
9
+ it 'handles timestamps in milliseconds as well' do
10
+ Tepoch::Tepoch.to_time(timestamp * 1000).should eq Time.at(timestamp)
11
+ end
12
+
13
+ it 'convert can convert to utc' do
14
+ Tepoch::Tepoch.to_time(timestamp, true).should be_utc
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tepoch::Tepoch do
4
+ it 'should conver a unix timestamp into a time object' do
5
+ timestamp = 1394483688
6
+ Tepoch::Tepoch.to_time(timestamp).should eq Time.at(1394483688)
7
+ end
8
+
9
+ it 'handles timestamps in milliseconds as well' do
10
+ timestamp = 1394483688000
11
+ Tepoch::Tepoch.to_time(timestamp).should eq Time.at(1394483688)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tepoch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Jorgensen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Easy way to convert and interactive with epoch timestamps in the terminal
42
+ email: andrew@andrewjorgensen.com
43
+ executables:
44
+ - tepoch
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ./lib/tepoch/version.rb
49
+ - ./lib/tepoch.rb
50
+ - ./spec/spec_helper.rb
51
+ - ./spec/tepoch/formatter_spec.rb
52
+ - ./spec/tepoch_spec.rb
53
+ - bin/tepoch
54
+ homepage: http://rubygems.org/gems/hola
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.0.3
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Terminal Epoch
78
+ test_files: []