Last active
November 4, 2021 22:56
-
-
Save puppe1990/d65f8cba8fdb039cab4fcb334220733c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first_hour = "08:06" | |
second_hour = "10:56" | |
third_hour = "14:39" | |
forth_hour = "19:45" | |
def working_hours(first_hour, second_hour, third_hour, forth_hour) | |
first_hour_hours = first_hour.split(":")[0].to_i * 60 + first_hour.split(":")[1].to_i | |
second_hour_hours = second_hour.split(":")[0].to_i * 60 + second_hour.split(":")[1].to_i | |
third_hour_hours = third_hour.split(":")[0].to_i * 60 + third_hour.split(":")[1].to_i | |
forth_hour_hours = forth_hour.split(":")[0].to_i * 60 + forth_hour.split(":")[1].to_i | |
minutes = second_hour_hours - first_hour_hours + forth_hour_hours - third_hour_hours | |
hours = 0 if hours.nil? | |
minutes = 0 if minutes.nil? | |
hours += (minutes / 60).floor | |
minutes = minutes.to_i % 60 | |
return "#{hours}:#{minutes.to_s.rjust(2, "0")}" | |
end | |
working_hours(first_hour, second_hour, third_hour, forth_hour) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment