Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeWithZoneTypecaster #92

Open
cgriego opened this issue Mar 15, 2012 · 2 comments
Open

TimeWithZoneTypecaster #92

cgriego opened this issue Mar 15, 2012 · 2 comments

Comments

@cgriego
Copy link
Owner

cgriego commented Mar 15, 2012

Time zone support is opt-in with ActiveRecord using time_zone_aware_attributes. TimeTypecaster will skip time zone conversion, TimeWithZoneTypecaster will not. Conversion in ActiveRecord uses the current Time.zone.

@cgriego
Copy link
Owner Author

cgriego commented Mar 15, 2012

Initial assessment was wrong. time_zone_aware_attributes is false by default in the class but enabled by default in the Railtie. The default_timezone option in ActiveRecord only accepts :utc and :local as the possible values.

@ryansch
Copy link

ryansch commented Nov 17, 2014

Possible implementation:

class TimeWithZoneTypecaster
  def call(value)
    if value.respond_to? :in_time_zone
      value.in_time_zone
    elsif value.respond_to? :to_s
      Time.zone.parse(value)
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants