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.

Date.yesterday on Rails3 return two days back date till 5:30 a.m., after that it returns last day

#6511

Date.yesterday on Rails3 return two days back date till 5:30 a.m. after that it returns last day. Whereas on Rails 2.3.5 the same scenario is working fine.

Rails 3 application returning two days back date till 5:30 a.m

C:\projects\rails3demo>rails c
Loading development environment (Rails 3.0.3)

irb(main):002:0> DateTime.now
=> Thu, 03 Mar 2011 02:20:23 +0530

irb(main):003:0> Date.yesterday => Tue, 01 Mar 2011

irb(main):008:0> DateTime.now
=> Thu, 03 Mar 2011 14:39:35 +0530

irb(main):009:0> Date.yesterday
=> Wed, 02 Mar 2011


Rails 2.3.5 application returning last date

C:\projects\rails2demo>ruby script/console
Loading development environment (Rails 2.3.5)

DateTime.now => Thu, 03 Mar 2011 02:21:29 +0530

Date.yesterday => Wed, 02 Mar 2011

DateTime.now => Thu, 03 Mar 2011 14:39:17 +0530

Date.yesterday => Wed, 02 Mar 2011

Reported by Ritesh Kumar · March 3rd, 2011 @ 09:20 AM

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

Activity

  1. Andrew White
    Andrew White
    • State changed from new to duplicate
    • Importance changed from to Low

    This is a duplicate of #6410 Date.yesterday == Date.today - Time.now & Date.today use the local system time and Date.yesterday uses Time.zone which defaults to UTC in Rails. Use Date.current and Time.current to get the current time and date in your application.

    March 3rd, 2011 @ 11:05 AM