when_exe 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -33
  3. data/bin/locales.rb +1 -1
  4. data/bin/make_ttl.rb.config +1 -1
  5. data/lib/when_exe.rb +27 -16
  6. data/lib/when_exe/basictypes.rb +772 -771
  7. data/lib/when_exe/calendartypes.rb +1485 -1453
  8. data/lib/when_exe/coordinates.rb +5 -0
  9. data/lib/when_exe/core/compatibility.rb +1 -1
  10. data/lib/when_exe/core/duration.rb +147 -116
  11. data/lib/when_exe/core/extension.rb +499 -497
  12. data/lib/when_exe/ephemeris.rb +1952 -1951
  13. data/lib/when_exe/ephemeris/eclipse.rb +5 -4
  14. data/lib/when_exe/ephemeris/notes.rb +457 -421
  15. data/lib/when_exe/ephemeris/planets.rb +585 -585
  16. data/lib/when_exe/ephemeris/sun.rb +214 -214
  17. data/lib/when_exe/google_api.rb +153 -0
  18. data/lib/when_exe/icalendar.rb +1640 -1632
  19. data/lib/when_exe/inspect.rb +42 -20
  20. data/lib/when_exe/linkeddata.rb +28 -7
  21. data/lib/when_exe/locales/autoload.rb +2 -1
  22. data/lib/when_exe/locales/locale.rb +35 -15
  23. data/lib/when_exe/locales/zh.rb +77 -0
  24. data/lib/when_exe/mini_application.rb +3 -1
  25. data/lib/when_exe/{googlecalendar.rb → obsolete/googlecalendar.rb} +144 -144
  26. data/lib/when_exe/parts/enumerator.rb +498 -486
  27. data/lib/when_exe/parts/geometric_complex.rb +397 -397
  28. data/lib/when_exe/parts/timezone.rb +246 -241
  29. data/lib/when_exe/region/armenian.rb +55 -56
  30. data/lib/when_exe/region/babylonian.rb +406 -405
  31. data/lib/when_exe/region/bahai.rb +107 -106
  32. data/lib/when_exe/region/balinese.rb +624 -622
  33. data/lib/when_exe/region/chinese.rb +1071 -1026
  34. data/lib/when_exe/region/chinese/epochs.rb +28 -28
  35. data/lib/when_exe/region/chinese/notes.rb +219 -0
  36. data/lib/when_exe/region/chinese/twins.rb +803 -803
  37. data/lib/when_exe/region/christian.rb +21 -15
  38. data/lib/when_exe/region/coptic.rb +107 -106
  39. data/lib/when_exe/region/discordian.rb +218 -218
  40. data/lib/when_exe/region/east_asian.rb +1 -1
  41. data/lib/when_exe/region/french.rb +126 -56
  42. data/lib/when_exe/region/geologicalage.rb +639 -639
  43. data/lib/when_exe/region/goddess.rb +60 -58
  44. data/lib/when_exe/region/hanke_henry.rb +2 -2
  45. data/lib/when_exe/region/indian.rb +1225 -1222
  46. data/lib/when_exe/region/international_fixed.rb +96 -97
  47. data/lib/when_exe/region/iranian.rb +206 -203
  48. data/lib/when_exe/region/islamic.rb +102 -102
  49. data/lib/when_exe/region/japanese.rb +126 -71
  50. data/lib/when_exe/region/japanese/epochs.rb +426 -426
  51. data/lib/when_exe/region/japanese/notes.rb +101 -81
  52. data/lib/when_exe/region/japanese/residues.rb +1345 -1311
  53. data/lib/when_exe/region/japanese/twins.rb +225 -225
  54. data/lib/when_exe/region/japanese/weeks.rb +112 -112
  55. data/lib/when_exe/region/javanese.rb +230 -230
  56. data/lib/when_exe/region/jewish.rb +130 -131
  57. data/lib/when_exe/region/m17n.rb +114 -114
  58. data/lib/when_exe/region/martian.rb +258 -258
  59. data/lib/when_exe/region/mayan.rb +11 -8
  60. data/lib/when_exe/region/pax.rb +4 -5
  61. data/lib/when_exe/region/pope.rb +1 -1
  62. data/lib/when_exe/region/positivist.rb +100 -100
  63. data/lib/when_exe/region/residue.rb +162 -162
  64. data/lib/when_exe/region/roman.rb +333 -333
  65. data/lib/when_exe/region/{soviet.rb → russian.rb} +221 -209
  66. data/lib/when_exe/region/shire.rb +222 -223
  67. data/lib/when_exe/region/symmetry.rb +50 -50
  68. data/lib/when_exe/region/thai.rb +336 -336
  69. data/lib/when_exe/region/tibetan.rb +315 -316
  70. data/lib/when_exe/region/tranquility.rb +207 -208
  71. data/lib/when_exe/region/vanishing_leprechaun.rb +3 -1
  72. data/lib/when_exe/region/vietnamese.rb +449 -440
  73. data/lib/when_exe/region/weekdate.rb +80 -80
  74. data/lib/when_exe/region/world.rb +170 -171
  75. data/lib/when_exe/region/world_season.rb +89 -89
  76. data/lib/when_exe/region/yerm.rb +3 -3
  77. data/lib/when_exe/region/zoroastrian.rb +205 -205
  78. data/lib/when_exe/timestandard.rb +708 -707
  79. data/lib/when_exe/tmduration.rb +338 -338
  80. data/lib/when_exe/tmobjects.rb +1356 -1356
  81. data/lib/when_exe/tmposition.rb +66 -31
  82. data/lib/when_exe/version.rb +16 -2
  83. data/test/examples/Residue.m17n +83 -83
  84. data/test/examples/Terms.m17n +2 -2
  85. data/test/test.rb +2 -2
  86. data/test/test/google_api.rb +65 -0
  87. data/test/test/linkeddata.rb +1 -1
  88. data/test/test/{googlecalendar.rb → obsolete/googlecalendar.rb} +194 -194
  89. data/test/test/region/indian.rb +90 -85
  90. data/test/test/region/m17n.rb +7 -7
  91. data/test/test/region/mayan.rb +195 -195
  92. data/test/test/region/residue.rb +153 -153
  93. data/test/test/tmposition.rb +11 -1
  94. data/when_exe.gemspec +2 -2
  95. metadata +95 -8
  96. data/test/test.rb.config +0 -1
