Class: TimezoneParser::WindowsZone

Inherits:
ZoneInfo
  • Object
show all
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

Attributes inherited from ZoneInfo

#FromTime, #ToTime

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ZoneInfo

#getMetazones, #getOffsets, #getTimezones, #getTypes, #reset, #setTime

Constructor Details

#initialize(name) ⇒ WindowsZone

Windows Timezone instance

Parameters:

  • name (String)

    Windows Timezone name



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

#LocalesObject

Returns the value of attribute Locales.



29
30
31
# File 'lib/timezone_parser/windows_zone.rb', line 29

def Locales
  @Locales
end

#RegionsObject

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

Parameters:

  • name (String)

    Windows Timezone name

  • locales (Array<String>) (defaults to: nil)

    search Timezone name only for these locales

Returns:

  • (Array<String>)

    list of metazone identifiers

See Also:



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

Parameters:

  • name (String)

    Windows Timezone name

  • locales (Array<String>) (defaults to: nil)

    search Timezone name only for these locales

Returns:

  • (Array<Fixnum>)

    list of timezone offsets in seconds

See Also:



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

Parameters:

  • name (String)

    Windows Timezone name

  • locales (Array<String>) (defaults to: nil)

    search Timezone name only for these locales

  • regions (Array<String>) (defaults to: nil)

    look for timezones only for these regions

Returns:

  • (Array<String>)

    list of timezone identifiers

See Also:



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

Parameters:

  • name (String)

    Windows Timezone name

  • locales (Array<String>) (defaults to: nil)

    search Timezone name only for these locales

Returns:

  • (String)

    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

Parameters:

  • name (String)

    Windows Timezone name

  • locales (Array<String>) (defaults to: nil)

    search Timezone name only for these locales

Returns:

  • (Boolean)

    whether Timezone is valid

See Also:



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

.LocalesArray<String>

Locales which will be used for WindowsZone methods if not specified there

Each locale consists of language identifier and country/region identifier

Returns:

  • (Array<String>)

    list containing locale identifiers

See Also:



16
17
18
# File 'lib/timezone_parser/windows_zone.rb', line 16

def self.Locales
    @@Locales
end

.RegionsArray<String>

Regions which will be used for WindowsZone methods if not specified there

Each region is either ISO 3166-1 alpha-2 code

Returns:

  • (Array<String>)

    list containing region identifiers

See Also:



25
26
27
# File 'lib/timezone_parser/windows_zone.rb', line 25

def self.Regions
    @@Regions
end

Instance Method Details

#getZoneString

Windows Timezone identifier

Returns:

  • (String)

    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

Returns:

  • (Boolean)

    whether 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

Parameters:

  • locales (Array<String>) (defaults to: nil)

    search only in these locales

  • regions (Array<String>) (defaults to: nil)

    filter for these regions

Returns:

See Also:



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