Forum: Ruby on Rails time_ago_in_words is off by a day

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D2a73c8e8b04027dd116e5bb7f536c50?d=identicon&s=25 Wayne M. (waynem)
on 2008-10-11 04:43
(Received via mailing list)
Maybe someone can help me; I'm sure I'm just missing something silly.
I have a Task model that has a due_date.  In my migration it's set to
a date:

t.date :due_date

I want to display both the actual date and a friendly format in the
application, so in my view I have:

<p><%= time_ago_in_words(@task.due_date) %> (<%=
@task.due_date.to_s(:long) %>)</p>

I have a sample task that has a due date set to October 12th, and
@task.due_date.to_s(:long) confirms this.  However, time_ago_in_words
says that it's "1 day", when today is the 10th and it should be 2
days.  In fact, I brought up a console and typed in 1.day.from_now,
and sure enough it says that tomorrow is Sunday the 12th, instead of
Saturday the 11th.

What am I missing?  Should I be using a datetime instead (presumably
it has something to do with the accuracy), even though I don't care
about the time, only the actual date?

If it matters at all, I am using Postgres as my database.

Thanks for any help.

- Wayne
C11006d67ed43abad522f5308fadf1f2?d=identicon&s=25 Maurício L. (mauricio)
on 2008-10-11 04:50
(Received via mailing list)
Look at your 1.day.from_now and see if it's like this:

Sun, 12 Oct 2008 02:45:42 UTC +00:00

If you also have the "UTC +00:00", it means that you timezone is the
GMT (and I think that it isn't your real timezone). For example, my
timezone is 3 hours after the GMT, so the right timezone would be
something like this:

Sat Oct 11 23:48:41 -0300 2008

At your environment.rb file, look for something like this:

config.time_zone = 'UTC'

And change it to your timezone.

On Fri, Oct 10, 2008 at 11:43 PM, Wayne M <wayne.molina@gmail.com>
wrote:
> <p><%= time_ago_in_words(@task.due_date) %> (<%=
> it has something to do with the accuracy), even though I don't care
> about the time, only the actual date?
>
> If it matters at all, I am using Postgres as my database.
>
> Thanks for any help.
>
> - Wayne
> >
>



--
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
João Pessoa, PB, +55 83 8867-7208
D2a73c8e8b04027dd116e5bb7f536c50?d=identicon&s=25 Wayne M. (waynem)
on 2008-10-11 05:08
(Received via mailing list)
Yep, that was it.  I knew it was something easy that I just
overlooked.

Thanks a lot!

On Oct 10, 10:49 pm, "Maurício Linhares" <mauricio.linha...@gmail.com>
This topic is locked and can not be replied to.