[Groonga-commit] droonga/droonga-engine at ae14394 [master] Output remaining time as XX:XX:XX format

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Nov 26 18:46:23 JST 2014


YUKI Hiroshi	2014-11-26 18:46:23 +0900 (Wed, 26 Nov 2014)

  New Revision: ae14394c12f6e79d351294a9fe18903a3b2b060a
  https://github.com/droonga/droonga-engine/commit/ae14394c12f6e79d351294a9fe18903a3b2b060a

  Message:
    Output remaining time as XX:XX:XX format

  Modified files:
    lib/droonga/data_absorber.rb

  Modified: lib/droonga/data_absorber.rb (+12 -7)
===================================================================
--- lib/droonga/data_absorber.rb    2014-11-26 16:19:03 +0900 (4de1a97)
+++ lib/droonga/data_absorber.rb    2014-11-26 18:46:23 +0900 (1af14fb)
@@ -82,19 +82,24 @@ module Droonga
       @required_time_in_seconds ||= calculate_required_time_in_seconds
     end
 
+    ONE_MINUTE_IN_SECONDS = 60
+    ONE_HOUR_IN_SECONDS = ONE_MINUTE_IN_SECONDS * 60
+
     def report_progress(start_time_in_seconds)
       return nil unless can_report_remaining_time?
 
       elapsed_time = Time.new.to_i - start_time_in_seconds
       progress = elapsed_time.to_f / required_time_in_seconds
       progress = [(progress * 100).to_i, 100].min
-      remaining_time_in_seconds = [required_time_in_seconds - elapsed_time, 0].max
-      if remaining_time_in_seconds < 60
-        "#{progress}% done (maybe #{remaining_time_in_seconds} seconds remaining)"
-      else
-        remaining_time_in_minutes = remaining_time_in_seconds.to_f / 60
-        "#{progress}% done (maybe #{sprintf("%.1f", remaining_time_in_minutes)} minutes remaining)"
-      end
+
+      remaining_seconds  = [required_time_in_seconds - elapsed_time, 0].max
+      remaining_hours    = remaining_seconds / ONE_HOUR_IN_SECONDS
+      remaining_seconds -= remaining_hours * ONE_HOUR_IN_SECONDS
+      remaining_minutes  = remaining_seconds / ONE_MINUTE_IN_SECONDS
+      remaining_seconds -= remaining_minutes * ONE_MINUTE_IN_SECONDS
+      remaining_time     = sprintf("%02i:%02i:%02i", remaining_hours, remaining_minutes, remaining_seconds)
+
+      "#{progress}% done (maybe #{remaining_time} remaining)"
     end
 
     def source_client
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index