篇首语:本文由编程笔记#自由互联小编为大家整理,主要介绍了ruby 检查什么时候回家相关的知识,希望对你有一定的参考价值。
#! /usr/bin/env ruby# ./worktime 10:12 [13:06] [14:15] [19:40]now = Time.nowexpected_work_time = 28800if ARGV[0].nil? puts Voc precisa fornecer ao menos o horrio de entrada exit 1endhour, min = ARGV[0].split(:)check_in = Time.new(now.year, now.month, now.day, hour, min)hour, min = ARGV[1].split(:) if ARGV[1]lunch_start = Time.new(now.year, now.month, now.day, hour, min)hour, min = ARGV[2].split(:) if ARGV[2]lunch_end = Time.new(now.year, now.month, now.day, hour, min)lunch_time = (lunch_end - lunch_start)if ARGV[3].nil? check_out = check_in + (expected_work_time + lunch_time) work_time = (now - check_in) - lunch_timeelse hour, min = ARGV[3].split(:) if ARGV[3] check_out = Time.new(now.year, now.month, now.day, hour, min) work_time = (check_out - check_in) - lunch_timeendwork_delta = work_time - expected_work_timework_hour, work_min = (work_time / 60).divmod(60)hour_diff, min_diff = (work_delta.abs / 60).divmod(60)puts Horrio de saida: + check_out.strftime(%H:%M)if work_delta > 0 puts "Horas trabalhadas: \e[1m\e[32m#{work_hour}:#{work_min.to_i} (hora extra!)\e[0m" puts "Horas extras: \e[1m\e[32m#{hour_diff}:#{min_diff.to_i}"elsif work_delta <0 puts "Horas trabalhadas: \e[1m\e[31m#{work_hour}:#{work_min.to_i} (faltam horas)\e[0m" puts "Horas faltantes: \e[1m\e[31m#{hour_diff}:#{min_diff.to_i}"else puts "Sem horas extras a registrar"end