Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

[2.3] Always convert Time and DateTime objects to local before converting to string #71

Open
wants to merge 6 commits into
base: 2-3-github
Choose a base branch
from

Conversation

haileys
Copy link

@haileys haileys commented Jun 10, 2014

This breaks a whole bunch of Rails tests, which is to be expected because there was previously no timezone handling here at all.

cc @github/timezones @github/rails3 github/github#27189

@rsanheim
Copy link

If we go this route, how should TimeWithZone behave? Right now, to_s(:db) for any time with zone will always output UTC:

    # <tt>:db</tt> format outputs time in UTC; all others output time in local.
    # Uses TimeWithZone's +strftime+, so <tt>%Z</tt> and <tt>%z</tt> work correctly.
    def to_s(format = :default)
      return utc.to_s(format) if format == :db
      if formatter = ::Time::DATE_FORMATS[format]
        formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
      else
        "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby 1.9 Time#to_s format
      end
    end
    alias_method :to_formatted_s, :to_s

@haileys
Copy link
Author

haileys commented Jun 11, 2014

@rsanheim Yeah, that's tricky. It should return local for us. I believe Rails 3 makes this configurable.

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

Successfully merging this pull request may close these issues.

2 participants