-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about Rails v Ruby Date/Time libraries #182
Comments
Isn't this inaccurate? It's more like, Rails monkey-patches Date/Time/DateTime for making them saner or richer. Right? |
@vemv hah I think "saner" may be a debatable point, but good catch! I've edited the original issue description. Unrelated, does anyone know if this gem is still being maintained in this repo (or at all) anymore? |
Hi @cjhin I'm doing some maintenance |
Hi @ballcheck! Let me know if I can help in any way! |
For anyone who's still confused Time.zone = -1
#=> -1
Time.now.hour
#=> 6
Time.current.hour
#=> 5 |
Thanks to https://github.com/cjhin for #182
@ballcheck thanks so much, it looks great! Thoughts on closing (what I think are related) issues #169 and #148? I'm happy to leave comments on them and/or close them, let me know what would be most helpful! |
As well as code review feedback, this change unit tests the new priority deadline date field. It was interesting to discover that the unit tests failed when the local machine had its time zone set to something other than PST, and it turns out to be a known issue discussed at travisjeffery/timecop#182. The solution is to use `Date.current` rather than `Date.today`. A bunch of factories were also updated to use the yyyy-mm-dd date format that it turns out we're storing, as described in #27895
tl;dr
Ruby
Date
/Time
and RailsDate
/Time
handle timezones differently, which can cause weird edge cases:Sometimes, people (including myself) assume Timecop is broken, and file unnecessary issue requests.
One possible solution is to mention in Timecop docs so people stop blaming Timecop 😋
Details
Ruby has Date, Time, and DateTime libraries.
Rails has monkey patched these libraries with additional methods.
(Rails: Date, Time, and DateTime)
Ruby Date/Time methods use the local system timezone, while Rails Date/Time methods use the timezone defined in Time.zone. When those two timezones don't match for some reason AND a developer accidentally uses methods from both classes together, things can break.
There is a really old issue request against Rails where the developers discuss this edge case.
Example
Possible Solutions
Date.yesterday
,Date.today
, andDate.tomorrow
things might break"Related Issues
Pretty sure they are related:
#169, #148, #62, #16
Sort of sure they are related:
#136, #100, #41
@yaauie basically describes this problem in his comments on PR #100, but it kind of gets lost in the other discussions on that thread. And by that I mean I failed to notice until right now... 🙈
The text was updated successfully, but these errors were encountered: