Project

General

Profile

Actions

Defect #10098

open

last_login_on set to wrong time when config.active_record.default_timezone = :utc

Added by Nickolay Mischenko almost 13 years ago. Updated over 4 years ago.

Status:
Confirmed
Priority:
Normal
Assignee:
-
Category:
Accounts / authentication
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
3.00 h
Resolution:
Affected version:

Description

reproduce
  1. Set config.active_record.default_timezone = :utc in config/enviroment.rb
  2. Login with administrative user, go Administration -> Users
  3. Last connection time is wrong

example
for me, I've logged in as admin in "01/01/2012 06:41 pm", my server zone is UTC+11, last connection time = "02/01/2012 05:43 am", admin user zone is UTC
value must be "01/01/2012 07:41 am"

solution?
Time.zone.now should be used instead of Time.now when user logged-in or autologged-in

Actions #1

Updated by Go MAEDA about 8 years ago

  • Category changed from Time tracking to Accounts / authentication
Actions #2

Updated by Go MAEDA about 5 years ago

  • Status changed from New to Confirmed

Confirmed the issue.

the user logged on at 12:47:49 JST +0900, but User.first.last_login_on returns 12:47:49 UTC +00:00.

[6] pry(main)> User.first.last_login_on
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."type" IN ('User', 'AnonymousUser') ORDER BY "users"."id" ASC LIMIT ?  [["LIMIT", 1]]
=> Wed, 11 Dec 2019 12:47:49 UTC +00:00
[7] pry(main)> Time.zone.now
=> Wed, 11 Dec 2019 03:51:12 UTC +00:00
Actions #3

Updated by Mizuki ISHIKAWA over 4 years ago

It could not be reproduced in the development environment. May be due to differences in environment.
However, I agree with changing Time.now to Time.zone.now


PostgreSQL: Docker container (TZ=JST)
Redmine app: Docker container (TZ=JST)

Run the following command in the Redmine app container:

$ date
2020/7/14 Tuesday 11:14:36 JST

$ rails console
> User.first.last_login_on
Tue, 14 Jul 2020 02:01:28 UTC +00:00
> Time.zone.now
Tue, 14 Jul 2020 02:07:28 UTC +00:00

$ psql
# show timezone;
  TimeZone  
------------
 Asia/Tokyo
(1 row)

# select login, last_login_on from users;

 login |       last_login_on        
-------+----------------------------
       | 
       | 
       | 
 admin | 2020-07-14 02:01:28.928461
(4 rows)

Actions

Also available in: Atom PDF