Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ActiveSupport::TimeWithZone and Time mixins cause incorrect behaviour #12551

Closed
wiggly opened this Issue Oct 15, 2013 · 2 comments

Comments

Projects
None yet
3 participants

wiggly commented Oct 15, 2013

Hello,

I have been hunting a bug in my code and eventually tracked it down to the following problem and minimal script that demonstrates the issue.

I develop on 3.2.13 but I have run this script against the most recent master (commit 9f80937) and the problem exists there as well.

While it is a problem for me I am wondering if this is expected behaviour, I hope not.

The following code demonstrates the problem;

https://gist.github.com/wiggly/6997961

If you add a mixin to the core Time class that provides before?/after? functionality then it causes the method to be called via method_missing in TimeWithZone. Doing this passes the result of TimeWithZone.time to the method in Time.

The issue, I believe, is with the output of TimeWithZone.time. It takes the internal time and uses the time zone period to convert it to local time. This generates a new Time object that has a different internal epoch-seconds than the TimeWithZone.

The subsequent comparison now fails even when the method is passed the receiver as the second argument, see gist above.

I have figured things out to this point and am wondering if I can get someone within the rails team to give their thoughts. I can fix this by applying the mixin to the TimeWithZone class so my problem is solved for now but I think that the behaviour is incorrect and leads to very difficult to track down bugs. This had me baffled for a long time before I started looking at rails/activesupport for the culprit.

@wiggly wiggly added the stale label Apr 23, 2014

Owner

rafaelfranca commented May 1, 2014

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Rails team are limited, and so we are asking for your help.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

@rails-bot rails-bot closed this May 27, 2014

This issue has been automatically closed because of inactivity.

If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment