Class: TimezoneParser::WindowsZone
- Defined in:
- lib/timezone_parser/windows_zone.rb
Overview
Windows Timezone
Constant Summary
Constants inherited from ZoneInfo
ZoneInfo::TIMEZONE_TYPE_DAYLIGHT, ZoneInfo::TIMEZONE_TYPE_STANDARD
Instance Attribute Summary collapse
-
#Locales ⇒ Object
Returns the value of attribute Locales.
-
#Regions ⇒ Object
Returns the value of attribute Regions.
Attributes inherited from ZoneInfo
Class Method Summary collapse
-
.getMetazones(name, locales = nil) ⇒ Array<String>
Get Metazone identifiers for given Windows Timezone name.
-
.getOffsets(name, locales = nil) ⇒ Array<Fixnum>
Get UTC offsets in seconds for given Windows Timezone name.
-
.getTimezones(name, locales = nil, regions = nil) ⇒ Array<String>
Get Timezone identifiers for given Windows Timezone name.
-
.getZone(name, locales = nil) ⇒ String
Windows Timezone identifier.
-
.isValid?(name, locales = nil) ⇒ Boolean
Check if given Windows Timezone name is a valid timezone.
-
.Locales ⇒ Array<String>
Locales which will be used for WindowsZone methods if not specified there.
-
.Regions ⇒ Array<String>
Regions which will be used for WindowsZone methods if not specified there.
Instance Method Summary collapse
-
#getZone ⇒ String
Windows Timezone identifier.
-
#initialize(name) ⇒ WindowsZone
constructor
Windows Timezone instance.
-
#isValid? ⇒ Boolean
Check if timezone is valid.
-
#set(locales = nil, regions = nil) ⇒ WindowsZone
Set locales and regions.
Methods inherited from ZoneInfo
#getMetazones, #getOffsets, #getTimezones, #getTypes, #reset, #setTime
Constructor Details
#initialize(name) ⇒ WindowsZone
Windows Timezone instance
34 35 36 37 38 |
# File 'lib/timezone_parser/windows_zone.rb', line 34 def initialize(name) @Name = name @Valid = nil set(@@Locales.dup, @@Regions.dup) end |
Instance Attribute Details
#Locales ⇒ Object
Returns the value of attribute Locales.
29 30 31 |
# File 'lib/timezone_parser/windows_zone.rb', line 29 def Locales @Locales end |
#Regions ⇒ Object
Returns the value of attribute Regions.
30 31 32 |
# File 'lib/timezone_parser/windows_zone.rb', line 30 def Regions @Regions end |
Class Method Details
.getMetazones(name, locales = nil) ⇒ Array<String>
Get Metazone identifiers for given Windows Timezone name
117 118 119 |
# File 'lib/timezone_parser/windows_zone.rb', line 117 def self.getMetazones(name, locales = nil) self.new(name).set(locales, nil).getMetazones end |
.getOffsets(name, locales = nil) ⇒ Array<Fixnum>
Get UTC offsets in seconds for given Windows Timezone name
97 98 99 |
# File 'lib/timezone_parser/windows_zone.rb', line 97 def self.getOffsets(name, locales = nil) self.new(name).set(locales, nil).getOffsets end |
.getTimezones(name, locales = nil, regions = nil) ⇒ Array<String>
Get Timezone identifiers for given Windows Timezone name
108 109 110 |
# File 'lib/timezone_parser/windows_zone.rb', line 108 def self.getTimezones(name, locales = nil, regions = nil) self.new(name).set(locales, regions).getTimezones end |
.getZone(name, locales = nil) ⇒ String
Windows Timezone identifier
125 126 127 |
# File 'lib/timezone_parser/windows_zone.rb', line 125 def self.getZone(name, locales = nil) self.new(name).set(locales, nil).getZone end |
.isValid?(name, locales = nil) ⇒ Boolean
Check if given Windows Timezone name is a valid timezone
88 89 90 |
# File 'lib/timezone_parser/windows_zone.rb', line 88 def self.isValid?(name, locales = nil) self.new(name).set(locales).isValid? end |
.Locales ⇒ Array<String>
Locales which will be used for WindowsZone methods if not specified there
Each locale consists of language identifier and country/region identifier
16 17 18 |
# File 'lib/timezone_parser/windows_zone.rb', line 16 def self.Locales @@Locales end |
.Regions ⇒ Array<String>
Regions which will be used for WindowsZone methods if not specified there
Each region is either ISO 3166-1 alpha-2 code
25 26 27 |
# File 'lib/timezone_parser/windows_zone.rb', line 25 def self.Regions @@Regions end |
Instance Method Details
#getZone ⇒ String
Windows Timezone identifier
76 77 78 79 80 81 |
# File 'lib/timezone_parser/windows_zone.rb', line 76 def getZone unless @Zone @Zone = self.getFilteredData(:Zone).first end @Zone end |
#isValid? ⇒ Boolean
Check if timezone is valid
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/timezone_parser/windows_zone.rb', line 54 def isValid? if @Valid.nil? params = [] joins = '' where = '' if not @Locales.empty? joins += ' LEFT JOIN `Locales` AS L ON TN.Locale = L.ID' where = 'L.Name COLLATE NOCASE IN (' + Array.new(@Locales.count, '?').join(',') + ') AND ' params += @Locales end sql = "SELECT 1 FROM `WindowsZoneNames` TN #{joins} WHERE #{where}TN.`NameLowercase` = ? LIMIT 1" params << @Name.downcase @Valid = Data::Storage.getStatement(sql).execute(*params).count > 0 end @Valid end |
#set(locales = nil, regions = nil) ⇒ WindowsZone
Set locales and regions
46 47 48 49 50 |
# File 'lib/timezone_parser/windows_zone.rb', line 46 def set(locales = nil, regions = nil) @Locales = locales unless locales.nil? @Regions = regions unless regions.nil? self end |