Skip to content

Commit

Permalink
Fixed TimeZone issues in action-pack and active-support #704
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@776 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Feb 23, 2005
1 parent 11a2bb9 commit 65d3430
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 10 additions & 6 deletions actionpack/lib/action_view/helpers/form_options_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def country_options_for_select(selected = nil, priority_countries = nil)
# (long) list. (You can use TimeZone.us_zones as a convenience for # (long) list. (You can use TimeZone.us_zones as a convenience for
# obtaining a list of the US time zones.) # obtaining a list of the US time zones.)
# #
# The +selected+ parameter must be either +nil+, or a string that names
# a TimeZone.
#
# By default, +model+ is the TimeZone constant (which can be obtained # By default, +model+ is the TimeZone constant (which can be obtained
# in ActiveRecord as a value object). The only requirement is that the # in ActiveRecord as a value object). The only requirement is that the
# +model+ parameter be an object that responds to #all, and returns # +model+ parameter be an object that responds to #all, and returns
Expand All @@ -195,16 +198,17 @@ def country_options_for_select(selected = nil, priority_countries = nil)
def time_zone_options_for_select(selected = nil, priority_zones = nil, model = TimeZone) def time_zone_options_for_select(selected = nil, priority_zones = nil, model = TimeZone)
zone_options = "" zone_options = ""


zones = model.all
convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } }

if priority_zones if priority_zones
zone_options += options_for_select(priority_zones, selected) zone_options += options_for_select(convert_zones[priority_zones], selected)
zone_options += "<option>-------------</option>\n" zone_options += "<option>-------------</option>\n"


zones = model.all.reject { |z| priority_zones.include?( z ) } zones = zones.reject { |z| priority_zones.include?( z ) }
zone_options += options_for_select(zones, selected)
else
zone_options += options_for_select(model.all, selected)
end end


zone_options += options_for_select(convert_zones[zones], selected)
zone_options zone_options
end end


Expand Down Expand Up @@ -292,4 +296,4 @@ def add_blank_option(option_tags, add_blank)
end end
end end
end end
end end
8 changes: 7 additions & 1 deletion activesupport/lib/active_support/values/time_zone.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ def now
adjust(Time.now) adjust(Time.now)
end end


# Return the current date in this time zone.
def today
now.to_date
end

# Adjust the given time to the time zone represented by +self+. # Adjust the given time to the time zone represented by +self+.
def adjust(time) def adjust(time)
time = time.to_time
offset = time.utc_offset offset = time.utc_offset
time + utc_offset - offset time + utc_offset - offset
end end
Expand Down Expand Up @@ -152,4 +158,4 @@ def us_zones
all.find_all { |z| z.name =~ US_ZONES } all.find_all { |z| z.name =~ US_ZONES }
end end
end end
end end

0 comments on commit 65d3430

Please sign in to comment.