#7 √ resolved
Maurício Linhares

TzTime active record plugin changing dates incorrectly

Reported by Maurício Linhares | May 6th, 2008 @ 09:47 PM

The following method on the TzTimeHepers::ActiveRecordMethods ( tztime/lib/tz_time_helpers/active_record_methods.rb ) doesn't work when you pass an UTC based Time object to it, as it thinks that the time is in the local time, not asking the time object if it's already an UTC time.

define_method "#{attribute}=" do |local_time|

fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil

write_attribute attribute, fixed

end

The following method yields the correct behaviour, first testing if the time is already in UTC and only if it is not it will try to convert it.

define_method "#{attribute}=" do |local_time|

fixed = nil

if local_time.acts_like?(:time) || local_time.acts_like?(:date)

fixed = local_time.utc? ? local_time : TzTime.at(local_time)

end

write_attribute attribute, fixed

end

Comments and changes to this ticket

  • Maurício Linhares

    Maurício Linhares May 6th, 2008 @ 09:50 PM

    Ops, sorry about the formatting:

    This is the code that is failing:

        define_method "#{attribute}=" do |local_time|
            fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ?  TzTime.at(local_time) : nil
            write_attribute attribute, fixed
        end
    

    This is the correct code:

              define_method "#{attribute}=" do |local_time|            
                fixed = nil
                if local_time.acts_like?(:time) || local_time.acts_like?(:date)
                  fixed = local_time.utc? ? local_time : TzTime.at(local_time)
                end
                write_attribute attribute, fixed
              end
    
  • Geoff Buesing

    Geoff Buesing May 13th, 2008 @ 02:47 PM

    • → State changed from “new” to “resolved”

    Going forward, we'll be supporting the time zone features introduced in 2.1; the tztime plugin will become legacy.

    Therefore, I'm closing this ticket, given that this is not an issue with 2.1.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

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

People watching this ticket