Class: TimezoneParser::Abbreviation

Inherits:
ZoneInfo
  • Object
show all
Defined in:
lib/timezone_parser/abbreviation.rb

Overview

Timezone abbreviation

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(abbreviation) ⇒ Abbreviation

Abbreviation instance

Parameters:

  • abbreviation (String)

    Timezone abbreviation



24
25
26
27
28
# File 'lib/timezone_parser/abbreviation.rb', line 24

def initialize(abbreviation)
    @Abbreviation = abbreviation
    setTime
    set(@@Regions.dup, nil)
end

Instance Attribute Details

#RegionsObject

Returns the value of attribute Regions.



19
20
21
# File 'lib/timezone_parser/abbreviation.rb', line 19

def Regions
  @Regions
end

#TypeObject

Returns the value of attribute Type.



20
21
22
# File 'lib/timezone_parser/abbreviation.rb', line 20

def Type
  @Type
end

Class Method Details

.couldBeValid?(abbreviation) ⇒ Boolean

Check if given Timezone abbreviation (case-insensitive) could be a valid timezone

Parameters:

  • abbreviation (String)

    Timezone abbreviation to check for

Returns:

  • (Boolean)

    whether Timezone is valid



61
62
63
# File 'lib/timezone_parser/abbreviation.rb', line 61

def self.couldBeValid?(abbreviation)
    Data::Storage.getStatement('SELECT 1 FROM `Abbreviations` WHERE `NameLowercase` = ? LIMIT 1').execute(abbreviation.downcase).count > 0
end

.getMetazones(abbreviation) ⇒ Object

Get Metazone identifiers for given Timezone abbreviation

Parameters:

  • abbreviation (String)

    Timezone abbreviation



91
92
93
# File 'lib/timezone_parser/abbreviation.rb', line 91

def self.getMetazones(abbreviation)
    self.new(abbreviation).getMetazones
end

.getOffsets(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) ⇒ Array<Fixnum>

Get UTC offsets in seconds for given Timezone abbreviation

Parameters:

  • abbreviation (String)

    Timezone abbreviation

  • toTime (DateTime) (defaults to: nil)

    look for offsets which came into effect before this date, exclusive

  • fromTime (DateTime) (defaults to: nil)

    look for offsets which came into effect at this date, inclusive

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

    look for offsets only for these regions

  • type (Symbol) (defaults to: nil)

    specify whether offset should be :standard time or :daylight

Returns:

  • (Array<Fixnum>)

    list of timezone offsets in seconds

See Also:



73
74
75
# File 'lib/timezone_parser/abbreviation.rb', line 73

def self.getOffsets(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil)
    self.new(abbreviation).setTime(toTime, fromTime).set(regions, type).getOffsets
end

.getTimezones(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil) ⇒ Array<String>

Get Timezone identifiers for given Timezone abbreviation

Parameters:

  • abbreviation (String)

    Timezone abbreviation

  • toTime (DateTime) (defaults to: nil)

    look for timezones which came into effect before this date, exclusive

  • fromTime (DateTime) (defaults to: nil)

    look for timezones which came into effect at this date, inclusive

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

    look for timezones only for these regions

  • type (Symbol) (defaults to: nil)

    specify whether timezones should be :standard time or :daylight

Returns:

  • (Array<String>)

    list of timezone identifiers

See Also:



85
86
87
# File 'lib/timezone_parser/abbreviation.rb', line 85

def self.getTimezones(abbreviation, toTime = nil, fromTime = nil, regions = nil, type = nil)
    self.new(abbreviation).setTime(toTime, fromTime).set(regions, type).getTimezones
end

.isValid?(abbreviation) ⇒ Boolean

Check if given Timezone abbreviation (case-sensitive) is a valid timezone

Parameters:

  • abbreviation (String)

    Timezone abbreviation

Returns:

  • (Boolean)

    whether Timezone is valid



54
55
56
# File 'lib/timezone_parser/abbreviation.rb', line 54

def self.isValid?(abbreviation)
    Data::Storage.getStatement('SELECT 1 FROM `Abbreviations` WHERE `Name` = ? LIMIT 1').execute(abbreviation).count > 0
end

.RegionsArray<String>

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

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

Returns:

  • (Array<String>)

    list containing region identifiers

See Also:



15
16
17
# File 'lib/timezone_parser/abbreviation.rb', line 15

def self.Regions
    @@Regions
end

Instance Method Details

#isValid?Boolean

Check if abbreviation is valid

Returns:

  • (Boolean)

    whether abbreviation is valid



43
44
45
46
47
48
49
# File 'lib/timezone_parser/abbreviation.rb', line 43

def isValid?
    if @Valid.nil?
        sql = 'SELECT 1 FROM `Abbreviations` WHERE `Name` = ? LIMIT 1'
        @Valid = Data::Storage.getStatement(sql).execute(@Abbreviation).count > 0
    end
    @Valid
end

#set(regions = nil, type = nil) ⇒ Abbreviation

Set regions and type

Parameters:

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

    filter for these regions

  • type (Symbol) (defaults to: nil)

    filter by type, :standard time or :daylight

Returns:

See Also:



35
36
37
38
39
# File 'lib/timezone_parser/abbreviation.rb', line 35

def set(regions = nil, type = nil)
    @Regions = regions unless regions.nil?
    @Type = type.to_sym if type
    self
end