Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveSupport Date class methods seem to be buggy

#6029

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

Reported by Xac · November 22nd, 2010 @ 02:54 AM

State: new
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Utkarsh Kukreti
    Utkarsh Kukreti

    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.

    November 22nd, 2010 @ 06:50 PM

  2. agmcleod
    agmcleod

    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
    

    November 30th, 2010 @ 04:13 AM

  3. Xac
    Xac

    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.

    November 30th, 2010 @ 05:35 AM

  4. agmcleod
    agmcleod

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

    December 1st, 2010 @ 12:30 AM

  5. Rohit Arondekar
    Rohit Arondekar
    • Importance changed from to Low

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

    January 2nd, 2011 @ 01:06 AM

  6. bingbing