The application displays the wrong hours and minutes

First: This is not a wrong zone problem. In irb and the database, everything is fine. The problem arises when I want to display dates in my views (created_at, updated_at and everything defined by me in each model). I tried to set the time zone in application.rb and remove the temporary formats from the initializers, and this did not solve my problem.

Schema information created using the Annotate gem object:

# created_at :datetime # updated_at :datetime # publish_at :datetime 

from irb:

 1.9.2-p290 :004 > Time.zone => (GMT+00:00) UTC 1.9.2-p290 :005 > Time.zone.now => Fri, 24 Feb 2012 12:14:04 UTC +00:00 1.9.2-p290 :006 > Time.now => 2012-02-24 13:14:07 +0100 

<strong> Examples:

 1.9.2-p290 :007 > Article.last Article Load (0.3ms) SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` DESC LIMIT 1 => #<... created_at: "2012-02-24 12:04:24", updated_at: "2012-02-24 12:04:24", publish_at: "2012-02-24 12:04:24"...> 

App displays:

Created_at 2012-02-24 12:02, Updated_at 2012-02-24 12:02, Publish_at 2012-02-24 12:02,

 1.9.2-p290 :008 > Article.first Article Load (0.5ms) SELECT `articles`.* FROM `articles` LIMIT 1 => #<...created_at: "2012-01-30 10:28:07", updated_at: "2012-02-08 17:20:41", publish_at: "2012-02-08 17:20:33"...> 

App displays:

Created_at 2012-01-30 10:01, Updated_at 2012-02-08 17:02, Publish_at 2012-02-08 17:02

this applies to the entire application (including active_admin)

Sorry for my english;) Any ideas what is the cause of my problem?

+6
source share
1 answer

I did it :) It was stupid, but maybe someone would need a reminder: the application first gets the format from the local yml file (this is the only way to set the date format in the active admin, the formats from the initializers do not matter):

 time: formats: default: "%Y-%m-%d" short: "%b %d" long: "%Y-%m-%d %H:%m" 

and minutes in long format should be% M (not% m)

0
source

Source: https://habr.com/ru/post/909272/


All Articles