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
haileys wants to merge 6 commits into2-3-githubfrom
2-3-github+fixed-db-timezones
Open

[2.3] Always convert Time and DateTime objects to local before converting to string#71
haileys wants to merge 6 commits into2-3-githubfrom
2-3-github+fixed-db-timezones

Conversation

@haileys
Copy link
Copy Markdown

@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
Copy Markdown

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
Copy Markdown
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