#28 ✓resolved
James B. Byrne

AuthLogic and config.active_record.default_timezone = :utc

Reported by James B. Byrne | January 20th, 2009 @ 12:15 PM

It appears that the datetime columns maintained by authlogic do not honour the default_timezone configured in environment.rb. An example of the problem is given below.

This is the output of the unmodified contents of a user table containing the columns last_request_at, last_login_at and current_login-at which are maintained by authlogic code. For comparison, that row's created_at column, which is maintained by AR itself, is provided.

Last request at: Tue Jan 20 11:56:44 UTC 2009

Last login at: Tue Jan 20 11:38:36 UTC 2009

Current login at: Tue Jan 20 11:56:44 UTC 2009

Created at: Tue Jan 20 16:38:36 UTC 2009

According to this data, the current session started some 4.5 hours before the user record was created.

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson January 20th, 2009 @ 12:57 PM

    • State changed from “new” to “resolved”

    Authlogic has nothing to do with this. If setup properly, AR will convert local times to UTC before saving, and vice versa when reading. Is your server using UTC time? My guess is that it's not, because I am using Time.now in authlogic, which will return the server time, which should be UTC.

  • Ben Johnson

    Ben Johnson January 20th, 2009 @ 02:30 PM

    ActiveRecord wants you to use Time.zone.now to represent your local time. When you use Time.now ActiveRecord assumes this is in UTC, as a result it doesn't convert this value to UTC.

    Also, if I am not mistaken, if you do Time.zone and don't set a zone in your configuration that will be a nil value. So I can't do Time.zone. Therefore I don't have a choice.

  • Ben Johnson

    Ben Johnson January 20th, 2009 @ 02:36 PM

    That is strange, let me write up some tests in authlogic and see if I can duplicate this. If so, I don't think I can do anything about it, because Authlogic doesn't do anything with converting time zones, that is all done behind the scenes in AR.

  • Ben Johnson

    Ben Johnson January 20th, 2009 @ 02:36 PM

    • State changed from “resolved” to “open”
  • Ben Johnson

    Ben Johnson January 20th, 2009 @ 05:03 PM

    What do you get when you do the following?

    >> Time.now
    => Tue Jan 20 22:02:36 +0000 2009
    >> Time.now.utc
    => Tue Jan 20 22:02:36 UTC 2009
  • Ben Johnson

    Ben Johnson January 21st, 2009 @ 10:15 PM

    • State changed from “open” to “resolved”

    Alright, I uploaded a fix. Thanks for your help on this. Let me know if you have any other problems. Just update from the repo and you should be good.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Object based authentication solution that handles all of the non sense for you. It's as easy as ActiveRecord is with a database.

People watching this ticket