ActiveSupport Date class methods seem to be buggy #759

Closed
lighthouse-import opened this Issue May 16, 2011 · 12 comments

Comments

Projects
None yet
7 participants
@lighthouse-import

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6029
Created by Xac - 2011-02-19 09:28:23 UTC

There seem to be issues with Date.yesterday and Date.today:

ruby-1.8.7-p302 > Rails.version #=> "3.0.3"
ruby-1.8.7-p302 > Date.today #=> Sun, 21 Nov 2010
ruby-1.8.7-p302 > Date.yesterday #=> Sun, 21 Nov 2010
ruby-1.8.7-p302 > Date.today == Date.yesterday #=> true
ruby-1.8.7-p302 > Date.today.today? #=> false
ruby-1.8.7-p302 > Date.tomorrow #=> Tue, 23 Nov 2010
ruby-1.8.7-p302 > Time.now #=> Sun Nov 21 22:00:13 -0500 2010
ruby-1.8.7-p302 > Time.now.utc #=> Mon Nov 22 03:00:20 UTC 2010

@lighthouse-import

This comment has been minimized.

Show comment
Hide comment
@lighthouse-import

lighthouse-import May 16, 2011

Imported from Lighthouse.
Comment by Utkarsh Kukreti - 2010-11-22 18:50:21 UTC

I'm getting

> Date.today == Date.tomorrow
=> true
> Time.now
=> 2010-11-23 00:19:52 +0530
> Time.now.utc
=> 2010-11-22 18:49:54 UTC

Date.tomorrow and Date.yesterday are not taking the local timezone into consideration, and are using the UTC offsets.

Imported from Lighthouse.
Comment by Utkarsh Kukreti - 2010-11-22 18:50:21 UTC

I'm getting

> Date.today == Date.tomorrow
=> true
> Time.now
=> 2010-11-23 00:19:52 +0530
> Time.now.utc
=> 2010-11-22 18:49:54 UTC

Date.tomorrow and Date.yesterday are not taking the local timezone into consideration, and are using the UTC offsets.

@lighthouse-import

This comment has been minimized.

Show comment
Hide comment
@lighthouse-import

lighthouse-import May 16, 2011

Imported from Lighthouse.
Comment by agmcleod - 2010-11-30 04:13:39 UTC

I'm having issues where Date.today isn't even resolving...

aaronmcleod@MacBook-Pro $ irb
ruby-1.9.2-p0 > require 'active_support'
 => true 
ruby-1.9.2-p0 > Date.today
NoMethodError: undefined method `today' for Date:Class
    from (irb):2
    from /Users/aaronmcleod/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'
ruby-1.9.2-p0 > exit
aaronmcleod@MacBook-Pro $ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
aaronmcleod@MacBook-Pro $ rails -v
Rails 3.0.3

Imported from Lighthouse.
Comment by agmcleod - 2010-11-30 04:13:39 UTC

I'm having issues where Date.today isn't even resolving...

aaronmcleod@MacBook-Pro $ irb
ruby-1.9.2-p0 > require 'active_support'
 => true 
ruby-1.9.2-p0 > Date.today
NoMethodError: undefined method `today' for Date:Class
    from (irb):2
    from /Users/aaronmcleod/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'
ruby-1.9.2-p0 > exit
aaronmcleod@MacBook-Pro $ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
aaronmcleod@MacBook-Pro $ rails -v
Rails 3.0.3
@lighthouse-import

This comment has been minimized.

Show comment
Hide comment
@lighthouse-import

lighthouse-import May 16, 2011

Imported from Lighthouse.
Comment by Xac - 2010-11-30 05:35:15 UTC

ActiveSupport is broken down into pieces that need to be individually required now.

Try "require 'active_support/core_ext/date'" for date helpers, or "require 'activesupport/all'" for the old functionality.

Imported from Lighthouse.
Comment by Xac - 2010-11-30 05:35:15 UTC

ActiveSupport is broken down into pieces that need to be individually required now.

Try "require 'active_support/core_ext/date'" for date helpers, or "require 'activesupport/all'" for the old functionality.

@lighthouse-import

This comment has been minimized.

Show comment
Hide comment
@lighthouse-import

lighthouse-import May 16, 2011

Imported from Lighthouse.
Comment by agmcleod - 2010-12-01 00:30:30 UTC

Ah alright, I have it working now. I seem to be getting the correct date & times. Note that I am in eastern standard time.

Imported from Lighthouse.
Comment by agmcleod - 2010-12-01 00:30:30 UTC

Ah alright, I have it working now. I seem to be getting the correct date & times. Note that I am in eastern standard time.

@lighthouse-import

This comment has been minimized.

Show comment
Hide comment
@lighthouse-import

lighthouse-import May 16, 2011

Imported from Lighthouse.
Comment by Rohit Arondekar - 2011-01-02 01:06:31 UTC

Xac, Utkarsh: is this an issue of bad documentation of Date.yesterday and Date.tomorrow or bugs in the methods themselves?

Imported from Lighthouse.
Comment by Rohit Arondekar - 2011-01-02 01:06:31 UTC

Xac, Utkarsh: is this an issue of bad documentation of Date.yesterday and Date.tomorrow or bugs in the methods themselves?

@nicknovitski

This comment has been minimized.

Show comment
Hide comment
@nicknovitski

nicknovitski Jun 23, 2011

Contributor

Why was this closed? It's still present in 3.1 rc3.

e: and rc4

Contributor

nicknovitski commented Jun 23, 2011

Why was this closed? It's still present in 3.1 rc3.

e: and rc4

@thetron

This comment has been minimized.

Show comment
Hide comment
@thetron

thetron Jun 23, 2011

Contributor

Working fine for me in 3.1 rc4, in Ruby 1.9.2

