您可以根据您想要的日期检查日期,并进行相应调整。这不是很好,但它确实有效。
$ irb
1.9.3p0 :001 > require 'date'
=> true
1.9.3p0 :002 > other_date = DateTime.now
=> #<DateTime: 2012-06-08T14:23:44-04:00 ((2456087j,66224s,205565000n),-14400s,2299161j)>
1.9.3p0 :003 > week = other_date.strftime('%W').to_i
=> 23
1.9.3p0 :004 > target_day = 2 # Tuesday
=> 2
1.9.3p0 :005 > while other_date.wday > target_day ; other_date = other_date.prev_day ; end
=> nil
1.9.3p0 :006 > while other_date.wday < target_day ; other_date = other_date.next_day ; end
=> nil
1.9.3p0 :007 > other_date # Tuesday of this week
=> #<DateTime: 2012-06-05T14:23:44-04:00 ((2456084j,66224s,205565000n),-14400s,2299161j)>
1.9.3p0 :008 > other_date.strftime('%W').to_i == week
=> true