1

How do I solve this date and timzeone comparison problem in RSpec:

Code:

promotion.start_date.should == DateTime.strptime("2012-02-08", "%F")

Result:

Failure/Error: promotion.start_date.should == DateTime.strptime("2012-02-08", "%F")
  expected: Wed, 08 Feb 2012 00:00:00 +0000
       got: Wed, 08 Feb 2012 00:00:00 EST -05:00 (using ==)
  Diff:
  @@ -1,2 +1,2 @@
  -Wed, 08 Feb 2012 00:00:00 +0000
  +Wed, 08 Feb 2012 00:00:00 EST -05:00
4

1 回答 1

-1

看起来您的开发机器上有 EST 时区,Rails 应用程序中有 UTC(默认)。我会说你的测试中的错误是合法的:) 在你的 Rails 应用程序中设置相同的时区,config.time_zone = 'Eastern Time (US & Canada)'错误就会消失。

于 2012-05-09T20:28:05.257 回答