c应该是2个周期的内部期间。如何以最优雅的方式获得它?如何在红宝石中获取2个日期的中期?
a1=Date.current
a2=Date.current + 2.months
b1=Date.current + 1.month
b2=Date.current + 3.months
c=???
c.should_be [Date.current + 1.month, Date.current + 2.months]
c应该是2个周期的内部期间。如何以最优雅的方式获得它?如何在红宝石中获取2个日期的中期?
a1=Date.current
a2=Date.current + 2.months
b1=Date.current + 1.month
b2=Date.current + 3.months
c=???
c.should_be [Date.current + 1.month, Date.current + 2.months]
d= [a1, a2, b1, b2]
[*1..d.length/ 2].map do |dt|
d.shift(2)
end.map do |dx|
Date.current+ (dx[1]- dx[0])
end
[孙,2012年6月24日,星期二,2012年7月24日]
@Sergio你不希望看到目前的实现。你的眼睛会流血。 –
我主要想知道你有多努力尝试:) –
“你有什么尝试”是不适合这样的一般问题imho – pguardiario