19/12/15 12:02:23.68 fpSJINfx.net
>>309
Ruby で、
require 'active_support/time'
def calculate_time_span( now, alarm )
current = Time.now
now_time = Time.parse( now, current ) #=> 2019-12-15 22:00:00 +0900
alarm_time = Time.parse( alarm, current ) #=> 2019-12-15 04:00:00 +0900
diff_time = alarm_time - now_time
# アラームが翌日の場合
diff_time = alarm_time.tomorrow - now_time if diff_time < 0
Time.at( diff_time ).utc.strftime( '%H:%M' )
end
inputs = %w(10:00 16:00 22:00 04:00) # (現在時刻, アラーム時刻)の組
inputs.each_slice( 2 ) do |now, alarm| # 2個ずつ処理する
puts calculate_time_span( now, alarm )
end