Rails 3/Ruby 1.9.2 Date.tomorrow不正确

Mik*_*ike 8 ruby ruby-on-rails ruby-on-rails-3

在Mac Snow leopard上使用Ruby 1.9.2和Rail 3

ruby-1.9.2-p290 :001 > Date.today
 => Sun, 25 Sep 2011 
ruby-1.9.2-p290 :002 > Date.tomorrow
 => Tue, 27 Sep 2011 
Run Code Online (Sandbox Code Playgroud)

ruby日期类可能有问题,或者这与我安装ruby的方式有关?

编辑:

ruby-1.9.2-p290 :039 > Date.current
 => Mon, 26 Sep 2011 
ruby-1.9.2-p290 :040 > DateTime.now
 => Sun, 25 Sep 2011 20:47:01 -0500
Run Code Online (Sandbox Code Playgroud)

好吧所以rails Date类看起来有点儿麻烦.DateTime类似乎工作正常.感谢derp和Adam

der*_*erp 11

在线查看信息并遇到了这个问题:https:
//rails.lighthouseapp.com/projects/8994/tickets/6410-dateyesterday-datetoday


查看最后的评论:

我同意你的看法,有点令人困惑的是你需要使用Date.urrent与Date.yesterday而不是Date.today,但一般的经验法则是Rails不会改变Ruby方法的工作方式,Date.today是.我们所能做的就是添加更好的文档,并确保人们意识到微妙的差异.


换句话说,使用current(rails)代替today(ruby)来避免问题.


Ada*_*lin 9

我也在观察这个.你可以试试DateTime.now.tomorrow.to_date.