Skip to content

Commit

Permalink
fix time to second helper
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Chulak <vchulakv@gmail.com>
  • Loading branch information
Jedoku committed Feb 12, 2024
1 parent a18fc02 commit b98b042
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/auxiliary/time_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
module AutoHCK
# Helper module
module Helper
def time_to_seconds(time)
time.split(':').reverse.map.with_index { |a, i| a.to_i * (60**i) }
.reduce(:+)
def time_to_seconds(time_str)
days, time_part = time_str.split('.')
hours, minutes, seconds = time_part.split(':').map(&:to_i)
total_hours = (days.to_i * 24) + hours
(total_hours * 3600) + (minutes * 60) + seconds
end

def seconds_to_time(sec)
Expand Down

0 comments on commit b98b042

Please sign in to comment.