Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6958117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:05:56+00:00 2026-05-27T15:05:56+00:00

In my application I have: config.time_zone = ‘Warsaw’ A strange issue I have, is

  • 0

In my application I have: config.time_zone = 'Warsaw'

A strange issue I have, is that it seems like Rails are having problems with comparision of datetime fields.
If I change the datetime 1 hour back (and Warsaw is currently in timezone +0100), Rails won’t update the database, even if the field has changed. However, if I change the field once again, then the update will go to the database.

Example:

(Rails 3.1.0, ruby-1.9.2-p290, fresh rails app):

$ rails g model User starts_at:datetime
$ rake db:migrate
$ rails c
Loading development environment (Rails 3.1.0)
ruby-1.9.2-p290 :001 > u = User.create({:starts_at => "2011-01-01 10:00"})
SQL (21.3ms)  INSERT INTO "users" ("created_at", "starts_at", "updated_at") VALUES (?, ?, ?)  [["created_at", Tue, 13 Dec 2011 11:32:50 CET +01:00], ["starts_at", Sat, 01 Jan 2011 10:00:00 CET +01:00], ["updated_at", Tue, 13 Dec 2011 11:32:50 CET +01:00]]
 => #<User id: 1, starts_at: "2011-01-01 09:00:00", created_at: "2011-12-13 10:32:50", updated_at: "2011-12-13 10:32:50"> 
ruby-1.9.2-p290 :002 > u.starts_at
 => Sat, 01 Jan 2011 10:00:00 CET +01:00 # datetime created
ruby-1.9.2-p290 :003 > u.starts_at = "2011-01-01 09:00:00" # new datetime with one hour back
 => "2011-01-01 09:00:00" 
ruby-1.9.2-p290 :004 > u.starts_at
 => Sat, 01 Jan 2011 09:00:00 CET +01:00 # changed datetime
ruby-1.9.2-p290 :005 > u.save 
 => true 
ruby-1.9.2-p290 :006 > u.starts_at = "2011-01-01 09:00:00"
 => "2011-01-01 09:00:00" 
ruby-1.9.2-p290 :007 > u.save
   (0.3ms)  UPDATE "users" SET "starts_at" = '2011-01-01 08:00:00.000000', "updated_at" = '2011-12-13 10:33:17.919092' WHERE "users"."id" = 1
 => true 

I’ve tested it in this fresh app, because I have a problem with this in larger application. What is going on? I’ve tried to browse the Rails code, tried to re-copy the relevant code ‘by-hand’ in console (like update, assign_attributes, even checked time_zone_conversion) and it worked, but not in ‘real world’..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:05:57+00:00Added an answer on May 27, 2026 at 3:05 pm

    looks like you stumbled on a similar issue.

    The problem appears to be here:
    https://github.com/rails/rails/blob/3-1-stable/activerecord/lib/active_record/attribute_methods/dirty.rb#L62

    When rails it testing if the value was changed it compares old & new:

    old = From cache (which is Time in your current timezone)

    new = Time in UTC (+00:00) as saved in the database

    If the difference in time is the UTC offset, the above erroneously succeeds (luckly the new cached value holds the intended change).

    The next save/update compares with the new (and correct) cached value and marks the field as changed.

    EDIT:

    Done some tests, this works well for me:

    https://github.com/rails/rails/blob/3-1-stable/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb#L50

    Change

    write_attribute(:#{attr_name}, original_time)
    

    to

    write_attribute(:#{attr_name}, time.in_time_zone('UTC').to_s)
    

    Boris

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with rails timezones. application.rb config.time_zone = 'Athens' controller @from =
I have Rails application with mounted Engine. #{main_app}/config/routes.rb mount CommentIt::Engine => /talk, :as =>
I have an service application that reads a config file containing a list of
I have a web application that is deployed with web.config file. Are there any
I have a strange issue with an Asp.NET MVC application. Using Asp.NET MVC 3
By default, Rails' config.time_zone is UTC. So, fields like created_at , updated_at are saved
In config/application.rb I have config.time_zone = 'UTC' (without quotes) in the file. I am
I do NOT have config.active_record.whitelist_attributes = true in application config. And I have attr_protected()
In application.rb, I have config.autoload_paths += %W(#{config.root}/lib So when I modify a class under
I have app.config in m win application, and loggingConfiguration section (enterprise library 4.1). I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.