scoped_search
scoped_search copied to clipboard
Date querying test failures due to timezones
I was looking at a few things today and was getting test failures for seemingly random reasons. I figured out later that I think its probably due to TZ conversions.
I was testing stuff before 8AM and I'm living in +8. So I'm guessing was 2013-03-16 but the DB entries were 2013-03-15 (because they're saved as UTC).
https://github.com/wvanbergen/scoped_search/blob/master/spec/integration/ordinal_querying_spec.rb#L191
https://github.com/wvanbergen/scoped_search/blob/master/spec/integration/ordinal_querying_spec.rb#L195
Does this reasoning sound about right? I've got a few ideas to try, like calling .to_utc
or something on the date as well (if that's a thing!?).
You can call .utc
on a DateTime or Timestamp.
I am not sure if this is part o Ruby or ActiveSupport though, and if it is available in all versions.
The tricky part is:
- Can we always assume times in the DB are in UTC?
- Can we always assume the time the user specifies in the query is in the same timezone as the server's timezone?
Having said that, we should make sure our testsuite doesn't run into these timezone issues.