Defect #10098
last_login_on set to wrong time when config.active_record.default_timezone = :utc
Status: | Confirmed | Start date: | ||
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | - | % Done: | 0% | |
Category: | Accounts / authentication | Estimated time: | 3.00 hours | |
Target version: | - | |||
Resolution: | Affected version: | 1.3.0 |
Description
reproduce
- Set config.active_record.default_timezone = :utc in config/enviroment.rb
- Login with administrative user, go Administration -> Users
- 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
History
#1
Updated by Go MAEDA over 5 years ago
- Category changed from Time tracking to Accounts / authentication
#2
Updated by Go MAEDA over 2 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
#3
Updated by Mizuki ISHIKAWA almost 2 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)