Class Chronos::Zone
In: lib/chronos/zone.rb
Parent: Object

Methods

[]   inspect   load   zone_names  

Constants

Inspect = "#<%s:%s>"
Offset = { "UTC-12".to_sym => -43200, # I would love to use :'UTC-12', but rdoc fails with that "UTC-11".to_sym => -39600, "UTC-10".to_sym => -36000, "UTC-9:30".to_sym => -34200, "UTC-9".to_sym => -32400, "UTC-8".to_sym => -28800, "UTC-7".to_sym => -25200, "UTC-6".to_sym => -21600, "UTC-5".to_sym => -18000, "UTC-4:30".to_sym => -16200, "UTC-4".to_sym => -14400, "UTC-3:30".to_sym => -12600, "UTC-3".to_sym => -10800, "UTC-2".to_sym => -7200, "UTC-1".to_sym => -3600, "UTC".to_sym => 0, "UTC+1".to_sym => 3600, "UTC+2".to_sym => 7200, "UTC+3".to_sym => 10800, "UTC+3:07".to_sym => 11224, "UTC+3:30".to_sym => 12600, "UTC+4".to_sym => 14400, "UTC+4:30".to_sym => 16200, "UTC+5".to_sym => 18000, "UTC+5:30".to_sym => 19800, "UTC+5:45".to_sym => 20700, "UTC+6".to_sym => 21600, "UTC+6:30".to_sym => 23400, "UTC+7".to_sym => 25200, "UTC+8".to_sym => 28800, "UTC+8:45".to_sym => 31500, "UTC+9".to_sym => 32400, "UTC+9:30".to_sym => 34200, "UTC+10".to_sym => 36000, "UTC+10:30".to_sym => 37800, "UTC+11".to_sym => 39600, "UTC+11:30".to_sym => 41400, "UTC+12".to_sym => 43200, "UTC+12:45".to_sym => 45900, "UTC+13".to_sym => 46800, "UTC+14".to_sym => 50400, }   the UTC timezones, offset in seconds FIXME: as soon as rdoc stops sucking, use :’<name>’ instead of ’<name>’.to_sym (:stopdoc: proved useless, see earlier version in the git repo)
Map = Hash.new { |hash, key| key }.merge!({ # for ::DateTime '-12:00' => ['utc-12', false], '-11:00' => ['utc-11', false], '-10:00' => ['utc-10', false], '-09:00' => ['utc-9', false], '-08:00' => ['utc-8', false], '-07:00' => ['utc-7', false], '-06:00' => ['utc-6', false], '-05:00' => ['utc-5', false], '-04:30' => ['utc-4:30', false], '-04:00' => ['utc-4', false], '-03:00' => ['utc-3', false], '-03:30' => ['utc-3:30', false], '-02:00' => ['utc-2', false], '-01:00' => ['utc-1', false], '+00:00' => ['utc', false], '+01:00' => ['utc+1', false], '+02:00' => ['utc+2', false], '+03:00' => ['utc+3', false], '+03:30' => ['utc+3:30', false], '+04:00' => ['utc+4', false], '+05:00' => ['utc+5', false], '+05:30' => ['utc+5:30', false], '+06:00' => ['utc+6', false], '+07:00' => ['utc+7', false], '+08:00' => ['utc+8', false], '+09:00' => ['utc+9', false], '+09:30' => ['utc+9:30', false], '+10:00' => ['utc+10', false], '+11:00' => ['utc+11', false], '+12:00' => ['utc+12', false], # military & old 'yankee' => ['utc-12', false], 'xray' => ['utc-11', false], 'hst' => ['utc-10', false], 'whisky' => ['utc-10', false], 'akst' => ['utc-9', false], 'akdt' => ['utc-9', true], 'ydt' => ['utc-9', true], 'victor' => ['utc-9', false], 'pst' => ['utc-8', false], 'pdt' => ['utc-8', true], 'uniform' => ['utc-8', false], 'mst' => ['utc-7', false], 'mdt' => ['utc-7', true], 'tango' => ['utc-7', false], 'cst' => ['utc-6', false], 'cdt' => ['utc-6', true], 'sierra' => ['utc-6', false], 'est' => ['utc-5', false], 'edt' => ['utc-5', true], 'romeo' => ['utc-5', false], 'vst' => ['utc-4:30', false], 'ast' => ['utc-4', false], 'adt' => ['utc-4', true], 'quebec' => ['utc-4', false], 'nst' => ['utc-3:30', false], 'ndt' => ['utc-3:30', true], 'papa' => ['utc-3', false], 'oscar' => ['utc-2', false], 'november' => ['utc-1', false], 'gmt' => ['utc', false], 'wet' => ['utc', false], 'zulu' => ['utc', false], 'cet' => ['utc+1', false], 'cest' => ['utc+1', true], 'alpha' => ['utc+1', false], 'bravo' => ['utc+2', false], 'msk' => ['utc+3', false], 'charlie' => ['utc+3', false], 'delta' => ['utc+4', false], 'echo' => ['utc+5', false], 'ist' => ['utc+5:30', false], 'foxtrot' => ['utc+6', false], 'golf' => ['utc+7', false], 'awst' => ['utc+8', false], 'hotel' => ['utc+8', false], 'india' => ['utc+9', false], 'acst' => ['utc+9:30', false], 'aest' => ['utc+10', false], 'kilo' => ['utc+10', false], 'lima' => ['utc+11', false], 'mike' => ['utc+12', false]   map old/military timezone names to UTC corresponding utc, isDST[BOOL]

Public Class methods

[Source]

     # File lib/chronos/zone.rb, line 195
195:     def self.[](name)
196:       name = name.to_s.downcase
197:       if zone = @by_name[name] then
198:         zone
199:       elsif mapped = Map[name]
200:         @by_name[mapped.first]
201:       end
202:     end

load locations from a tabfile

[Source]

     # File lib/chronos/zone.rb, line 167
167:     def self.load(tabfile, marshalfile=nil, marshal=true)
168:       if marshalfile && File.readable?(marshalfile) && File.mtime(tabfile) <= File.mtime(marshalfile) then
169:         @by_name.update(Marshal.load(File.read(marshalfile)))
170:       else
171:         data = {}
172:         File.foreach(tabfile) { |line|
173:           next if line[0] == ?#
174:           tmp                    = line.chomp.split("\t")
175:           tmp[3,0]               = 0
176:           location               = new(*tmp)
177:           location.utc           = location.utc.to_sym
178:           location.offset        = Offset[location.utc]
179:           location.numeric       = Integer(location.numeric) rescue nil
180:           location.latitude      = Float(location.latitude) rescue nil
181:           location.longitude     = Float(location.longitude) rescue nil
182:           location.latitude_iso  = Integer(location.latitude_iso) rescue nil
183:           location.longitude_iso = Integer(location.longitude_iso) rescue nil
184:           data[location.timezone_id.downcase] = location
185:         }
186:         @by_name.update(data)
187:         if marshalfile && marshal then
188:           File.open(marshalfile, "wb") { |fh|
189:             fh.write(Marshal.dump(data))
190:           }
191:         end
192:       end
193:     end

Public Instance methods

[Source]

     # File lib/chronos/zone.rb, line 208
208:     def inspect
209:       sprintf Inspect, self.class, timezone_id
210:     end

[Source]

     # File lib/chronos/zone.rb, line 204
204:     def zone_names
205:       @by_name.keys
206:     end

[Validate]