Reputation: 1450
33] pry(main)> Tweet.last.c_at.to_s
=> "2013-09-30 12:39:25 +0800"
[34] pry(main)> Tweet.last.c_at
=> Mon, 30 Sep 2013 12:39:25 CST +08:00
[35] pry(main)> Tweet.gt(c_at: "2013-09-30 12:39:25 +0800").count
=> 1
[36] pry(main)> Tweet.gt(c_at: "Mon, 30 Sep 2013 12:39:25 CST +08:00").count
=> 0
the query it fire up is different
command={:count=>"tweets", :query=>{"c_at"=>{"$gt"=>2013-09-30 04:47:33 UTC}}} (0.8490ms)
command={:count=>"tweets", :query=>{"c_at"=>{"$gt"=>2013-09-30 18:47:33 UTC}}} (0.8671ms)
why this happen and how to store time and then use that to query?
Upvotes: 0
Views: 91
Reputation: 18835
you are dealing with datetimes here. this is not a mongodb issue nor a rails issue, it's just the input that is broken:
Time.parse "2013-09-30 12:39:25 +0800"
=> 2013-09-30 06:39:25 +0200
Time.parse "Mon, 30 Sep 2013 12:39:25 CST +08:00"
=> 2013-09-30 20:39:25 +0200
i assume, that this is due to the CST in the last date string:
Time.parse "Mon, 30 Sep 2013 12:39:25 +08:00"
=> 2013-09-30 06:39:25 +0200
Upvotes: 1