Permalink
Browse files

Added time zone support

  • Loading branch information...
1 parent d40a38a commit 280c5b11dfbc50369377cf59aa9e5cb4cb28a7e5 Joshua Clayton committed Nov 10, 2008
@@ -7,12 +7,16 @@ class ApplicationController < ActionController::Base
filter_parameter_logging :password
- before_filter :manage_page
+ before_filter :manage_page, :set_time_zone
protected
def manage_page
@page_title = [ApplicationController::APPLICATION_NAME]
@copyright_year = [2008, Time.now.year].uniq.join(" - ")
end
+
+ def set_time_zone
+ Time.zone = current_user.time_zone if current_user
+ end
end
@@ -7,7 +7,7 @@
<% content_tag(:tr, :id => dom_id(post)) do %>
<td>
<p class="spaced quiet timestamp created-at">
- <strong><%= distance_of_time_in_words_to_now(post.created_at) %> ago</strong>
+ <strong><%= post.created_at < 1.day.ago ? post.created_at.to_s(:long) : "#{distance_of_time_in_words_to_now(post.created_at)} ago" %></strong>
</p>
<% column 2, :image do %>
<div style="width: 72px; height: 72px; padding-bottom: .75em">
@@ -11,4 +11,8 @@
<%= form.label :password_confirmation, "Confirm Password" %>
<%= form.password_field :password_confirmation, :class => "title" %>
<% end %>
+ <% set do %>
+ <%= form.label :time_zone %>
+ <%= form.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones %>
+ <% end %>
<% end %>
@@ -17,4 +17,6 @@
config.action_controller.session_store = :active_record_store
config.active_record.observers = :post_observer
+
+ config.time_zone = "UTC"
end
@@ -0,0 +1,13 @@
+class AddTimeZoneToUsers < ActiveRecord::Migration
+ def self.up
+ change_table :users do |t|
+ t.string :time_zone
+ end
+ end
+
+ def self.down
+ change_table :users do |t|
+ t.remove :time_zone
+ end
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20081104202327) do
+ActiveRecord::Schema.define(:version => 20081110231626) do
create_table "forums", :force => true do |t|
t.string "name"
@@ -110,6 +110,7 @@
t.string "last_name"
t.string "username"
t.integer "posts_count", :default => 0
+ t.string "time_zone"
end
add_index "users", ["role_id"], :name => "index_users_on_role_id"

0 comments on commit 280c5b1

Please sign in to comment.