irb(main):005:0> def create_time(h,m)
irb(main):006:1> Time.local(2008,5,10,h,m,0)
irb(main):007:1> end
=> nil
irb(main):010:0> arr = []
=> []
irb(main):011:0> arr << (create_time(5,50)..create_time(7,0))
=> [Sat May 10 05:50:00 +0800 2008..Sat May 10 07:00:00 +0800 2008]
irb(main):012:0> arr << (create_time(9,15)..create_time(9,35))
=> [Sat May 10 05:50:00 +0800 2008..Sat May 10 07:00:00 +0800 2008, Sat May 10 0
9:15:00 +0800 2008..Sat May 10 09:35:00 +0800 2008]
irb(main):013:0> arr << (create_time(12,50)..create_time(13,5))
=> [Sat May 10 05:50:00 +0800 2008..Sat May 10 07:00:00 +0800 2008, Sat May 10 0
9:15:00 +0800 2008..Sat May 10 09:35:00 +0800 2008, Sat May 10 12:50:00 +0800 20
08..Sat May 10 13:05:00 +0800 2008]
irb(main):014:0> arr << (create_time(5,20)..create_time(6,5))
=> [Sat May 10 05:50:00 +0800 2008..Sat May 10 07:00:00 +0800 2008, Sat May 10 0
9:15:00 +0800 2008..Sat May 10 09:35:00 +0800 2008, Sat May 10 12:50:00 +0800 20
08..Sat May 10 13:05:00 +0800 2008, Sat May 10 05:20:00 +0800 2008..Sat May 10 0
6:05:00 +0800 2008]
irb(main):015:0> arr << (create_time(9,50)..create_time(10,30))
=> [Sat May 10 05:50:00 +0800 2008..Sat May 10 07:00:00 +0800 2008, Sat May 10 0
9:15:00 +0800 2008..Sat May 10 09:35:00 +0800 2008, Sat May 10 12:50:00 +0800 20
08..Sat May 10 13:05:00 +0800 2008, Sat May 10 05:20:00 +0800 2008..Sat May 10 0
6:05:00 +0800 2008, Sat May 10 09:50:00 +0800 2008..Sat May 10 10:30:00 +0800 20
08]
irb(main):016:0> s = 0
=> 0
irb(main):017:0> arr.each {|i| s+=i.to_a.length }
=> [Sat May 10 05:50:00 +0800 2008..Sat May 10 07:00:00 +0800 2008, Sat May 10 0
9:15:00 +0800 2008..Sat May 10 09:35:00 +0800 2008, Sat May 10 12:50:00 +0800 20
08..Sat May 10 13:05:00 +0800 2008, Sat May 10 05:20:00 +0800 2008..Sat May 10 0
6:05:00 +0800 2008, Sat May 10 09:50:00 +0800 2008..Sat May 10 10:30:00 +0800 20
08]
irb(main):018:0> s
=> 11405
irb(main):019:0> s/60
=> 190
irb(main):020:0> s/3600
=> 3
irb(main):021:0> s/3600.0
=> 3.16805555555556
最保守的估计了吧,只会少,不会多
一天里有3.17个小时是用来想你的
以前只会更多
乘个1712吧... 或者
这么算... (3.17*1712)/(6153*24)
生命的3.68%