@@ -1,338 +1,338 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Minimum subset - A multicultural and multilingualized calendar library based on ISO 8601, ISO 19108 and RFC 5545
4
-
5
- Copyright (C) 2013 Takashi SUGA
6
-
7
- You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
8
-
9
- =end
10
-
11
- module When
12
-
13
- # 分解能定数
14
-
15
- CENTURY = -4
16
- DECADE = -3
17
- YEAR = -2
18
- MONTH = -1
19
- WEEK = -0.5
20
- DAY = 0
21
- HOUR = 1
22
- MINUTE = 2
23
- SECOND = 3
24
- STRING = 5
25
- SYSTEM = (Float::MANT_DIG*0.3).to_i
26
-
27
- #
28
- # (5.2) Temporal Objects Package
29
- #
30
- #
31
- module TM
32
-
33
- # 時間次元における長さ又は距離を記述するために使うデータ型
34
- #
35
- # see {gml schema}[link:http://schemas.opengis.net/gml/3.1.1/base/temporal.xsd#duration]
36
- #
37
- class Duration
38
-
39
- # 物理的な時間間隔の定数
40
- #
41
- # 時間の「秒」を Float で表現して丸め誤差が発生しない範囲で、
42
- # もっとも大きな時間間隔(86400s を 2 の因数で割りつくした値)
43
- # を単位 SYSTEM とする
44
- #
45
- SYSTEM = 1.0
46
- DAY = SYSTEM * 675
47
- YEAR = DAY * 365.2425
48
- MONTH = YEAR / 12
49
- WEEK = DAY * 7
50
- HOUR = DAY / 24
51
- MINUTE = HOUR / 60
52
- SECOND = MINUTE / 60
53
-
54
- UnitName = {YEAR=>'year', MONTH =>'month', WEEK =>'week', DAY =>'day',
55
- HOUR=>'hour', MINUTE=>'minute', SECOND=>'second', SYSTEM=>'system'}
56
- Unit = UnitName.invert
57
- DurationUnits = [DAY, HOUR, MINUTE, SECOND]
58
-
59
- #
60
- # オブジェクト生成用クラスメソッド
61
- #
62
- class << self
63
- #
64
- # 日時分秒からのオブジェクト生成
65
- #
66
- # @param [Array<Numeric>] value ( 日, 時, 分, 秒 ) 下位の桁は省略可
67
- #
68
- # @return [When::TM::Duration]
69
- #
70
- def dhms(*value)
71
- units = DurationUnits.dup
72
- Duration.new(value.inject(0) {|s,v| s + v * units.shift})
73
- end
74
-
75
- #
76
- # メソッド名に相当する単位で表した value に対応する When::TM::Duration を生成する
77
- # @method unit
78
- # @param [Numeric] value
79
- # @return [When::TM::Duration]
80
- # @note unit は second, minute, hour, day, week に読み替える
81
-
82
- # @private
83
- Unit.keys.each do |key|
84
- module_eval %Q{
85
- def #{key}(value)
86
- new(value * Unit['#{key}'])
87
- end
88
- }
89
- end
90
- end
91
-
92
- # 時間間隔の長さ (128秒単位)
93
- #
94
- # @return [Numeric]
95
- #
96
- attr_accessor :duration
97
-
98
- #
99
- # メソッド名に相当する単位で表した時間間隔の大きさ
100
- # @method unit
101
- # @return [Numeric]
102
- # @note unit は second, minute, hour, day, week に読み替える
103
-
104
- # @private
105
- Unit.keys.each do |key|
106
- module_eval %Q{
107
- def #{key}
108
- duration / Unit['#{key}']
109
- end
110
- }
111
- end
112
-
113
- # 時間間隔の長さ / 秒
114
- #
115
- # @return [Float]
116
- #
117
- def to_f
118
- duration / SECOND
119
- end
120
- alias :to_float :to_f
121
-
122
- # 時間間隔の長さ / 秒
123
- #
124
- # @return [Integer] (四捨五入値)
125
- #
126
- def to_i
127
- to_f.round
128
- end
129
- alias :to_int :to_i
130
-
131
- # 符号反転
132
- #
133
- # @return [When::TM::Duration]
134
- #
135
- def -@
136
- Duration.new(-@duration)
137
- end
138
-
139
- # 絶対値
140
- #
141
- # @return [When::TM::Duration]
142
- #
143
- def abs
144
- sign >= 0 ? self.dup : -self
145
- end
146
-
147
- # 符号
148
- #
149
- # @return [Integer] 0 との比較により、負,0,正の値を返す
150
- #
151
- def sign
152
- @duration <=> 0
153
- end
154
-
155
- # 比較
156
- #
157
- # @param [Numeric, When::TM::Duration] other
158
- #
159
- # @return [Integer] other との比較により、負,0,正の値を返す
160
- #
161
- def <=>(other)
162
- self.to_f <=> other.to_f
163
- end
164
-
165
- # オブジェクトの同値
166
- #
167
- # @param [Object] other
168
- #
169
- # @return [Boolean]
170
- # [ true - 同値 ]
171
- # [ false - 非同値 ]
172
- #
173
- def ==(other)
174
- return false unless other.instance_of?(self.class)
175
- return self.duration == other.duration
176
- end
177
-
178
- #
179
- # 加算
180
- #
181
- # @param [Numeric, When::TM::Duration] other 秒数とみなす
182
- # @param [その他] other 日時とみなす
183
- #
184
- # @return [When::TM::Duration] (other が Numeric, When::TM::Duration の場合)
185
- # @return [other と同じクラス] (other がその他の場合)
186
- #
187
- def +(other)
188
- case other
189
- when Duration ; Duration.new(@duration + other.duration)
190
- when Numeric ; Duration.new(@duration + other * SECOND)
191
- else ; other + self
192
- end
193
- end
194
-
195
- #
196
- # 減算
197
- #
198
- # @param [Numeric, When::TM::Duration] other 秒数とみなす
199
- #
200
- # @return [When::TM::Duration]
201
- #
202
- def -(other)
203
- Duration.new(@duration - (other.kind_of?(Duration) ? other.duration : other * SECOND))
204
- end
205
-
206
- #
207
- # 乗算
208
- #
209
- # @param [Numeric] other
210
- #
211
- # @return [When::TM::Duration]
212
- #
213
- def *(other)
214
- Duration.new(@duration * other)
215
- end
216
-
217
- #
218
- # 除算
219
- #
220
- # @param [Numeric, When::TM::Duration] other 秒数とみなす
221
- #
222
- # @return [When::TM::Duration] (other が Numeric の場合)
223
- # @return [Numeric] (other が When::TM::Duration の場合)
224
- #
225
- def /(other)
226
- other.kind_of?(Duration) ? @duration / other.duration : Duration.new(@duration / other)
227
- end
228
-
229
- #
230
- # 時間間隔を日時分秒を表すArrayに変換する
231
- #
232
- # @param [Integer] n 最下位要素のインデクス(デフォルト When::SECOND)
233
- #
234
- # @return [Array] [ 日, 時, 分, 秒 ]
235
- #
236
- def to_dhms(n=When::SECOND)
237
- a = []
238
- m = @duration
239
- n.times do |i|
240
- d, m = m.divmod(DurationUnits[i])
241
- a << d
242
- end
243
- a << m / DurationUnits[n]
244
- a
245
- end
246
-
247
- #
248
- # 時間間隔の要素を取り出す
249
- #
250
- # @param [Integer] n 要素のインデクス
251
- #
252
- # @return [Numeric] (秒は Float, その他は Integer)
253
- #
254
- def [](n)
255
- to_dhms([n+1,When::SECOND].min)[n]
256
- end
257
-
258
- #
259
- # 指定時刻よりselfの時間間隔だけ後の時刻オブジェクト
260
- #
261
- # @param [::Time, When::TM::TemporalPosition] time 指定時刻
262
- #
263
- # @return [引数と同種の時刻オブジェクト]
264
- #
265
- def after(time=Time.now)
266
- time + self
267
- end
268
- alias :since :after
269
-
270
- #
271
- # 指定時刻よりselfの時間間隔だけ前の時刻オブジェクト
272
- #
273
- # @param [::Time, When::TM::TemporalPosition] time 指定時刻
274
- #
275
- # @return [引数と同種の時刻オブジェクト]
276
- #
277
- def before(time=Time.now)
278
- time - self
279
- end
280
- alias :ago :before
281
-
282
- # When::TM::Duration オブジェクトを分かりやすい文字列にして返します
283
- #
284
- # @return [String] to_s と同様
285
- #
286
- def inspect
287
- to_s
288
- end
289
-
290
- # 文字列化
291
- #
292
- # @return [String]
293
- #
294
- def to_s
295
- to_dhms.to_s
296
- end
297
-
298
- #
299
- # When::TM::Duration への変換
300
- #
301
- # @note 必ずコピーを作る
302
- #
303
- # @return [When::TM::Duration]
304
- #
305
- def to_duration
306
- Duration.new(duration)
307
- end
308
-
309
- #
310
- # ActiveSupport::Duration への変換
311
- #
312
- # @return [ActiveSupport::Duration]
313
- #
314
- def to_as_duration
315
- [[:weeks, WEEK], [:days, DAY], [:hours, HOUR], [:minutes, MINUTE], [:seconds, SECOND]].each do |unit|
316
- div, mod = duration.divmod(unit[1])
317
- return div.send(unit[0]) if mod == 0
318
- end
319
- (duration / SECOND).seconds
320
- end
321
-
322
- # coerce
323
- # @private
324
- def coerce(other)
325
- [other, @duration]
326
- end
327
-
328
- #
329
- # Duration オブジェクトの初期化
330
- #
331
- # @param [Numeric] value Duration値 / 128秒
332
- #
333
- def initialize(value)
334
- @duration = value
335
- end
336
- end
337
- end
338
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Minimum subset - A multicultural and multilingualized calendar library based on ISO 8601, ISO 19108 and RFC 5545
4
+
5
+ Copyright (C) 2013-2015 Takashi SUGA
6
+
7
+ You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
8
+
9
+ =end
10
+
11
+ module When
12
+
13
+ # 分解能定数
14
+
15
+ CENTURY = -4
16
+ DECADE = -3
17
+ YEAR = -2
18
+ MONTH = -1
19
+ WEEK = -0.5
20
+ DAY = 0
21
+ HOUR = 1
22
+ MINUTE = 2
23
+ SECOND = 3
24
+ STRING = 5
25
+ SYSTEM = (Float::MANT_DIG*0.3).to_i
26
+
27
+ #
28
+ # (5.2) Temporal Objects Package
29
+ #
30
+ #
31
+ module TM
32
+
33
+ # 時間次元における長さ又は距離を記述するために使うデータ型
34
+ #
35
+ # see {gml schema}[link:http://schemas.opengis.net/gml/3.1.1/base/temporal.xsd#duration]
36
+ #
37
+ class Duration
38
+
39
+ # 物理的な時間間隔の定数
40
+ #
41
+ # 時間の「秒」を Float で表現して丸め誤差が発生しない範囲で、
42
+ # もっとも大きな時間間隔(86400s を 2 の因数で割りつくした値)
43
+ # を単位 SYSTEM とする
44
+ #
45
+ SYSTEM = 1.0
46
+ DAY = SYSTEM * 675
47
+ YEAR = DAY * 365.2425
48
+ MONTH = YEAR / 12
49
+ WEEK = DAY * 7
50
+ HOUR = DAY / 24
51
+ MINUTE = HOUR / 60
52
+ SECOND = MINUTE / 60
53
+
54
+ UnitName = {YEAR=>'year', MONTH =>'month', WEEK =>'week', DAY =>'day',
55
+ HOUR=>'hour', MINUTE=>'minute', SECOND=>'second', SYSTEM=>'system'}
56
+ Unit = UnitName.invert
57
+ DurationUnits = [DAY, HOUR, MINUTE, SECOND]
58
+
59
+ #
60
+ # オブジェクト生成用クラスメソッド
61
+ #
62
+ class << self
63
+ #
64
+ # 日時分秒からのオブジェクト生成
65
+ #
66
+ # @param [Array<Numeric>] value ( 日, 時, 分, 秒 ) 下位の桁は省略可
67
+ #
68
+ # @return [When::TM::Duration]
69
+ #
70
+ def dhms(*value)
71
+ units = DurationUnits.dup
72
+ Duration.new(value.inject(0) {|s,v| s + v * units.shift})
73
+ end
74
+
75
+ #
76
+ # メソッド名に相当する単位で表した value に対応する When::TM::Duration を生成する
77
+ # @method unit
78
+ # @param [Numeric] value
79
+ # @return [When::TM::Duration]
80
+ # @note unit は second, minute, hour, day, week に読み替える
81
+
82
+ # @private
83
+ Unit.keys.each do |key|
84
+ module_eval %Q{
85
+ def #{key}(value)
86
+ new(value * Unit['#{key}'])
87
+ end
88
+ }
89
+ end
90
+ end
91
+
92
+ # 時間間隔の長さ (128秒単位)
93
+ #
94
+ # @return [Numeric]
95
+ #
96
+ attr_accessor :duration
97
+
98
+ #
99
+ # メソッド名に相当する単位で表した時間間隔の大きさ
100
+ # @method unit
101
+ # @return [Numeric]
102
+ # @note unit は second, minute, hour, day, week に読み替える
103
+
104
+ # @private
105
+ Unit.keys.each do |key|
106
+ module_eval %Q{
107
+ def #{key}
108
+ duration / Unit['#{key}']
109
+ end
110
+ }
111
+ end
112
+
113
+ # 時間間隔の長さ / 秒
114
+ #
115
+ # @return [Float]
116
+ #
117
+ def to_f
118
+ duration / SECOND
119
+ end
120
+ alias :to_float :to_f
121
+
122
+ # 時間間隔の長さ / 秒
123
+ #
124
+ # @return [Integer] (四捨五入値)
125
+ #
126
+ def to_i
127
+ to_f.round
128
+ end
129
+ alias :to_int :to_i
130
+
131
+ # 符号反転
132
+ #
133
+ # @return [When::TM::Duration]
134
+ #
135
+ def -@
136
+ Duration.new(-@duration)
137
+ end
138
+
139
+ # 絶対値
140
+ #
141
+ # @return [When::TM::Duration]
142
+ #
143
+ def abs
144
+ sign >= 0 ? self.dup : -self
145
+ end
146
+
147
+ # 符号
148
+ #
149
+ # @return [Integer] 0 との比較により、負,0,正の値を返す
150
+ #
151
+ def sign
152
+ @duration <=> 0
153
+ end
154
+
155
+ # 比較
156
+ #
157
+ # @param [Numeric, When::TM::Duration] other
158
+ #
159
+ # @return [Integer] other との比較により、負,0,正の値を返す
160
+ #
161
+ def <=>(other)
162
+ self.to_f <=> other.to_f
163
+ end
164
+
165
+ # オブジェクトの同値
166
+ #
167
+ # @param [Object] other
168
+ #
169
+ # @return [Boolean]
170
+ # [ true - 同値 ]
171
+ # [ false - 非同値 ]
172
+ #
173
+ def ==(other)
174
+ return false unless other.instance_of?(self.class)
175
+ return self.duration == other.duration
176
+ end
177
+
178
+ #
179
+ # 加算
180
+ #
181
+ # @param [Numeric, When::TM::Duration] other 秒数とみなす
182
+ # @param [その他] other 日時とみなす
183
+ #
184
+ # @return [When::TM::Duration] (other が Numeric, When::TM::Duration の場合)
185
+ # @return [other と同じクラス] (other がその他の場合)
186
+ #
187
+ def +(other)
188
+ case other
189
+ when Duration ; Duration.new(@duration + other.duration)
190
+ when Numeric ; Duration.new(@duration + other * SECOND)
191
+ else ; other + self
192
+ end
193
+ end
194
+
195
+ #
196
+ # 減算
197
+ #
198
+ # @param [Numeric, When::TM::Duration] other 秒数とみなす
199
+ #
200
+ # @return [When::TM::Duration]
201
+ #
202
+ def -(other)
203
+ Duration.new(@duration - (other.kind_of?(Duration) ? other.duration : other * SECOND))
204
+ end
205
+
206
+ #
207
+ # 乗算
208
+ #
209
+ # @param [Numeric] other
210
+ #
211
+ # @return [When::TM::Duration]
212
+ #
213
+ def *(other)
214
+ Duration.new(@duration * other)
215
+ end
216
+
217
+ #
218
+ # 除算
219
+ #
220
+ # @param [Numeric, When::TM::Duration] other 秒数とみなす
221
+ #
222
+ # @return [When::TM::Duration] (other が Numeric の場合)
223
+ # @return [Numeric] (other が When::TM::Duration の場合)
224
+ #
225
+ def /(other)
226
+ other.kind_of?(Duration) ? @duration / other.duration : Duration.new(@duration / other)
227
+ end
228
+
229
+ #
230
+ # 時間間隔を日時分秒を表すArrayに変換する
231
+ #
232
+ # @param [Integer] n 最下位要素のインデクス(デフォルト When::SECOND)
233
+ #
234
+ # @return [Array] [ 日, 時, 分, 秒 ]
235
+ #
236
+ def to_dhms(n=When::SECOND)
237
+ a = []
238
+ m = @duration
239
+ n.times do |i|
240
+ d, m = m.divmod(DurationUnits[i])
241
+ a << d
242
+ end
243
+ a << m / DurationUnits[n]
244
+ a
245
+ end
246
+
247
+ #
248
+ # 時間間隔の要素を取り出す
249
+ #
250
+ # @param [Integer] n 要素のインデクス
251
+ #
252
+ # @return [Numeric] (秒は Float, その他は Integer)
253
+ #
254
+ def [](n)
255
+ to_dhms([n+1,When::SECOND].min)[n]
256
+ end
257
+
258
+ #
259
+ # 指定時刻よりselfの時間間隔だけ後の時刻オブジェクト
260
+ #
261
+ # @param [::Time, When::TM::TemporalPosition] time 指定時刻
262
+ #
263
+ # @return [引数と同種の時刻オブジェクト]
264
+ #
265
+ def after(time=Time.now)
266
+ time + self
267
+ end
268
+ alias :since :after
269
+
270
+ #
271
+ # 指定時刻よりselfの時間間隔だけ前の時刻オブジェクト
272
+ #
273
+ # @param [::Time, When::TM::TemporalPosition] time 指定時刻
274
+ #
275
+ # @return [引数と同種の時刻オブジェクト]
276
+ #
277
+ def before(time=Time.now)
278
+ time - self
279
+ end
280
+ alias :ago :before
281
+
282
+ # When::TM::Duration オブジェクトを分かりやすい文字列にして返します
283
+ #
284
+ # @return [String] to_s と同様
285
+ #
286
+ def inspect
287
+ to_s
288
+ end
289
+
290
+ # 文字列化
291
+ #
292
+ # @return [String]
293
+ #
294
+ def to_s
295
+ to_dhms.to_s
296
+ end
297
+
298
+ #
299
+ # When::TM::Duration への変換
300
+ #
301
+ # @note 必ずコピーを作る
302
+ #
303
+ # @return [When::TM::Duration]
304
+ #
305
+ def to_duration
306
+ Duration.new(duration)
307
+ end
308
+
309
+ #
310
+ # ActiveSupport::Duration への変換
311
+ #
312
+ # @return [ActiveSupport::Duration]
313
+ #
314
+ def to_as_duration
315
+ [[:weeks, WEEK], [:days, DAY], [:hours, HOUR], [:minutes, MINUTE], [:seconds, SECOND]].each do |unit|
316
+ div, mod = duration.divmod(unit[1])
317
+ return div.send(unit[0]) if mod == 0
318
+ end
319
+ (duration / SECOND).seconds
320
+ end
321
+
322
+ # coerce
323
+ # @private
324
+ def coerce(other)
325
+ [other, @duration]
326
+ end
327
+
328
+ #
329
+ # Duration オブジェクトの初期化
330
+ #
331
+ # @param [Numeric] value Duration値 / 128秒
332
+ #
333
+ def initialize(value)
334
+ @duration = value
335
+ end
336
+ end
337
+ end
338
+ end