作者:铱雯_213 | 来源:互联网 | 2023-07-22 16:33
Ihaveanoffermodel.andwhenIaccessitfromthecommandline,itisdisplayedinthefollowing
I have an offer model. and when I access it from the command line, it is displayed in the following format:
我有报价模型。当我从命令行访问它时,它以下列格式显示:
1.9.3p392 :058 > o = Offer.last
=> #
In this output, valid_from
and valid_until
are formatted as I would expect. however, when I access them directly, I get something different:
在此输出中,valid_from和valid_until的格式符合我的预期。但是,当我直接访问它们时,我会得到一些不同的东西:
1.9.3p392 :059 > o.valid_from
=> Fri, 12 Apr 2013 05:00:00 EDT -04:00
The issue comes with this function I have inside of app/models/offer_model.rb
:
问题来自app / models / offer_model.rb中的这个函数:
def start_hour
self.valid_from.strftime('%l').to_i unless self.valid_from.nil?
end
When I run this command, with the model above, the output is 5
. I would expect it to return 9
in this case. How can I get start_hour
to return the hour adjusted for the time zone in this case?
当我运行此命令时,使用上面的模型,输出为5.我希望它在这种情况下返回9。在这种情况下,如何让start_hour返回为时区调整的小时数?
1 个解决方案