下面的代码是关于一些时间处理的,感觉判断写的好挫啊,能不能改得漂亮点? 本人新手,勿喷啊~求指导
if self.start_time == nil
s_time = Time.now
s_hour = s_time.strftime('%H').to_i
s_minute = s_time.strftime('%M').to_i
if ((s_hour == 11 && s_minute >= 30) || s_hour > 11) && ((s_hour == 13 && s_minute == 0) || s_hour < 13)
puts "11:30-13:00"
self.start_time = Time.mktime(s_time.strftime('%Y'),s_time.strftime('%m'),s_time.strftime('%d'),13)
elsif ((s_hour == 17&& s_minute >= 30) || s_hour > 17) && ((s_hour == 18 && s_minute <= 30) || s_hour < 18)
puts "17:30-18:30"
self.start_time = Time.mktime(s_time.strftime('%Y'),s_time.strftime('%m'),s_time.strftime('%d'),18,30)
elsif ((s_hour == 21 && s_minute >= 30) || s_hour > 21) || ((s_hour == 8 && s_minute <= 30) || s_hour < 8)
if (s_hour == 21 && s_minute >= 30) || s_hour > 21
day = s_time.strftime('%d').to_i + 1
else
day = s_time.strftime('%d')
end
puts "21:30-08:30"
self.start_time = Time.mktime(s_time.strftime('%Y'),s_time.strftime('%m'),day,8,30)
else
puts "工作时段"
self.start_time = s_time
end
end
#开始时间处理,当处于休息时间段时,将开始时间设置为该时间段的结束时间```