Skip to content

Commit

Permalink
Matching seconds including fraction
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Chulak <[email protected]>
  • Loading branch information
Jedoku committed Feb 13, 2024
1 parent 9aaaf50 commit 4c36b0d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/auxiliary/time_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ module AutoHCK
# Helper module
module Helper
def time_to_seconds(time_string)
match = time_string.match(/^(?:(\d+)\.)?(?:(\d+):)?(\d+)(?::(\d+))?(?:\.(\d+))?$/)
match = time_string.match(/^(?:(\d+)\.)?(?:(\d+):)?(\d+)(?::(\d+(?:\.\d+)?))?$/)

return 0 unless match

days = match[1].to_i
hours = match[2].to_i
minutes = match[3].to_i
seconds = match[4].to_i
fractional_seconds = "0.#{match[5]}".to_f
seconds = match[4].to_f

(((((days * 24) + hours) * 60) + minutes) * 60) + seconds + fractional_seconds
(((((days * 24) + hours) * 60) + minutes) * 60) + seconds
end

def seconds_to_time(sec)
Expand Down

0 comments on commit 4c36b0d

Please sign in to comment.