Skip to content
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

Date.today reports wrong date when frozen #62

Closed
joshwalsh opened this issue Jan 9, 2013 · 1 comment
Closed

Date.today reports wrong date when frozen #62

joshwalsh opened this issue Jan 9, 2013 · 1 comment

Comments

@joshwalsh
Copy link

Today is 2013, 1, 8 but when I freeze the date for yesterday it reports the wrong date. Running ruby 1.9.3 and Timecop 0.5.8.

require 'timecop'
require 'date'

Timecop.freeze(2013,1,7) do
  puts Date.today
  puts Time.now
end

I expected to see:

2013-01-07
2013-01-07 00:00:00 -0500

But, I actually see:

2013-01-08
2013-01-07 00:00:00 -0500

Am I using this incorrectly?

@travisjeffery
Copy link
Owner

Timecop doesn't override Date#today but you can just do Time.now.to_date, e.g.

Timecop.freeze(Time.local(2013, 1, 7)) { puts Time.now.to_date } # 2013-01-07

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants