tiny_eta 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tiny_eta.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df7971d0e4357130ab623fdf5f7c913519f08a8e6279f6dbd8dc347599257bea
|
4
|
+
data.tar.gz: 6377a1c565dd139be96049a468db611e60d3f8eb4b7b6118c6abe48b4936e5c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 694f1021815f0ed255a04c45792635373aad552a617b9c95b7c3250cdc7bc38c80cbb40fe22922e6c35e7177d46a081590f95aaead5efef02ab0b52b0ade436c
|
7
|
+
data.tar.gz: add57c787cf01b2dd745a5452ded44c392688a7639c41613f5e15abee2b73af426c3edda29b376ceb905bbc06fa3fbc9386e39ab901375851e31ab8ff979dc12
|
data/lib/tiny_eta.rb
CHANGED
@@ -18,11 +18,15 @@ module TinyEta
|
|
18
18
|
# elapsed: the number of seconds elapsed (Integer or Float)
|
19
19
|
# percent_complete: 0.0..1.0 - the percent completion (Float)
|
20
20
|
def self.eta(elapsed, percent_complete)
|
21
|
+
return "?d ??:??:??" if percent_complete == 0
|
22
|
+
|
21
23
|
percent_remaining = (1.0 - percent_complete)
|
22
24
|
remaining_time = ((elapsed / percent_complete) * percent_remaining).round
|
23
25
|
puts remaining_time
|
24
26
|
|
25
27
|
days = (remaining_time / SECONDS_PER_DAY.to_f).to_i
|
28
|
+
return "?d ??:??:??" if days > 999
|
29
|
+
|
26
30
|
remaining_time -= days * SECONDS_PER_DAY
|
27
31
|
|
28
32
|
hours = (remaining_time / SECONDS_PER_HOUR.to_f).to_i
|