Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Let Rails do the timezone adjustments

  • Loading branch information...
commit 73ca7980a8bda8a236d49b289c7590e6b21d712b 1 parent e3e4529
@joshfrench joshfrench authored
View
2  app/helpers/application_helper.rb
@@ -112,7 +112,7 @@ def updated_stamp(model)
end
def timestamp(time)
- adjust_time(time).strftime("%I:%M <small>%p</small> on %B %d, %Y")
+ time.strftime("%I:%M <small>%p</small> on %B %d, %Y")
end
def meta_visible(symbol)
View
3  app/models/radiant/config.rb
@@ -24,8 +24,7 @@ module Radiant
# defaults.page.status :: a string representation of the default page status
# defaults.page.filter :: the default filter to use on new page parts
# dev.host :: the hostname where draft pages are viewable
- # local.timezone :: the timezone offset (using a String or integer
- # from http://api.rubyonrails.org/classes/TimeZone.html)
+ # local.timezone :: the timezone name (`rake -D time` for full list)
# used to correct displayed times
# page.edit.published_date? :: when true, shows the datetime selector
# for published date on the page edit screen
View
2  app/models/standard_tags.rb
@@ -569,7 +569,7 @@ class TagError < StandardError; end
else
page.published_at || page.created_at
end
- adjust_time(date).strftime(format)
+ date.strftime(format)
end
desc %{
View
12 lib/local_time.rb
@@ -1,12 +1,6 @@
-require 'radiant/config'
module LocalTime
def adjust_time(time)
- if (tz_string = Radiant::Config["local.timezone"]) and
- timezone = (ActiveSupport::TimeZone[tz_string] || ActiveSupport::TimeZone[tz_string.to_i])
- # adjust time
- time.in_time_zone(timezone).time
- else
- time
- end
+ ::ActiveSupport::Deprecation.warn("`adjust_time' is deprecated. All time output is now auto-adjusted to Radiant::Config['local.timezone'] or the default ActiveRecord time zone.", caller)
+ time
end
-end
+end
View
13 spec/controllers/application_controller_spec.rb
@@ -67,4 +67,17 @@
controller.template_name.should == 'show'
end
end
+
+ describe "set_timezone" do
+ it "should use Radiant::Config['local.timezone']" do
+ Radiant::Config['local.timezone'] = 'Kuala Lumpur'
+ controller.send(:set_timezone)
+ Time.zone.name.should == 'Kuala Lumpur'
+ end
+
+ it "should default to config.time_zone" do
+ controller.send(:set_timezone)
+ Time.zone.name.should == 'UTC'
+ end
+ end
end
View
40 spec/lib/local_time_spec.rb
@@ -1,40 +0,0 @@
-require File.dirname(__FILE__) + "/../spec_helper"
-
-class MockTime
- include LocalTime
-end
-
-describe LocalTime, "when included in a class" do
- it "should add the adjust_time instance method to the class" do
- MockTime.new.should respond_to(:adjust_time)
- end
-end
-
-describe LocalTime, "when adjusting the time to local" do
- before :each do
- @obj = MockTime.new
- @conf = Radiant::Config
- @time = Time.gm 2004
- end
-
- it "should not change the time when no timezone is specified" do
- @obj.adjust_time(@time).should == @time
- end
-
- it "should not change the time when an invalid timezone is specified" do
- @conf["local.timezone"] = "Timezone that doesn't exist"
- @obj.adjust_time(@time).should == @time
- end
-
- it "should properly adjust the time when a numeric offset is specified" do
- offset = -10.hours
- @conf["local.timezone"] = offset
- @obj.adjust_time(@time).should == @time + offset
- end
-
- it "should properly adjust the time when a named timezone is specified" do
- offset = 9.hours # Tokyo
- @conf["local.timezone"] = "Tokyo"
- @obj.adjust_time(@time).should == @time + offset
- end
-end
View
2  spec/models/page_spec.rb
@@ -184,7 +184,7 @@ def headers
@page.status_id = Status[:published].id
@page.save
@page.published_at.should_not be_nil
- @page.published_at.day.should == Time.now.day
+ @page.published_at.day.should == Time.now.utc.day
end
it 'should not update published_at when already published' do
View
4 spec/models/standard_tags_spec.rb
@@ -479,8 +479,8 @@
end
end
- it "should use the configured local timezone" do
- Radiant::Config["local.timezone"] = "Tokyo"
+ it "should use the currently set timezone" do
+ Time.zone = "Tokyo"
format = "%H:%m"
expected = page.published_at.in_time_zone(ActiveSupport::TimeZone['Tokyo']).strftime(format)
page.should render(%Q(<r:date format="#{format}" />) ).as(expected)
Please sign in to comment.
Something went wrong with that request. Please try again.