class TimezoneParser::ZoneInfo
Generic Timezone
class
Constants
- TIMEZONE_TYPE_DAYLIGHT
- TIMEZONE_TYPE_STANDARD
Attributes
FromTime[RW]
ToTime[RW]
Protected Class Methods
addOffset(offsets, offset, types)
click to toggle source
# File lib/timezone_parser/zone_info.rb, line 108 def self.addOffset(offsets, offset, types) offsets << offset.utc_total_offset if (offset.dst? and types.include?(:daylight)) or (not offset.dst? and types.include?(:standard)) end
convertTypes(rawTypes)
click to toggle source
# File lib/timezone_parser/zone_info.rb, line 112 def self.convertTypes(rawTypes) types = Set.new rawTypes.each do |t| types << :standard unless (t.to_i & TIMEZONE_TYPE_STANDARD).zero? types << :daylight unless (t.to_i & TIMEZONE_TYPE_DAYLIGHT).zero? end types.sort end
findOffsets(timezones, toTime, fromTime, types = nil)
click to toggle source
# File lib/timezone_parser/zone_info.rb, line 86 def self.findOffsets(timezones, toTime, fromTime, types = nil) toTime = Time.now unless toTime types = types.to_a unless types types = [:daylight, :standard] if types.empty? allOffsets = Set.new timezones.each do |timezone| begin tz = TZInfo::Timezone.get(timezone) rescue TZInfo::InvalidTimezoneIdentifier tz = nil end next unless tz offsets = [] self.addOffset(offsets, tz.period_for_utc(fromTime).offset, types) tz.transitions_up_to(toTime, fromTime).each do |transition| self.addOffset(offsets, transition.offset, types) end allOffsets += offsets end allOffsets.sort end
findOffsetsFromTimezonesTypes(timezonesTypes, toTime, fromTime, types)
click to toggle source
# File lib/timezone_parser/zone_info.rb, line 121 def self.findOffsetsFromTimezonesTypes(timezonesTypes, toTime, fromTime, types) timezones = Set.new timezoneTypes = Set.new timezonesTypes.each do |timezoneType| timezones << timezoneType[0] timezoneTypes << timezoneType[1] end timezoneTypes = self.convertTypes(timezoneTypes) if not types.nil? and not types.empty? and not timezoneTypes.empty? types &= timezoneTypes elsif not timezoneTypes.empty? types = timezoneTypes end self.findOffsets(timezones, toTime, fromTime, types).sort end
Public Instance Methods
getMetazones()
click to toggle source
Get Metazone identifiers @return [Array<String>] list of Metazone identifiers
# File lib/timezone_parser/zone_info.rb, line 54 def getMetazones unless @Metazones @Metazones = self.getFilteredData(:Metazones) end @Metazones end
getOffsets()
click to toggle source
Get UTC offsets in seconds @return [Array<Fixnum>] list of timezone offsets in seconds
# File lib/timezone_parser/zone_info.rb, line 36 def getOffsets unless @Offsets @Offsets = self.getFilteredData(:Offsets) end @Offsets end
getTimezones()
click to toggle source
Get Timezone
identifiers @return [Array<String>] list of timezone identifiers
# File lib/timezone_parser/zone_info.rb, line 45 def getTimezones unless @Timezones @Timezones = self.getFilteredData(:Timezones) end @Timezones end
getTypes()
click to toggle source
Get Types @return [Array<Symbol>] list of types
# File lib/timezone_parser/zone_info.rb, line 63 def getTypes unless @TimezoneTypes @TimezoneTypes = self.getFilteredData(:Types) end @TimezoneTypes end
reset()
click to toggle source
Reset cached result
# File lib/timezone_parser/zone_info.rb, line 71 def reset @Offsets = nil @Timezones = nil @Metazones = nil @TimezoneTypes = nil @ToTime = nil @FromTime = nil end
setTime(toTime = nil, fromTime = nil)
click to toggle source
Set time range @param toTime [DateTime] filter timezones before this date, exclusive @param fromTime [DateTime] filter timezones at this date, inclusive @return [ZoneInfo] self
# File lib/timezone_parser/zone_info.rb, line 25 def setTime(toTime = nil, fromTime = nil) @ToTime = toTime @ToTime = DateTime.now unless @ToTime @FromTime = fromTime @FromTime = DateTime.new(@ToTime.year - 1) unless @FromTime self end
Protected Instance Methods
getFilteredData(dataType)
click to toggle source
# File lib/timezone_parser/zone_info.rb, line 82 def getFilteredData(dataType) raise StandardError, '#getFilteredData must be implemented in subclass' end