midwire_common 0.1.3 → 0.1.4
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.
- data/CHANGELOG +4 -0
- data/README.md +1 -1
- data/lib/midwire_common/all.rb +1 -0
- data/lib/midwire_common/time_tool.rb +35 -0
- data/lib/midwire_common/version.rb +1 -1
- data/spec/lib/midwire_common/time_tool_spec.rb +13 -0
- metadata +7 -4
data/CHANGELOG
CHANGED
data/README.md
CHANGED
data/lib/midwire_common/all.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module MidwireCommon
|
2
|
+
|
3
|
+
class TimeTool
|
4
|
+
|
5
|
+
# converts the given time (HH:MM:SS) to seconds
|
6
|
+
#
|
7
|
+
# +time+ the time-string
|
8
|
+
def self.time_to_seconds(time)
|
9
|
+
return -1 if time.nil? or time.strip.empty?
|
10
|
+
times = time.split(/:/).reverse
|
11
|
+
seconds = 0
|
12
|
+
for i in (0...times.length)
|
13
|
+
seconds += times[i].to_i * (60**i)
|
14
|
+
end
|
15
|
+
return seconds
|
16
|
+
end
|
17
|
+
|
18
|
+
# converts the given seconds into a time string (HH:MM:SS)
|
19
|
+
#
|
20
|
+
# +seconds+ the seconds to convert
|
21
|
+
def self.seconds_to_time(seconds)
|
22
|
+
return "unknown" if seconds.nil?
|
23
|
+
t = seconds
|
24
|
+
time = ""
|
25
|
+
2.downto(0) { |i|
|
26
|
+
tmp = t / (60**i)
|
27
|
+
t = t - tmp * 60**i
|
28
|
+
time = time + ":" if not time.empty?
|
29
|
+
time = time + ("%02d" % tmp)
|
30
|
+
}
|
31
|
+
return time
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MidwireCommon::TimeTool do
|
4
|
+
|
5
|
+
it "converts seconds to timestamp" do
|
6
|
+
MidwireCommon::TimeTool.seconds_to_time(92353).should == "25:39:13"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "converts timestamp to seconds" do
|
10
|
+
MidwireCommon::TimeTool.time_to_seconds("25:39:13").should == 92353
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midwire_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/midwire_common/rake_tasks.rb
|
185
185
|
- lib/midwire_common/string.rb
|
186
186
|
- lib/midwire_common/time.rb
|
187
|
+
- lib/midwire_common/time_tool.rb
|
187
188
|
- lib/midwire_common/version.rb
|
188
189
|
- lib/tasks/version.rake
|
189
190
|
- midwire_common.gemspec
|
@@ -196,6 +197,7 @@ files:
|
|
196
197
|
- spec/lib/midwire_common/hash_spec.rb
|
197
198
|
- spec/lib/midwire_common/string_spec.rb
|
198
199
|
- spec/lib/midwire_common/time_spec.rb
|
200
|
+
- spec/lib/midwire_common/time_tool_spec.rb
|
199
201
|
- spec/spec_helper.rb
|
200
202
|
homepage: http://git-2.americadirect.net/prosup
|
201
203
|
licenses: []
|
@@ -211,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
213
|
version: '0'
|
212
214
|
segments:
|
213
215
|
- 0
|
214
|
-
hash:
|
216
|
+
hash: 2378234403548503770
|
215
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
218
|
none: false
|
217
219
|
requirements:
|
@@ -220,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
222
|
version: '0'
|
221
223
|
segments:
|
222
224
|
- 0
|
223
|
-
hash:
|
225
|
+
hash: 2378234403548503770
|
224
226
|
requirements: []
|
225
227
|
rubyforge_project:
|
226
228
|
rubygems_version: 1.8.23
|
@@ -237,4 +239,5 @@ test_files:
|
|
237
239
|
- spec/lib/midwire_common/hash_spec.rb
|
238
240
|
- spec/lib/midwire_common/string_spec.rb
|
239
241
|
- spec/lib/midwire_common/time_spec.rb
|
242
|
+
- spec/lib/midwire_common/time_tool_spec.rb
|
240
243
|
- spec/spec_helper.rb
|