Class: When::Parts::Timezone
- Inherits:
-
Object
- Object
- When::Parts::Timezone
- Extended by:
- Resource::Pool
- Defined in:
- lib/when_exe/parts/timezone.rb
Overview
TZInfo::Timezone クラスを本ライブラリから使用するためのラッパークラス
Instance Attribute Summary collapse
-
#daylight ⇒ When::TM::Clock
readonly
夏時間帯の時計.
-
#difference ⇒ When::TM:IntervalLength
readonly
夏時間帯と標準時間帯の時間差.
-
#indices ⇒ Array<When::Coordinates::Index>
readonly
時分秒のインデクス.
-
#standard ⇒ When::TM::Clock
readonly
標準時間帯の時計.
-
#timezone ⇒ TZInfo::Timezone
readonly
ラップしている TZInfo::Timezone インスタンス.
Class Method Summary collapse
-
.[](label) ⇒ When::Parts::Timezone
(also: get)
オブジェクト参照.
- ._get ⇒ Object
-
.tz_info ⇒ Hash
TZInfo でサポートしている Timezone の連想配列.
Instance Method Summary collapse
- #_daylight(zdate = nil) ⇒ Object
- #_need_validate ⇒ Object
-
#initialize(identifier) ⇒ Timezone
constructor
オブジェクト生成.
-
#label ⇒ String
ユニーク識別名.
-
#latitude ⇒ Rational
時間帯を代表する都市の緯度 / 度.
-
#longitude ⇒ Rational
時間帯を代表する都市の経度 / 度.
Methods included from Resource::Pool
[], []=, _pool, _setup_, pool_keys
Methods included from Resource::Synchronize
Constructor Details
#initialize(identifier) ⇒ Timezone
オブジェクト生成
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/when_exe/parts/timezone.rb', line 109 def initialize(identifier) @timezone = TZInfo::Timezone.get(identifier) unless TZInfo::TimeOrDateTime.method_defined?(:_to_datetime) if TZInfo::RubyCoreSupport.respond_to?(:datetime_new) TZInfo::TimeOrDateTime.class_eval %Q{ alias :_to_datetime :to_datetime ::Rational def to_datetime unless @datetime u = usec s = u == 0 ? sec : Rational(sec * 1000000 + u, 1000000) @datetime = TZInfo::RubyCoreSupport.datetime_new(year, mon, mday, hour, min, s, 0, Date::GREGORIAN) end @datetime end } else TZInfo::TimeOrDateTime.class_eval %Q{ alias :_to_datetime :to_datetime def to_datetime @datetime ||= DateTime.new(year, mon, mday, hour, min, sec, 0, Date::GREGORIAN) end } end end std, dst = _offsets(Time.now.to_i) @standard = When::TM::Clock.new({:zone=>std, :tz_prop=>self}) if std == dst @daylight = @standard @difference = 0 else @daylight = When::TM::Clock.new({:zone=>dst, :tz_prop=>self}) @difference = @standard.universal_time - @daylight.universal_time end @indices = When::Coordinates::DefaultTimeIndices end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
その他のメソッド
When::Parts::GeometricComplex で定義されていないメソッドは
処理を first (type: When::TM::(Temporal)Position) に委譲する
184 185 186 |
# File 'lib/when_exe/parts/timezone.rb', line 184 def method_missing(name, *args, &block) timezone.send(name.to_sym, *args, &block) end |
Instance Attribute Details
#daylight ⇒ When::TM::Clock (readonly)
夏時間帯の時計
77 78 79 |
# File 'lib/when_exe/parts/timezone.rb', line 77 def daylight @daylight end |
#difference ⇒ When::TM:IntervalLength (readonly)
夏時間帯と標準時間帯の時間差
81 82 83 |
# File 'lib/when_exe/parts/timezone.rb', line 81 def difference @difference end |
#indices ⇒ Array<When::Coordinates::Index> (readonly)
時分秒のインデクス
103 104 105 |
# File 'lib/when_exe/parts/timezone.rb', line 103 def indices @indices end |
#standard ⇒ When::TM::Clock (readonly)
標準時間帯の時計
73 74 75 |
# File 'lib/when_exe/parts/timezone.rb', line 73 def standard @standard end |
#timezone ⇒ TZInfo::Timezone (readonly)
ラップしている TZInfo::Timezone インスタンス
69 70 71 |
# File 'lib/when_exe/parts/timezone.rb', line 69 def timezone @timezone end |
Class Method Details
.[](label) ⇒ When::Parts::Timezone Also known as: get
オブジェクト参照
30 31 32 33 34 |
# File 'lib/when_exe/parts/timezone.rb', line 30 def [](label) ref = _get(label) return ref if ref self[label] = self.new(label) end |
._get ⇒ Object
22 |
# File 'lib/when_exe/parts/timezone.rb', line 22 alias :_get :[] |
.tz_info ⇒ Hash
TZInfo でサポートしている Timezone の連想配列
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/when_exe/parts/timezone.rb', line 43 def tz_info return @tz_info if @tz_info zones = {} TZInfo::Country.all.each do |c| c.zone_info.each do |z| zones[z.identifier] ||= {} zones[z.identifier][c.code] = z end end @tz_info = {} zones.each_pair do |id, hash| if hash.keys.size == 1 @tz_info[id] = hash[hash.keys[0]] else hash.each_pair do |c, z| @tz_info["#{id}(#{c})"] = z end end end @tz_info end |
Instance Method Details
#_daylight(zdate = nil) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/when_exe/parts/timezone.rb', line 147 def _daylight(zdate=nil) if block_given? zdate = yield(@standard.dup.tap{|clock| clock.tz_prop = nil}) now = zdate.to_time.to_i clocks = _offsets(now).map {|clock| When::TM::Clock.new({:zone=>clock, :tz_prop=>self})} flags = clocks.map {|z| @timezone.period_for_utc(yield(z.dup.tap{|clock| clock.tz_prop = nil}).to_time.to_i).dst? } (flags[0] || flags[1]) ? clocks[1] : clocks[0] else When::TM::Clock.new({:zone=>@timezone.period_for_utc(zdate.to_time.to_i).utc_total_offset, :tz_prop=>self}) end end |
#_need_validate ⇒ Object
160 161 162 |
# File 'lib/when_exe/parts/timezone.rb', line 160 def _need_validate true end |
#label ⇒ String
ユニーク識別名
85 86 87 |
# File 'lib/when_exe/parts/timezone.rb', line 85 def label @timezone.identifier end |
#latitude ⇒ Rational
時間帯を代表する都市の緯度 / 度
97 98 99 |
# File 'lib/when_exe/parts/timezone.rb', line 97 def latitude self.class.tz_info[label].latitude end |
#longitude ⇒ Rational
時間帯を代表する都市の経度 / 度
91 92 93 |
# File 'lib/when_exe/parts/timezone.rb', line 91 def longitude self.class.tz_info[label].longitude end |