Changeset 9149
- Timestamp:
- 03/30/08 22:24:35 (3 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/time_with_zone.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/values/time_zone.rb (modified) (4 diffs)
- trunk/activesupport/lib/active_support/vendor.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8 (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone_info.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Algiers.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Cairo.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Casablanca.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Harare.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Johannesburg.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Monrovia.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Nairobi.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/Buenos_Aires.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/San_Juan.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Bogota.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Caracas.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chicago.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chihuahua.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Denver.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Godthab.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Guatemala.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Halifax.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Indiana (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Indiana/Indianapolis.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Juneau.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/La_Paz.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Lima.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Los_Angeles.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mazatlan.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mexico_City.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Monterrey.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/New_York.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Phoenix.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Regina.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Santiago.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/St_Johns.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Tijuana.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Almaty.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baghdad.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baku.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Bangkok.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Chongqing.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Dhaka.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Hong_Kong.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Irkutsk.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jakarta.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jerusalem.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kabul.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kamchatka.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Karachi.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Katmandu.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kolkata.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Krasnoyarsk.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuala_Lumpur.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuwait.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Magadan.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Muscat.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Novosibirsk.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Rangoon.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Riyadh.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Seoul.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Shanghai.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Singapore.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Taipei.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tashkent.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tbilisi.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tehran.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tokyo.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Ulaanbaatar.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Urumqi.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Vladivostok.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yakutsk.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yekaterinburg.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yerevan.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Azores.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Cape_Verde.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/South_Georgia.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Adelaide.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Brisbane.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Darwin.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Hobart.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Melbourne.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Perth.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Sydney.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Etc (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Etc/UTC.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Amsterdam.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Athens.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Belgrade.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Berlin.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bratislava.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Brussels.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bucharest.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Budapest.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Copenhagen.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Dublin.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Helsinki.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Istanbul.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Kiev.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Lisbon.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Ljubljana.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/London.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Madrid.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Minsk.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Moscow.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Paris.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Prague.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Riga.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Rome.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sarajevo.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Skopje.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sofia.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Stockholm.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Tallinn.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vienna.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vilnius.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Warsaw.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Zagreb.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Auckland.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Fiji.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Guam.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Honolulu.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Majuro.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Midway.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Noumea.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Pago_Pago.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Port_Moresby.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Tongatapu.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/info_timezone.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone_info.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/offset_rationals.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/time_or_datetime.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_definition.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_index_definition.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_info.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_offset_info.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_period.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_proxy.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_transition_info.rb (added)
- trunk/activesupport/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone.rb (added)
- trunk/activesupport/Rakefile (modified) (1 diff)
- trunk/activesupport/test/abstract_unit.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r9108 r9149 1 1 *SVN* 2 3 * Bundling abbreviated version of TZInfo gem 0.3.8: only the classes and zone definitions required to support Rails time zone features are included. If a recent version of the full TZInfo gem is installed, this will take precedence over the bundled version [Geoff Buesing] 2 4 3 5 * TimeWithZone#marshal_load does zone lookup via Time.get_zone, so that tzinfo/Olson identifiers are handled [Geoff Buesing] trunk/activesupport/lib/active_support/time_with_zone.rb
r9108 r9149 1 require 'tzinfo' 1 2 module ActiveSupport 2 3 # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are trunk/activesupport/lib/active_support/values/time_zone.rb
r9107 r9149 1 1 class TimeZone 2 # Keys are Rails TimeZone names, values are TZInfo identifiers 2 3 MAPPING = { 3 4 "International Date Line West" => "Pacific/Midway", … … 41 42 "Casablanca" => "Africa/Casablanca", 42 43 "Monrovia" => "Africa/Monrovia", 43 "UTC" => " UTC",44 "UTC" => "Etc/UTC", 44 45 "Belgrade" => "Europe/Belgrade", 45 46 "Bratislava" => "Europe/Bratislava", … … 94 95 "Karachi" => "Asia/Karachi", 95 96 "Tashkent" => "Asia/Tashkent", 96 "Chennai" => "Asia/ Calcutta",97 "Kolkata" => "Asia/ Calcutta",98 "Mumbai" => "Asia/ Calcutta",99 "New Delhi" => "Asia/ Calcutta",97 "Chennai" => "Asia/Kolkata", 98 "Kolkata" => "Asia/Kolkata", 99 "Mumbai" => "Asia/Kolkata", 100 "New Delhi" => "Asia/Kolkata", 100 101 "Kathmandu" => "Asia/Katmandu", 101 102 "Astana" => "Asia/Dhaka", … … 180 181 "(UTC#{formatted_offset}) #{name}" 181 182 end 182 183 begin # the following methods depend on the tzinfo gem184 require_library_or_gem "tzinfo" unless Object.const_defined?(:TZInfo)185 raise LoadError unless TZInfo.const_defined?(:TimeOrDateTime)186 183 187 # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example: 188 # 189 # Time.zone = "Hawaii" # => "Hawaii" 190 # Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00 191 def local(*args) 192 time = Time.utc_time(*args) 193 ActiveSupport::TimeWithZone.new(nil, self, time) 194 end 195 196 # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example: 197 # 198 # Time.zone = "Hawaii" # => "Hawaii" 199 # Time.utc(2000).to_f # => 946684800.0 200 # Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00 201 def at(secs) 202 utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs) 203 utc.in_time_zone(self) 204 end 205 206 # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example: 207 # 208 # Time.zone = "Hawaii" # => "Hawaii" 209 # Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00 210 # 211 # If upper components are missing from the string, they are supplied from TimeZone#now: 212 # 213 # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00 214 # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00 215 def parse(str, now=now) 216 time = Time.parse(str, now) rescue DateTime.parse(str) 217 ActiveSupport::TimeWithZone.new(nil, self, time) 218 end 219 220 # Returns an ActiveSupport::TimeWithZone instance representing the current time 221 # in the time zone represented by +self+. Example: 222 # 223 # Time.zone = 'Hawaii' # => "Hawaii" 224 # Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00 225 def now 226 Time.now.utc.in_time_zone(self) 227 end 228 229 # Return the current date in this time zone. 230 def today 231 tzinfo.now.to_date 232 end 233 234 # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a 235 # Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead. 236 def utc_to_local(time) 237 tzinfo.utc_to_local(time) 238 end 239 240 # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance. 241 def local_to_utc(time, dst=true) 242 tzinfo.local_to_utc(time, dst) 243 end 244 245 # Available so that TimeZone instances respond like TZInfo::Timezone instances 246 def period_for_utc(time) 247 tzinfo.period_for_utc(time) 248 end 249 250 # Available so that TimeZone instances respond like TZInfo::Timezone instances 251 def period_for_local(time, dst=true) 252 tzinfo.period_for_local(time, dst) 253 end 254 255 def tzinfo 256 @tzinfo ||= TZInfo::Timezone.get(MAPPING[name]) 257 end 258 259 rescue LoadError # Tzinfo gem is not available 260 # re-raise LoadError only when a tzinfo-dependent method is called: 261 %w(local at parse now today utc_to_local local_to_utc period_for_utc period_for_local tzinfo).each do |method| 262 define_method(method) {|*args| raise LoadError, "TZInfo version >= 0.2 is required for TimeZone##{method}(). `gem install tzinfo` and try again."} 263 end 184 # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from given values. Example: 185 # 186 # Time.zone = "Hawaii" # => "Hawaii" 187 # Time.zone.local(2007, 2, 1, 15, 30, 45) # => Thu, 01 Feb 2007 15:30:45 HST -10:00 188 def local(*args) 189 time = Time.utc_time(*args) 190 ActiveSupport::TimeWithZone.new(nil, self, time) 191 end 192 193 # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from number of seconds since the Unix epoch. Example: 194 # 195 # Time.zone = "Hawaii" # => "Hawaii" 196 # Time.utc(2000).to_f # => 946684800.0 197 # Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00 198 def at(secs) 199 utc = Time.at(secs).utc rescue DateTime.civil(1970).since(secs) 200 utc.in_time_zone(self) 201 end 202 203 # Method for creating new ActiveSupport::TimeWithZone instance in time zone of +self+ from parsed string. Example: 204 # 205 # Time.zone = "Hawaii" # => "Hawaii" 206 # Time.zone.parse('1999-12-31 14:00:00') # => Fri, 31 Dec 1999 14:00:00 HST -10:00 207 # 208 # If upper components are missing from the string, they are supplied from TimeZone#now: 209 # 210 # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00 211 # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00 212 def parse(str, now=now) 213 time = Time.parse(str, now) rescue DateTime.parse(str) 214 ActiveSupport::TimeWithZone.new(nil, self, time) 215 end 216 217 # Returns an ActiveSupport::TimeWithZone instance representing the current time 218 # in the time zone represented by +self+. Example: 219 # 220 # Time.zone = 'Hawaii' # => "Hawaii" 221 # Time.zone.now # => Wed, 23 Jan 2008 20:24:27 HST -10:00 222 def now 223 Time.now.utc.in_time_zone(self) 224 end 225 226 # Return the current date in this time zone. 227 def today 228 tzinfo.now.to_date 229 end 230 231 # Adjust the given time to the simultaneous time in the time zone represented by +self+. Returns a 232 # Time.utc() instance -- if you want an ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead. 233 def utc_to_local(time) 234 tzinfo.utc_to_local(time) 235 end 236 237 # Adjust the given time to the simultaneous time in UTC. Returns a Time.utc() instance. 238 def local_to_utc(time, dst=true) 239 tzinfo.local_to_utc(time, dst) 240 end 241 242 # Available so that TimeZone instances respond like TZInfo::Timezone instances 243 def period_for_utc(time) 244 tzinfo.period_for_utc(time) 245 end 246 247 # Available so that TimeZone instances respond like TZInfo::Timezone instances 248 def period_for_local(time, dst=true) 249 tzinfo.period_for_local(time, dst) 250 end 251 252 def tzinfo 253 @tzinfo ||= TZInfo::Timezone.get(MAPPING[name]) 264 254 end 265 255 trunk/activesupport/lib/active_support/vendor.rb
r8546 r9149 19 19 $:.unshift "#{File.dirname(__FILE__)}/vendor/memcache-client-1.5.0" 20 20 end 21 22 begin 23 gem 'tzinfo', '~> 0.3.8' 24 rescue Gem::LoadError 25 $:.unshift "#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.8" 26 end trunk/activesupport/Rakefile
r9054 r9149 86 86 rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages) 87 87 end 88 89 90 require 'lib/active_support/values/time_zone' 91 92 namespace :tzinfo do 93 desc "Update bundled tzinfo gem. Only copies the subset of classes and definitions required to support Rails time zone features." 94 task :update => ['tzinfo:copy_classes', 'tzinfo:copy_definitions'] do 95 Rake::Task['tzinfo:cleanup_tmp'].invoke 96 end 97 98 task :unpack_gem do 99 mkdir_p "tmp" 100 cd "tmp" 101 sh "gem unpack --version #{ENV['VERSION'] || "'> 0'"} tzinfo" 102 cd ".." 103 end 104 105 task :copy_classes => :unpack_gem do 106 mkdir_p "#{destination_path}/tzinfo" 107 cp "#{tmp_path}/lib/tzinfo.rb", destination_path 108 comment_requires_for_excluded_classes!('tzinfo.rb') 109 files = FileList["#{tmp_path}/lib/tzinfo/*.rb"] 110 files.each do |file| 111 filename = File.basename(file) 112 unless excluded_classes.include? filename.sub(/.rb$/, '') 113 cp "#{tmp_path}/lib/tzinfo/#{filename}", "#{destination_path}/tzinfo" 114 comment_requires_for_excluded_classes!("tzinfo/#{filename}") 115 end 116 end 117 end 118 119 task :copy_definitions => :unpack_gem do 120 definitions_path = "#{destination_path}/tzinfo/definitions/" 121 mkdir_p definitions_path 122 TimeZone::MAPPING.values.each do |zone| 123 subdir = nil 124 if /\// === zone 125 subdir = zone.sub(/\w+$/, '') 126 mkdir_p "#{definitions_path}/#{subdir}" 127 end 128 cp "#{tmp_path}/lib/tzinfo/definitions/#{zone}.rb", "#{definitions_path}/#{subdir}" 129 end 130 end 131 132 task :cleanup_tmp do 133 rm_rf "tmp" 134 end 135 136 def comment_requires_for_excluded_classes!(file) 137 lines = open("#{destination_path}/#{file}") {|f| f.readlines} 138 updated = false 139 140 new_lines = [] 141 lines.each do |line| 142 if Regexp.new("require 'tzinfo/(#{excluded_classes.join('|')})'") === line 143 updated = true 144 new_lines << "# #{line}" 145 else 146 new_lines << line 147 end 148 end 149 150 if updated 151 open("#{destination_path}/#{file}", "w") {|f| f.write(new_lines.join)} 152 end 153 end 154 155 def version 156 ENV['VERSION'] ||= get_unpacked_version 157 end 158 159 def get_unpacked_version 160 m = (FileList["tmp/tzinfo-*"].to_s.match /\d+\.\d+\.\d+/) 161 m ? m[0] : raise(LoadError, "TZInfo gem must be installed locally. `gem install tzinfo` and try again") 162 end 163 164 def tmp_path 165 "tmp/tzinfo-#{version}" 166 end 167 168 def destination_path 169 "lib/active_support/vendor/tzinfo-#{version}" 170 end 171 172 def excluded_classes 173 %w(country country_index_definition country_info country_timezone tzdataparser) 174 end 175 end trunk/activesupport/test/abstract_unit.rb
r9071 r9149 24 24 unless defined? uses_tzinfo 25 25 def uses_tzinfo(test_name, &block) 26 uses_gem('tzinfo', test_name, '>= 0.2.0', &block)26 yield #TZInfo is now bundled 27 27 end 28 28 end