This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Loading…
Labels












@piglop,
I can confirm that the test cases you have supplied do in fact fail. I am not certain yet whether or not I think they are valid test cases though. I'll be taking a deeper look into these issues later this week.
-John
The problem is when I freeze or travel, DateTime.now always returns an UTC time (offset is 0) with local values in individual fields (year, hour, etc.). Whereas standard DateTime.now returns a true local time (local values in individual fields and local offset).
The problem arises when you convert DateTime.now to another timezone (or even the local timezone). The individual fields are changed according to the new timezone. But since the individual values were already local, the converted time is wrong.
I've added another test in the branch to illustrate this.
@piglop thanks for following up with more information. This will be helpful.
I found a solution and made a single commit from master here : http://github.com/piglop/timecop/commit/7478f7ff28f2b5ea4b5476622c5de36bf7edca9f
I also added a fix for the problem with Time.utc here : http://github.com/piglop/timecop/commit/550183c5fb9fca7ac4351e16dc1cae4469c292cb
@piglop it's taken me a couple of extra days to get around to this. I'll be able to review these patches this weekend and hopefully get them merged in.
Thanks again.
-John
Should be fixed with http://github.com/piglop/timecop/commit/607af97d9d352b6b7e077658d2b759704d9749ba
Commited : http://github.com/jtrupiano/timecop/commit/d74af87729f8488fad2344e40810928216228702
Included in 0.3.2 release
I haven't studied the code changes, but timecop 0.3.2 has definitely broken in terms of how Time.now works when freezing. For example, here's a tiny "test" to illustrate:
If I run that with Timecop 0.3.1, I get:
Time (local) at start is: Mon Oct 26 13:40:39 -0700 2009
Time (UTC) at start is : Mon Oct 26 20:40:39 UTC 2009
Time (local) after timecop added 3 hours: Mon Oct 26 23:40:39 UTC 2009
Time (UTC) after timecop added 3 hours : Mon Oct 26 23:40:39 UTC 2009
But, if I run that with Timecop 0.3.2, I get:
Time (local) at start is: Mon Oct 26 13:41:30 -0700 2009
Time (UTC) at start is : Mon Oct 26 20:41:30 UTC 2009
Time (local) after timecop added 3 hours: Mon Oct 26 16:41:30 UTC 2009
Time (UTC) after timecop added 3 hours : Mon Oct 26 16:41:30 UTC 2009
So, now, time has gone backwards. In both cases my local timezone has been changed to UTC. What it's doing in 0.3.2 appears to be that it's adding 3 hours to the "Time.now" result, and not taking into account the Time zone.
@chris thanks for the report. If you have a free moment and can add a failing test to the test suite, I'd really appreciate it.
In the meantime, I suspect you'll get away with 0.3.1. It will probably be several days before I can get around to this.
While I was trying to write a test case for this problem, I discovered the current test suite fails since DST shift.
Indeed, in the new tests, we check that DateTime.now returns a local time, i.e. a DateTime with the current local offset. But when we create a DateTime in summer while we're in winter, the local offset should not be the same.
And I couldn't find a way to get the local offset at a specific time with the DateTime class. It may be possible with the Time class.
I couldn't write a test case for chris's problem, but I could reproduce it in a Rails environment.
I won't have a lot of time to check these problems this week.
I'm looking into it. I'm starting to think it's a conflict with Rails though. I forked the code, added a test case and it behaves properly when using simple math to add 3 hours to the time. So, I'm going to look into whether it's Rails' extensions for doing things like "3.hours.from_now" and if that messes with it. Like you guys, I'm pretty busy, and Timecop 0.3.1 works for me, so I'm not sure when I'll resolve this.
So I've had some time to really dig into this.
@chris, I think I have your issues worked out. I'll be releasing a prerelease version of timecop in a couple of days that I'll want you to try out for me. If you care to try my latest release candidate before I get the prerelease version sorted out, you can pull it down from a new branch named 'rewind'.
@piglop, there is a separate problem related to the patch you originally submitted. You had noticed behavior where traveling to times/datetimes in a different timezone were losing the timezone information, causing that time to be represented as UTC. Your patch corrected this, but at the same time underscored a new issue that I don't think we can solve.
The problem lies in the fact that a DateTime is incapable of representing DST properly. A DateTime only carries an offset (e.g. +0200), but this is not enough information for us to know if this particular DateTime instance should be subject to DST. Different timezones exist within the same offset, and some observe DST while others do not.
Due to this limitation, you can end up with the following test case failing:
I have pushed a new branch "rewind" to GitHub where you can see this test currently failing.
As a result of this finding, I am seriously considering removing the ability to pass a DateTime instance to Timecop calls. My concern is that this is simply too little known (that DateTime's cannot represent DST) and will cause many people headaches if we allow them to do so.
I'm curious what your thoughts are.
The gemspec in the 'rewind' branch now specifies a prerelease version (0.3.3.rc1). I'd really appreciate it if you guys (@chris and @piglop) could give it a try with your respective problems and report back to me.
Note that if you had previously installed 0.3.3 that it will take precedence over 0.3.3.rc1. I'm still getting the hang of this prerelease workflow...
I have released 0.3.4.rc1 as a prerelease gem. You can install it via: gem install/update --prerelease timecop