ruby-1.9.2-p180 > Rails.version # => "3.1.0.rc4" 
ruby-1.9.2-p180 > Date.today # => Thu, 23 Jun 2011 
ruby-1.9.2-p180 > Date.yesterday # => Wed, 22 Jun 2011 
ruby-1.9.2-p180 > Date.today == Date.yesterday # => false 
ruby-1.9.2-p180 > Date.today.today? # => true 
ruby-1.9.2-p180 > Date.tomorrow # => Fri, 24 Jun 2011 
ruby-1.9.2-p180 > Time.now # => 2011-06-23 15:45:33 +1000 
ruby-1.9.2-p180 > Time.now.utc # => 2011-06-23 05:45:36 UTC
Contributor

thetron commented Jun 23, 2011

Working fine for me in 3.1 rc4, in Ruby 1.9.2

ruby-1.9.2-p180 > Rails.version # => "3.1.0.rc4" 
ruby-1.9.2-p180 > Date.today # => Thu, 23 Jun 2011 
ruby-1.9.2-p180 > Date.yesterday # => Wed, 22 Jun 2011 
ruby-1.9.2-p180 > Date.today == Date.yesterday # => false 
ruby-1.9.2-p180 > Date.today.today? # => true 
ruby-1.9.2-p180 > Date.tomorrow # => Fri, 24 Jun 2011 
ruby-1.9.2-p180 > Time.now # => 2011-06-23 15:45:33 +1000 
ruby-1.9.2-p180 > Time.now.utc # => 2011-06-23 05:45:36 UTC
@jhawthorn

This comment has been minimized.

Show comment
Hide comment
@jhawthorn

jhawthorn Jun 23, 2011

Contributor

The reason for this behaviour is that Date.today and Date.tomorrow rely on Date.current, rather than Date.today

def current
  ::Time.zone ? ::Time.zone.today : ::Date.today
end

Those experiencing this issue will find their Time.zone being set to a different time zone than their server (probably UTC). This issue will then manifest when the date in UTC is different than the date in the server's time zone.

A workaround would be to use Date.current instead.

Contributor

jhawthorn commented Jun 23, 2011

The reason for this behaviour is that Date.today and Date.tomorrow rely on Date.current, rather than Date.today

def current
  ::Time.zone ? ::Time.zone.today : ::Date.today
end

Those experiencing this issue will find their Time.zone being set to a different time zone than their server (probably UTC). This issue will then manifest when the date in UTC is different than the date in the server's time zone.

A workaround would be to use Date.current instead.

@osegrums

This comment has been minimized.

Show comment
Hide comment
@osegrums

osegrums Jul 10, 2011

+1
`$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
$ rails -v
Rails 3.0.9
$ date
Sun Jul 10 01:17:36 EEST 2011
$ rails c
Loading development environment (Rails 3.0.9)

Date.today == Date.tomorrow
true
Date.today.today?
false

Date.today
Sun, 10 Jul 2011
Date.tomorrow
Sun, 10 Jul 2011
Time.now
2011-07-10 01:21:03 +0300
Time.now.utc
2011-07-09 22:21:10 UTC
`

+1
`$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
$ rails -v
Rails 3.0.9
$ date
Sun Jul 10 01:17:36 EEST 2011
$ rails c
Loading development environment (Rails 3.0.9)

Date.today == Date.tomorrow
true
Date.today.today?
false

Date.today
Sun, 10 Jul 2011
Date.tomorrow
Sun, 10 Jul 2011
Time.now
2011-07-10 01:21:03 +0300
Time.now.utc
2011-07-09 22:21:10 UTC
`

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 23, 2011

There are two issues here:

#1) ActiveSupport::Date current method has a misleading conditional. Time.zone is always returned because config.time_zone is set by default on a project.

#2) ActiveSupport::Date does not override the Date.today method. This means that the core ruby library's .today method is called which may be based off of a different time zone than what's set in config.time_zone.

Submitting a pull request.

ghost commented Jul 23, 2011

There are two issues here:

#1) ActiveSupport::Date current method has a misleading conditional. Time.zone is always returned because config.time_zone is set by default on a project.

#2) ActiveSupport::Date does not override the Date.today method. This means that the core ruby library's .today method is called which may be based off of a different time zone than what's set in config.time_zone.

Submitting a pull request.

@ghost

This comment has been minimized.

Show comment
Hide comment

ghost pushed a commit to Mochaleaf/rails that referenced this issue Aug 4, 2011

Fixing bugs in ActiveSupport::Date. Fixes #759.
There are two issues here:

#1) ActiveSupport::Date current method has a misleading conditional. Time.zone is always returned because config.time_zone is set by default on a project.

#2) ActiveSupport::Date does not override the Date.today method. This means that the core ruby library's .today method is called which may be based off of a different time zone than what's set in config.time_zone.

ghost pushed a commit to Mochaleaf/rails that referenced this issue Aug 4, 2011

Fixing bugs in ActiveSupport::Date. Fixes #759.
ActiveSupport::Date does not override the Date.today method. This means that the core ruby library's .today method is called which may be based off of a different time zone than what's set in config.time_zone.
@fxn

This comment has been minimized.

Show comment
Hide comment
@fxn

fxn Aug 4, 2011

Member

Sorry, the issue was closed automatically by GitHub after closing a related pull request.

A Rails application is expected to use Date.current and friends. As the AS guide throughly documents, in general date methods are based on Date.current (also Time.current, etc.).

Member

fxn commented Aug 4, 2011

Sorry, the issue was closed automatically by GitHub after closing a related pull request.

A Rails application is expected to use Date.current and friends. As the AS guide throughly documents, in general date methods are based on Date.current (also Time.current, etc.).

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