1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------------+ |
4
|
|
|
// | This file is part of the Agavi package. | |
5
|
|
|
// | Copyright (c) 2005-2011 the Agavi Project. | |
6
|
|
|
// | | |
7
|
|
|
// | For the full copyright and license information, please view the LICENSE | |
8
|
|
|
// | file that was distributed with this source code. You can also view the | |
9
|
|
|
// | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
10
|
|
|
// | vi: set noexpandtab: | |
11
|
|
|
// | Local Variables: | |
12
|
|
|
// | indent-tabs-mode: t | |
13
|
|
|
// | End: | |
14
|
|
|
// +---------------------------------------------------------------------------+ |
15
|
|
|
|
16
|
|
|
namespace Agavi\Date; |
17
|
|
|
|
18
|
|
|
use Agavi\Translation\TranslationManager; |
19
|
|
|
use Agavi\Util\Toolkit; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Ported from ICU: |
23
|
|
|
* icu/trunk/source/i18n/simpletz.cpp r21282 |
24
|
|
|
* icu/trunk/source/i18n/unicode/simpletz.h r18762 |
25
|
|
|
* |
26
|
|
|
* @package agavi |
27
|
|
|
* @subpackage date |
28
|
|
|
* |
29
|
|
|
* @author Dominik del Bondio <[email protected]> |
30
|
|
|
* @author The ICU Project |
31
|
|
|
* @copyright Authors |
32
|
|
|
* @copyright The Agavi Project |
33
|
|
|
* |
34
|
|
|
* @since 0.11.0 |
35
|
|
|
* |
36
|
|
|
* @version $Id$ |
37
|
|
|
*/ |
38
|
|
|
class SimpleTimeZone extends TimeZone |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* TimeMode is used, together with a millisecond offset after |
42
|
|
|
* midnight, to specify a rule transition time. Most rules |
43
|
|
|
* transition at a local wall time, that is, according to the |
44
|
|
|
* current time in effect, either standard, or DST. However, some |
45
|
|
|
* rules transition at local standard time, and some at a specific |
46
|
|
|
* UTC time. Although it might seem that all times could be |
47
|
|
|
* converted to wall time, thus eliminating the need for this |
48
|
|
|
* parameter, this is not the case. |
49
|
|
|
* |
50
|
|
|
* @author Dominik del Bondio <[email protected]> |
51
|
|
|
* @author The ICU Project |
52
|
|
|
* @since 0.11.0 |
53
|
|
|
*/ |
54
|
|
|
const WALL_TIME = 0.0; |
55
|
|
|
const STANDARD_TIME = 1.0; |
56
|
|
|
const UTC_TIME = 2.0; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Returns true if the two TimeZone objects are equal; that is, they have |
60
|
|
|
* the same ID, raw GMT offset, and DST rules. |
61
|
|
|
* |
62
|
|
|
* @param TimeZone $that The SimpleTimeZone object to be compared with. |
63
|
|
|
* |
64
|
|
|
* @return bool True if the given time zone is equal to this time zone; |
65
|
|
|
* false otherwise. |
66
|
|
|
* |
67
|
|
|
* @author Dominik del Bondio <[email protected]> |
68
|
|
|
* @author The ICU Project |
69
|
|
|
* @since 0.11.0 |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
function __is_equal(TimeZone $that) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
return ($this === $that || |
74
|
|
|
(get_class($this) == get_class($that) && |
75
|
|
|
TimeZone::__is_equal($that) && |
76
|
|
|
$this->hasSameRules($that) |
77
|
|
|
)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Overloaded. |
82
|
|
|
* |
83
|
|
|
* @see SimpleTimeZone::constructorOIS() |
84
|
|
|
* @see SimpleTimeZone::constructorOISIIIIIIII() |
85
|
|
|
* @see SimpleTimeZone::constructorOISIIIIIIIII() |
86
|
|
|
* @see SimpleTimeZone::constructorOISIIIIIIIIIII() |
87
|
|
|
* |
88
|
|
|
* @author Dominik del Bondio <[email protected]> |
89
|
|
|
* @author The ICU Project |
90
|
|
|
* @since 0.11.0 |
91
|
|
|
*/ |
92
|
|
|
public function __construct() |
93
|
|
|
{ |
94
|
|
|
$arguments = func_get_args(); |
95
|
|
|
if (count($arguments) == 1) { |
96
|
|
|
$arguments[1] = 0; |
97
|
|
|
$arguments[2] = ''; |
98
|
|
|
} |
99
|
|
|
if (count($arguments) == 2) { |
100
|
|
|
$arguments[2] = ''; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$fName = Toolkit::overloadHelper(array( |
104
|
|
|
array('name' => 'constructorOIS', |
105
|
|
|
'parameters' => array('object', 'int', 'string')), |
106
|
|
|
array('name' => 'constructorOISIIIIIIII', |
107
|
|
|
'parameters' => array('object', 'int', 'string', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int')), |
108
|
|
|
array('name' => 'constructorOISIIIIIIIII', |
109
|
|
|
'parameters' => array('object', 'int', 'string', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int')), |
110
|
|
|
array('name' => 'constructorOISIIIIIIIIIII', |
111
|
|
|
'parameters' => array('object', 'int', 'string', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int', 'int')), |
112
|
|
|
), |
113
|
|
|
$arguments |
114
|
|
|
); |
115
|
|
|
call_user_func_array(array($this, $fName), $arguments); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Constructs a SimpleTimeZone with the given raw GMT offset and time zone ID, |
120
|
|
|
* and which doesn't observe daylight savings time. Normally you should use |
121
|
|
|
* TimeZone::createInstance() to create a TimeZone instead of creating a |
122
|
|
|
* SimpleTimeZone directly with this constructor. |
123
|
|
|
* |
124
|
|
|
* @param TranslationManager $tm The translation Manager |
125
|
|
|
* @param int $rawOffsetGMT The given base time zone offset to GMT. |
126
|
|
|
* @param string $id The timezone ID which is obtained from |
127
|
|
|
* TimeZone.getAvailableIDs. |
128
|
|
|
* |
129
|
|
|
* @author Dominik del Bondio <[email protected]> |
130
|
|
|
* @author The ICU Project |
131
|
|
|
* @since 0.11.0 |
132
|
|
|
*/ |
133
|
|
|
protected function constructorOIS(TranslationManager $tm, $rawOffsetGMT, $id) |
134
|
|
|
{ |
135
|
|
|
parent::__construct($tm, $id); |
|
|
|
|
136
|
|
|
$this->startMonth = 0; |
137
|
|
|
$this->startDay = 0; |
138
|
|
|
$this->startDayOfWeek = 0; |
139
|
|
|
$this->startTime = 0; |
140
|
|
|
$this->startTimeMode = self::WALL_TIME; |
141
|
|
|
$this->endTimeMode = self::WALL_TIME; |
142
|
|
|
$this->endMonth = 0; |
143
|
|
|
$this->endDay = 0; |
144
|
|
|
$this->endDayOfWeek = 0; |
145
|
|
|
$this->endTime = 0; |
146
|
|
|
$this->startYear = 0; |
147
|
|
|
$this->rawOffset = $rawOffsetGMT; |
148
|
|
|
$this->useDaylight = false; |
149
|
|
|
$this->startMode = self::DOM_MODE; |
150
|
|
|
$this->endMode = self::DOM_MODE; |
151
|
|
|
$this->dstSavings = DateDefinitions::MILLIS_PER_HOUR; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, |
156
|
|
|
* and times to start and end daylight savings time. To create a TimeZone that |
157
|
|
|
* doesn't observe daylight savings time, don't use this constructor; use |
158
|
|
|
* SimpleTimeZone(rawOffset, ID) instead. Normally, you should use |
159
|
|
|
* TranslationManager->createTimeZone() to create a TimeZone instead of |
160
|
|
|
* creating a SimpleTimeZone directly with this constructor. |
161
|
|
|
* <P> |
162
|
|
|
* Various types of daylight-savings time rules can be specified by using |
163
|
|
|
* different values for startDay and startDayOfWeek and endDay and |
164
|
|
|
* endDayOfWeek. For a complete explanation of how these parameters work, |
165
|
|
|
* see the documentation for setStartRule(). |
166
|
|
|
* |
167
|
|
|
* @param TranslationManager $tm The translation Manager |
168
|
|
|
* @param int $rawOffsetGMT The new SimpleTimeZone's raw GMT offset |
169
|
|
|
* @param string $id The new SimpleTimeZone's time zone ID. |
170
|
|
|
* @param int $savingsStartMonth The daylight savings starting month. Month is |
171
|
|
|
* 0-based. eg, 0 for January. |
172
|
|
|
* @param int $savingsStartDay The daylight savings starting |
173
|
|
|
* day-of-week-in-month. See setStartRule() for a complete explanation. |
174
|
|
|
* @param int $savingsStartDayOfWeek The daylight savings starting day-of-week. |
175
|
|
|
* See setStartRule() for a complete explanation. |
176
|
|
|
* @param int $savingsStartTime The daylight savings starting time, expressed as the |
177
|
|
|
* number of milliseconds after midnight. |
178
|
|
|
* @param int $savingsEndMonth The daylight savings ending month. Month is |
179
|
|
|
* 0-based. eg, 0 for January. |
180
|
|
|
* @param int $savingsEndDay The daylight savings ending day-of-week-in-month. |
181
|
|
|
* See setStartRule() for a complete explanation. |
182
|
|
|
* @param int $savingsEndDayOfWeek The daylight savings ending day-of-week. |
183
|
|
|
* See setStartRule() for a complete explanation. |
184
|
|
|
* @param int $savingsEndTime The daylight savings ending time, expressed as the |
185
|
|
|
* number of milliseconds after midnight. |
186
|
|
|
* |
187
|
|
|
* @author Dominik del Bondio <[email protected]> |
188
|
|
|
* @author The ICU Project |
189
|
|
|
* @since 0.11.0 |
190
|
|
|
*/ |
191
|
|
|
protected function constructorOISIIIIIIII(TranslationManager $tm, $rawOffsetGMT, $id, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime) |
192
|
|
|
{ |
193
|
|
|
parent::__construct($tm, $id); |
|
|
|
|
194
|
|
|
$this->construct($rawOffsetGMT, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, self::WALL_TIME, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime, self::WALL_TIME, DateDefinitions::MILLIS_PER_HOUR); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, |
199
|
|
|
* and times to start and end daylight savings time. To create a TimeZone that |
200
|
|
|
* doesn't observe daylight savings time, don't use this constructor; use |
201
|
|
|
* SimpleTimeZone(rawOffset, ID) instead. Normally, you should use |
202
|
|
|
* TimeZone.createInstance() to create a TimeZone instead of creating a |
203
|
|
|
* SimpleTimeZone directly with this constructor. |
204
|
|
|
* <P> |
205
|
|
|
* Various types of daylight-savings time rules can be specified by using |
206
|
|
|
* different values for startDay and startDayOfWeek and endDay and |
207
|
|
|
* endDayOfWeek. For a complete explanation of how these parameters work, see |
208
|
|
|
* the documentation for setStartRule(). |
209
|
|
|
* |
210
|
|
|
* @param TranslationManager $tm The translation Manager |
211
|
|
|
* @param int $rawOffsetGMT The new SimpleTimeZone's raw GMT offset |
212
|
|
|
* @param string $id The new SimpleTimeZone's time zone ID. |
213
|
|
|
* @param int $savingsStartMonth The daylight savings starting month. Month is |
214
|
|
|
* 0-based. eg, 0 for January. |
215
|
|
|
* @param int $savingsStartDay The daylight savings starting |
216
|
|
|
* day-of-week-in-month. See setStartRule() for a |
217
|
|
|
* complete explanation. |
218
|
|
|
* @param int $savingsStartDayOfWeek The daylight savings starting day-of-week. |
219
|
|
|
* See setStartRule() for a complete explanation. |
220
|
|
|
* @param int $savingsStartTime The daylight savings starting time, expressed as the |
221
|
|
|
* number of milliseconds after midnight. |
222
|
|
|
* @param int $savingsEndMonth The daylight savings ending month. Month is |
223
|
|
|
* 0-based. eg, 0 for January. |
224
|
|
|
* @param int $savingsEndDay The daylight savings ending day-of-week-in-month. |
225
|
|
|
* See setStartRule() for a complete explanation. |
226
|
|
|
* @param int $savingsEndDayOfWeek The daylight savings ending day-of-week. |
227
|
|
|
* See setStartRule() for a complete explanation. |
228
|
|
|
* @param int $savingsEndTime The daylight savings ending time, expressed as the |
229
|
|
|
* number of milliseconds after midnight. |
230
|
|
|
* @param int $savingsDST The number of milliseconds added to standard time |
231
|
|
|
* to get DST time. Default is one hour. |
232
|
|
|
* |
233
|
|
|
* @author Dominik del Bondio <[email protected]> |
234
|
|
|
* @author The ICU Project |
235
|
|
|
* @since 0.11.0 |
236
|
|
|
*/ |
237
|
|
|
protected function constructorOISIIIIIIIII(TranslationManager $tm, $rawOffsetGMT, $id, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime, $savingsDST) |
238
|
|
|
{ |
239
|
|
|
parent::__construct($tm, $id); |
|
|
|
|
240
|
|
|
$this->construct($rawOffsetGMT, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, self::WALL_TIME, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime, self::WALL_TIME, $savingsDST); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Construct a SimpleTimeZone with the given raw GMT offset, time zone ID, |
245
|
|
|
* and times to start and end daylight savings time. To create a TimeZone that |
246
|
|
|
* doesn't observe daylight savings time, don't use this constructor; use |
247
|
|
|
* SimpleTimeZone(rawOffset, ID) instead. Normally, you should use |
248
|
|
|
* TimeZone.createInstance() to create a TimeZone instead of creating a |
249
|
|
|
* SimpleTimeZone directly with this constructor. |
250
|
|
|
* <P> |
251
|
|
|
* Various types of daylight-savings time rules can be specified by using |
252
|
|
|
* different values for startDay and startDayOfWeek and endDay and |
253
|
|
|
* endDayOfWeek. For a complete explanation of how these parameters work, see |
254
|
|
|
* the documentation for setStartRule(). |
255
|
|
|
* |
256
|
|
|
* @param TranslationManager $tm The translation Manager |
257
|
|
|
* @param int $rawOffsetGMT The new SimpleTimeZone's raw GMT offset |
258
|
|
|
* @param string $id The new SimpleTimeZone's time zone ID. |
259
|
|
|
* @param int $savingsStartMonth The daylight savings starting month. Month is |
260
|
|
|
* 0-based. eg, 0 for January. |
261
|
|
|
* @param int $savingsStartDay The daylight savings starting |
262
|
|
|
* day-of-week-in-month. See setStartRule() for a |
263
|
|
|
* complete explanation. |
264
|
|
|
* @param int $savingsStartDayOfWeek The daylight savings starting day-of-week. |
265
|
|
|
* See setStartRule() for a complete explanation. |
266
|
|
|
* @param int $savingsStartTime The daylight savings starting time, expressed as the |
267
|
|
|
* number of milliseconds after midnight. |
268
|
|
|
* @param int $savingsStartTimeMode Whether the start time is local wall time, local |
269
|
|
|
* standard time, or UTC time. Default is local wall time. |
270
|
|
|
* @param int $savingsEndMonth The daylight savings ending month. Month is |
271
|
|
|
* 0-based. eg, 0 for January. |
272
|
|
|
* @param int $savingsEndDay The daylight savings ending day-of-week-in-month. |
273
|
|
|
* See setStartRule() for a complete explanation. |
274
|
|
|
* @param int $savingsEndDayOfWeek The daylight savings ending day-of-week. |
275
|
|
|
* See setStartRule() for a complete explanation. |
276
|
|
|
* @param int $savingsEndTime The daylight savings ending time, expressed as the |
277
|
|
|
* number of milliseconds after midnight. |
278
|
|
|
* @param int $savingsEndTimeMode Whether the end time is local wall time, local |
279
|
|
|
* standard time, or UTC time. Default is local wall time. |
280
|
|
|
* @param int $savingsDST The number of milliseconds added to standard time |
281
|
|
|
* to get DST time. Default is one hour. |
282
|
|
|
* |
283
|
|
|
* @author Dominik del Bondio <[email protected]> |
284
|
|
|
* @author The ICU Project |
285
|
|
|
* @since 0.11.0 |
286
|
|
|
*/ |
287
|
|
|
protected function constructorOISIIIIIIIIIII(TranslationManager $tm, $rawOffsetGMT, $id, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, $savingsStartTimeMode, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime, $savingsEndTimeMode, $savingsDST) |
288
|
|
|
{ |
289
|
|
|
parent::__construct($tm, $id); |
|
|
|
|
290
|
|
|
$this->construct($rawOffsetGMT, $savingsStartMonth, $savingsStartDay, $savingsStartDayOfWeek, $savingsStartTime, $savingsStartTimeMode, $savingsEndMonth, $savingsEndDay, $savingsEndDayOfWeek, $savingsEndTime, $savingsEndTimeMode, $savingsDST); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Sets the daylight savings starting year, that is, the year this time zone |
295
|
|
|
* began observing its specified daylight savings time rules. The time zone |
296
|
|
|
* is considered not to observe daylight savings time prior to that year; |
297
|
|
|
* SimpleTimeZone doesn't support historical daylight-savings-time rules. |
298
|
|
|
* |
299
|
|
|
* @param int $year The daylight savings starting year. |
300
|
|
|
* |
301
|
|
|
* @author Dominik del Bondio <[email protected]> |
302
|
|
|
* @author The ICU Project |
303
|
|
|
* @since 0.11.0 |
304
|
|
|
*/ |
305
|
|
|
public function setStartYear($year) |
306
|
|
|
{ |
307
|
|
|
$this->startYear = $year; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Overloaded. |
312
|
|
|
* |
313
|
|
|
* @see AgaviSimpleTimeZone::setStartRuleIIII() |
314
|
|
|
* @see AgaviSimpleTimeZone::setStartRuleIIIIF() |
315
|
|
|
* @see AgaviSimpleTimeZone::setStartRuleIII() |
316
|
|
|
* @see AgaviSimpleTimeZone::setStartRuleIIIF() |
317
|
|
|
* @see AgaviSimpleTimeZone::setStartRuleIIIIB() |
318
|
|
|
* @see AgaviSimpleTimeZone::setStartRuleIIIIFB() |
319
|
|
|
* |
320
|
|
|
* @author Dominik del Bondio <[email protected]> |
321
|
|
|
* @author The ICU Project |
322
|
|
|
* @since 0.11.0 |
323
|
|
|
*/ |
324
|
|
View Code Duplication |
public function setStartRule() |
|
|
|
|
325
|
|
|
{ |
326
|
|
|
$arguments = func_get_args(); |
327
|
|
|
$fName = Toolkit::overloadHelper(array( |
328
|
|
|
array('name' => 'setStartRuleIIII', |
329
|
|
|
'parameters' => array('int', 'int', 'int', 'int')), |
330
|
|
|
array('name' => 'setStartRuleIIIIF', |
331
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'double')), |
332
|
|
|
array('name' => 'setStartRuleIII', |
333
|
|
|
'parameters' => array('int', 'int', 'int')), |
334
|
|
|
array('name' => 'setStartRuleIIIF', |
335
|
|
|
'parameters' => array('int', 'int', 'int', 'double')), |
336
|
|
|
array('name' => 'setStartRuleIIIIB', |
337
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'bool')), |
338
|
|
|
array('name' => 'setStartRuleIIIIFB', |
339
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'float', 'bool')), |
340
|
|
|
), |
341
|
|
|
$arguments |
342
|
|
|
); |
343
|
|
|
call_user_func_array(array($this, $fName), $arguments); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Sets the daylight savings starting rule. For example, in the U.S., Daylight |
348
|
|
|
* Savings Time starts at the first Sunday in April, at 2 AM in standard time. |
349
|
|
|
* Therefore, you can set the start rule by calling: |
350
|
|
|
* <code> |
351
|
|
|
* setStartRule(DateDefinitions::APRIL, 1, DateDefinitions::SUNDAY, |
352
|
|
|
* 2*60*60*1000); |
353
|
|
|
* </code> |
354
|
|
|
* The dayOfWeekInMonth and dayOfWeek parameters together specify how to |
355
|
|
|
* calculate the exact starting date. Their exact meaning depend on their |
356
|
|
|
* respective signs, allowing various types of rules to be constructed, as |
357
|
|
|
* follows: |
358
|
|
|
* <ul> |
359
|
|
|
* <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the |
360
|
|
|
* day of week in the month (e.g., (2, WEDNESDAY) is the second |
361
|
|
|
* Wednesday of the month). |
362
|
|
|
* </li> |
363
|
|
|
* <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they |
364
|
|
|
* specify the day of week in the month counting backward from the end |
365
|
|
|
* of the month. (e.g., (-1, MONDAY) is the last Monday in the month) |
366
|
|
|
* </li> |
367
|
|
|
* <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, |
368
|
|
|
* dayOfWeekInMonth specifies the day of the month, regardless of what |
369
|
|
|
* day of the week it is. (e.g., (10, 0) is the tenth day of the month) |
370
|
|
|
* </li> |
371
|
|
|
* <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, |
372
|
|
|
* dayOfWeekInMonth specifies the day of the month counting backward |
373
|
|
|
* from the end of the month, regardless of what day of the week it is |
374
|
|
|
* (e.g., (-2, 0) is the next-to-last day of the month). |
375
|
|
|
* </li> |
376
|
|
|
* <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they |
377
|
|
|
* specify the first specified day of the week on or after the specified |
378
|
|
|
* day of the month. (e.g., (15, -SUNDAY) is the first Sunday after the |
379
|
|
|
* 15th of the month [or the 15th itself if the 15th is a Sunday].) |
380
|
|
|
* </li> |
381
|
|
|
* <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the |
382
|
|
|
* last specified day of the week on or before the specified day of the |
383
|
|
|
* month. (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of |
384
|
|
|
* the month [or the 20th itself if the 20th is a Tuesday].) |
385
|
|
|
* </li> |
386
|
|
|
* </ul> |
387
|
|
|
* |
388
|
|
|
* @param int $month The daylight savings starting month. Month is 0-based. |
389
|
|
|
* eg, 0 for January. |
390
|
|
|
* @param int $dayOfWeekInMonth The daylight savings starting day-of-week-in-month. Please |
391
|
|
|
* see the member description for an example. |
392
|
|
|
* @param int $dayOfWeek The daylight savings starting day-of-week. Please see |
393
|
|
|
* the member description for an example. |
394
|
|
|
* @param int $time The daylight savings starting time. Please see the member |
395
|
|
|
* description for an example. |
396
|
|
|
* |
397
|
|
|
* @author Dominik del Bondio <[email protected]> |
398
|
|
|
* @author The ICU Project |
399
|
|
|
* @since 0.11.0 |
400
|
|
|
*/ |
401
|
|
|
public function setStartRuleIIII($month, $dayOfWeekInMonth, $dayOfWeek, $time) |
402
|
|
|
{ |
403
|
|
|
$this->setStartRuleIIIIF($month, $dayOfWeekInMonth, $dayOfWeek, $time, self::WALL_TIME); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Sets the daylight savings starting rule. For example, in the U.S., Daylight |
408
|
|
|
* Savings Time starts at the first Sunday in April, at 2 AM in standard time. |
409
|
|
|
* Therefore, you can set the start rule by calling: |
410
|
|
|
* setStartRule(TimeFields.APRIL, 1, TimeFields.SUNDAY, 2*60*60*1000); |
411
|
|
|
* The dayOfWeekInMonth and dayOfWeek parameters together specify how to |
412
|
|
|
* calculate the exact starting date. Their exact meaning depend on their |
413
|
|
|
* respective signs, allowing various types of rules to be constructed, as |
414
|
|
|
* follows: |
415
|
|
|
* <ul> |
416
|
|
|
* <li>If both dayOfWeekInMonth and dayOfWeek are positive, they specify the |
417
|
|
|
* day of week in the month (e.g., (2, WEDNESDAY) is the second |
418
|
|
|
* Wednesday of the month). |
419
|
|
|
* </li> |
420
|
|
|
* <li>If dayOfWeek is positive and dayOfWeekInMonth is negative, they |
421
|
|
|
* specify the day of week in the month counting backward from the end |
422
|
|
|
* of the month. (e.g., (-1, MONDAY) is the last Monday in the month) |
423
|
|
|
* </li> |
424
|
|
|
* <li>If dayOfWeek is zero and dayOfWeekInMonth is positive, |
425
|
|
|
* dayOfWeekInMonth specifies the day of the month, regardless of what |
426
|
|
|
* day of the week it is. (e.g., (10, 0) is the tenth day of the month) |
427
|
|
|
* </li> |
428
|
|
|
* <li>If dayOfWeek is zero and dayOfWeekInMonth is negative, |
429
|
|
|
* dayOfWeekInMonth specifies the day of the month counting backward |
430
|
|
|
* from the end of the month, regardless of what day of the week it is |
431
|
|
|
* (e.g., (-2, 0) is the next-to-last day of the month). |
432
|
|
|
* </li> |
433
|
|
|
* <li>If dayOfWeek is negative and dayOfWeekInMonth is positive, they |
434
|
|
|
* specify the first specified day of the week on or after the specified |
435
|
|
|
* day of the month. (e.g., (15, -SUNDAY) is the first Sunday after the |
436
|
|
|
* 15th of the month [or the 15th itself if the 15th is a Sunday].) |
437
|
|
|
* </li> |
438
|
|
|
* <li>If dayOfWeek and DayOfWeekInMonth are both negative, they specify the |
439
|
|
|
* last specified day of the week on or before the specified day of the |
440
|
|
|
* month. (e.g., (-20, -TUESDAY) is the last Tuesday before the 20th of |
441
|
|
|
* the month [or the 20th itself if the 20th is a Tuesday].) |
442
|
|
|
* </li> |
443
|
|
|
* </ul> |
444
|
|
|
* |
445
|
|
|
* @param int $month The daylight savings starting month. Month is 0-based. |
446
|
|
|
* eg, 0 for January. |
447
|
|
|
* @param int $dayOfWeekInMonth The daylight savings starting day-of-week-in-month. |
448
|
|
|
* Please see the member description for an example. |
449
|
|
|
* @param int $dayOfWeek The daylight savings starting day-of-week. Please see |
450
|
|
|
* the member description for an example. |
451
|
|
|
* @param int $time The daylight savings starting time. Please see the member |
452
|
|
|
* description for an example. |
453
|
|
|
* @param float $month Whether the time is local wall time, local standard time, |
454
|
|
|
* or UTC time. Default is local wall time. |
455
|
|
|
* |
456
|
|
|
* @author Dominik del Bondio <[email protected]> |
457
|
|
|
* @author The ICU Project |
458
|
|
|
* @since 0.11.0 |
459
|
|
|
*/ |
460
|
|
|
public function setStartRuleIIIIF($month, $dayOfWeekInMonth, $dayOfWeek, $time, $mode) |
461
|
|
|
{ |
462
|
|
|
$this->startMonth = $month; |
463
|
|
|
$this->startDay = $dayOfWeekInMonth; |
464
|
|
|
$this->startDayOfWeek = $dayOfWeek; |
465
|
|
|
$this->startTime = $time; |
466
|
|
|
$this->startTimeMode = $mode; |
467
|
|
|
$this->decodeStartRule(); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Sets the DST start rule to a fixed date within a month. |
472
|
|
|
* |
473
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
474
|
|
|
* @param int $dayOfMonth The date in that month (1-based). |
475
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
476
|
|
|
* when DST takes effect in local wall time, which is |
477
|
|
|
* standard time in this case. |
478
|
|
|
* |
479
|
|
|
* @author Dominik del Bondio <[email protected]> |
480
|
|
|
* @author The ICU Project |
481
|
|
|
* @since 0.11.0 |
482
|
|
|
*/ |
483
|
|
|
public function setStartRuleIII($month, $dayOfMonth, $time) |
484
|
|
|
{ |
485
|
|
|
$this->setStartRuleIIIF($month, $dayOfMonth, $time, self::WALL_TIME); |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
/** |
489
|
|
|
* Sets the DST start rule to a fixed date within a month. |
490
|
|
|
* |
491
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
492
|
|
|
* @param int $dayOfMonth The date in that month (1-based). |
493
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
494
|
|
|
* when DST takes effect in local wall time, which is |
495
|
|
|
* standard time in this case. |
496
|
|
|
* @param float $mode Whether the time is local wall time, local standard time, |
497
|
|
|
* or UTC time. Default is local wall time. |
498
|
|
|
* |
499
|
|
|
* @author Dominik del Bondio <[email protected]> |
500
|
|
|
* @author The ICU Project |
501
|
|
|
* @since 0.11.0 |
502
|
|
|
*/ |
503
|
|
|
public function setStartRuleIIIF($month, $dayOfMonth, $time, $mode) |
504
|
|
|
{ |
505
|
|
|
$this->setStartRuleIIIIF($month, $dayOfMonth, 0, $time, $mode); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* Sets the DST start rule to a weekday before or after a give date within |
510
|
|
|
* a month, e.g., the first Monday on or after the 8th. |
511
|
|
|
* |
512
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
513
|
|
|
* @param int $dayOfMonth A date within that month (1-based). |
514
|
|
|
* @param int $dayOfWeek The day of the week on which this rule occurs. |
515
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
516
|
|
|
* when DST takes effect in local wall time, which is |
517
|
|
|
* standard time in this case. |
518
|
|
|
* @param bool $after If true, this rule selects the first dayOfWeek on |
519
|
|
|
* or after dayOfMonth. If false, this rule selects |
520
|
|
|
* the last dayOfWeek on or before dayOfMonth. |
521
|
|
|
* |
522
|
|
|
* @author Dominik del Bondio <[email protected]> |
523
|
|
|
* @author The ICU Project |
524
|
|
|
* @since 0.11.0 |
525
|
|
|
*/ |
526
|
|
|
public function setStartRuleIIIIB($month, $dayOfMonth, $dayOfWeek, $time, $after) |
527
|
|
|
{ |
528
|
|
|
$this->setStartRuleIIIIFB($month, $dayOfMonth, $dayOfWeek, $time, self::WALL_TIME, $after); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
/** |
532
|
|
|
* Sets the DST start rule to a weekday before or after a give date within |
533
|
|
|
* a month, e.g., the first Monday on or after the 8th. |
534
|
|
|
* |
535
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
536
|
|
|
* @param int $dayOfMonth A date within that month (1-based). |
537
|
|
|
* @param int $dayOfWeek The day of the week on which this rule occurs. |
538
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
539
|
|
|
* when DST takes effect in local wall time, which is |
540
|
|
|
* standard time in this case. |
541
|
|
|
* @param float $mode Whether the time is local wall time, local standard time, |
542
|
|
|
* or UTC time. Default is local wall time. |
543
|
|
|
* @param bool $after If true, this rule selects the first dayOfWeek on |
544
|
|
|
* or after dayOfMonth. If false, this rule selects |
545
|
|
|
* the last dayOfWeek on or before dayOfMonth. |
546
|
|
|
* |
547
|
|
|
* @author Dominik del Bondio <[email protected]> |
548
|
|
|
* @author The ICU Project |
549
|
|
|
* @since 0.11.0 |
550
|
|
|
*/ |
551
|
|
|
public function setStartRuleIIIIFB($month, $dayOfMonth, $dayOfWeek, $time, $mode, $after) |
552
|
|
|
{ |
553
|
|
|
$this->setStartRuleIIIIF($month, $after ? $dayOfMonth : -$dayOfMonth, -$dayOfWeek, $time, $mode); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
/** |
557
|
|
|
* Overloaded. |
558
|
|
|
* |
559
|
|
|
* @see AgaviSimpleTimeZone::setEndRuleIIII() |
560
|
|
|
* @see AgaviSimpleTimeZone::setEndRuleIIIIF() |
561
|
|
|
* @see AgaviSimpleTimeZone::setEndRuleIII() |
562
|
|
|
* @see AgaviSimpleTimeZone::setEndRuleIIIF() |
563
|
|
|
* @see AgaviSimpleTimeZone::setEndRuleIIIIB() |
564
|
|
|
* @see AgaviSimpleTimeZone::setEndRuleIIIIFB() |
565
|
|
|
* |
566
|
|
|
* @author Dominik del Bondio <[email protected]> |
567
|
|
|
* @author The ICU Project |
568
|
|
|
* @since 0.11.0 |
569
|
|
|
*/ |
570
|
|
View Code Duplication |
public function setEndRule() |
|
|
|
|
571
|
|
|
{ |
572
|
|
|
$arguments = func_get_args(); |
573
|
|
|
$fName = Toolkit::overloadHelper(array( |
574
|
|
|
array('name' => 'setEndRuleIIII', |
575
|
|
|
'parameters' => array('int', 'int', 'int', 'int')), |
576
|
|
|
array('name' => 'setEndRuleIIIIF', |
577
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'double')), |
578
|
|
|
array('name' => 'setEndRuleIII', |
579
|
|
|
'parameters' => array('int', 'int', 'int')), |
580
|
|
|
array('name' => 'setEndRuleIIIF', |
581
|
|
|
'parameters' => array('int', 'int', 'int', 'double')), |
582
|
|
|
array('name' => 'setEndRuleIIIIB', |
583
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'bool')), |
584
|
|
|
array('name' => 'setEndRuleIIIIFB', |
585
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'float', 'bool')), |
586
|
|
|
), |
587
|
|
|
$arguments |
588
|
|
|
); |
589
|
|
|
call_user_func_array(array($this, $fName), $arguments); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* Sets the daylight savings ending rule. For example, in the U.S., Daylight |
594
|
|
|
* Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard |
595
|
|
|
* time. |
596
|
|
|
* Therefore, you can set the end rule by calling: |
597
|
|
|
* <pre> |
598
|
|
|
* . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000); |
599
|
|
|
* </pre> |
600
|
|
|
* Various other types of rules can be specified by manipulating the dayOfWeek |
601
|
|
|
* and dayOfWeekInMonth parameters. For complete details, see the |
602
|
|
|
* documentation for setStartRule(). |
603
|
|
|
* |
604
|
|
|
* @param int $month The daylight savings ending month. Month is 0-based. |
605
|
|
|
* eg, 0 for January. |
606
|
|
|
* @param int $dayOfWeekInMonth The daylight savings ending day-of-week-in-month. |
607
|
|
|
* See setStartRule() for a complete explanation. |
608
|
|
|
* @param int $dayOfWeek The daylight savings ending day-of-week. See setStartRule() |
609
|
|
|
* for a complete explanation. |
610
|
|
|
* @param int $time The daylight savings ending time. Please see the member |
611
|
|
|
* description for an example. |
612
|
|
|
* |
613
|
|
|
* @author Dominik del Bondio <[email protected]> |
614
|
|
|
* @author The ICU Project |
615
|
|
|
* @since 0.11.0 |
616
|
|
|
*/ |
617
|
|
|
public function setEndRuleIIII($month, $dayOfWeekInMonth, $dayOfWeek, $time) |
618
|
|
|
{ |
619
|
|
|
$this->setEndRuleIIIIF($month, $dayOfWeekInMonth, $dayOfWeek, $time, self::WALL_TIME); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
/** |
623
|
|
|
* Sets the daylight savings ending rule. For example, in the U.S., Daylight |
624
|
|
|
* Savings Time ends at the last (-1) Sunday in October, at 2 AM in standard |
625
|
|
|
* time. |
626
|
|
|
* Therefore, you can set the end rule by calling: |
627
|
|
|
* <pre> |
628
|
|
|
* . setEndRule(TimeFields.OCTOBER, -1, TimeFields.SUNDAY, 2*60*60*1000); |
629
|
|
|
* </pre> |
630
|
|
|
* Various other types of rules can be specified by manipulating the dayOfWeek |
631
|
|
|
* and dayOfWeekInMonth parameters. For complete details, see the |
632
|
|
|
* documentation for setStartRule(). |
633
|
|
|
* |
634
|
|
|
* @param int $month The daylight savings ending month. Month is 0-based. |
635
|
|
|
* eg, 0 for January. |
636
|
|
|
* @param int $dayOfWeekInMonth The daylight savings ending day-of-week-in-month. |
637
|
|
|
* See setStartRule() for a complete explanation. |
638
|
|
|
* @param int $dayOfWeek The daylight savings ending day-of-week. See setStartRule() |
639
|
|
|
* for a complete explanation. |
640
|
|
|
* @param int $time The daylight savings ending time. Please see the member |
641
|
|
|
* description for an example. |
642
|
|
|
* @param float $mode Whether the time is local wall time, local standard time, |
643
|
|
|
* or UTC time. Default is local wall time. |
644
|
|
|
* |
645
|
|
|
* @author Dominik del Bondio <[email protected]> |
646
|
|
|
* @author The ICU Project |
647
|
|
|
* @since 0.11.0 |
648
|
|
|
*/ |
649
|
|
|
public function setEndRuleIIIIF($month, $dayOfWeekInMonth, $dayOfWeek, $time, $mode) |
650
|
|
|
{ |
651
|
|
|
$this->endMonth = $month; |
652
|
|
|
$this->endDay = $dayOfWeekInMonth; |
653
|
|
|
$this->endDayOfWeek = $dayOfWeek; |
654
|
|
|
$this->endTime = $time; |
655
|
|
|
$this->endTimeMode = $mode; |
656
|
|
|
$this->decodeEndRule(); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
/** |
660
|
|
|
* Sets the DST end rule to a fixed date within a month. |
661
|
|
|
* |
662
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
663
|
|
|
* @param int $dayOfMonth The date in that month (1-based). |
664
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
665
|
|
|
* when DST ends in local wall time, which is daylight |
666
|
|
|
* time in this case. |
667
|
|
|
* |
668
|
|
|
* @author Dominik del Bondio <[email protected]> |
669
|
|
|
* @author The ICU Project |
670
|
|
|
* @since 0.11.0 |
671
|
|
|
*/ |
672
|
|
|
public function setEndRuleIII($month, $dayOfMonth, $time) |
673
|
|
|
{ |
674
|
|
|
$this->setEndRuleIIIF($month, $dayOfMonth, $time, self::WALL_TIME); |
675
|
|
|
} |
676
|
|
|
|
677
|
|
|
/** |
678
|
|
|
* Sets the DST end rule to a fixed date within a month. |
679
|
|
|
* |
680
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
681
|
|
|
* @param int $dayOfMonth The date in that month (1-based). |
682
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
683
|
|
|
* when DST ends in local wall time, which is daylight |
684
|
|
|
* time in this case. |
685
|
|
|
* @param float $mode Whether the time is local wall time, local standard time, |
686
|
|
|
* or UTC time. Default is local wall time. |
687
|
|
|
* |
688
|
|
|
* @author Dominik del Bondio <[email protected]> |
689
|
|
|
* @author The ICU Project |
690
|
|
|
* @since 0.11.0 |
691
|
|
|
*/ |
692
|
|
|
public function setEndRuleIIIF($month, $dayOfMonth, $time, $mode) |
693
|
|
|
{ |
694
|
|
|
$this->setEndRuleIIIIF($month, $dayOfMonth, 0, $time, $mode); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* Sets the DST end rule to a weekday before or after a give date within |
699
|
|
|
* a month, e.g., the first Monday on or after the 8th. |
700
|
|
|
* |
701
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
702
|
|
|
* @param int $dayOfMonth A date within that month (1-based). |
703
|
|
|
* @param int $dayOfWeek The day of the week on which this rule occurs. |
704
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
705
|
|
|
* when DST ends in local wall time, which is daylight |
706
|
|
|
* time in this case. |
707
|
|
|
* @param bool $after If true, this rule selects the first dayOfWeek on |
708
|
|
|
* or after dayOfMonth. If false, this rule selects |
709
|
|
|
* the last dayOfWeek on or before dayOfMonth. |
710
|
|
|
* |
711
|
|
|
* @author Dominik del Bondio <[email protected]> |
712
|
|
|
* @author The ICU Project |
713
|
|
|
* @since 0.11.0 |
714
|
|
|
*/ |
715
|
|
|
public function setEndRuleIIIIB($month, $dayOfMonth, $dayOfWeek, $time, $after) |
716
|
|
|
{ |
717
|
|
|
$this->setEndRuleIIIIFB($month, $dayOfMonth, $dayOfWeek, $time, self::WALL_TIME, $after); |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
/** |
721
|
|
|
* Sets the DST end rule to a weekday before or after a give date within |
722
|
|
|
* a month, e.g., the first Monday on or after the 8th. |
723
|
|
|
* |
724
|
|
|
* @param int $month The month in which this rule occurs (0-based). |
725
|
|
|
* @param int $dayOfMonth A date within that month (1-based). |
726
|
|
|
* @param int $dayOfWeek The day of the week on which this rule occurs. |
727
|
|
|
* @param int $time The time of that day (number of millis after midnight) |
728
|
|
|
* when DST ends in local wall time, which is daylight |
729
|
|
|
* time in this case. |
730
|
|
|
* @param float $mode Whether the time is local wall time, local standard |
731
|
|
|
* time, or UTC time. Default is local wall time. |
732
|
|
|
* @param bool $after If true, this rule selects the first dayOfWeek on |
733
|
|
|
* or after dayOfMonth. If false, this rule selects |
734
|
|
|
* the last dayOfWeek on or before dayOfMonth. |
735
|
|
|
* |
736
|
|
|
* @author Dominik del Bondio <[email protected]> |
737
|
|
|
* @author The ICU Project |
738
|
|
|
* @since 0.11.0 |
739
|
|
|
*/ |
740
|
|
|
public function setEndRuleIIIIFB($month, $dayOfMonth, $dayOfWeek, $time, $mode, $after) |
741
|
|
|
{ |
742
|
|
|
$this->setEndRuleIIIIF($month, $after ? $dayOfMonth : -$dayOfMonth, -$dayOfWeek, $time, $mode); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* Overloaded. |
747
|
|
|
* |
748
|
|
|
* @see AgaviSimpleTimeZone::getOffsetIIIIII() |
749
|
|
|
* @see AgaviSimpleTimeZone::getOffsetIIIIIII() |
750
|
|
|
* @see AgaviSimpleTimeZone::getOffsetIIIIIIII() |
751
|
|
|
* |
752
|
|
|
* @author Dominik del Bondio <[email protected]> |
753
|
|
|
* @author The ICU Project |
754
|
|
|
* @since 0.11.0 |
755
|
|
|
*/ |
756
|
|
|
public function getOffset() |
757
|
|
|
{ |
758
|
|
|
$arguments = func_get_args(); |
759
|
|
|
$fName = Toolkit::overloadHelper(array( |
760
|
|
|
array('name' => 'getOffsetIIIIII', |
761
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'int', 'int')), |
762
|
|
|
array('name' => 'getOffsetIIIIIII', |
763
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'int', 'int', 'int')), |
764
|
|
|
array('name' => 'getOffsetIIIIIIII', |
765
|
|
|
'parameters' => array('int', 'int', 'int', 'int', 'int', 'int', 'int', 'int')), |
766
|
|
|
), |
767
|
|
|
$arguments |
768
|
|
|
); |
769
|
|
|
|
770
|
|
|
return call_user_func_array(array($this, $fName), $arguments); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* Returns the TimeZone's adjusted GMT offset (i.e., the number of |
775
|
|
|
* milliseconds to add to GMT to get local time in this time zone, taking |
776
|
|
|
* daylight savings time into account) as of a particular reference date. |
777
|
|
|
* The reference date is used to determine whether daylight savings time is in |
778
|
|
|
* effect and needs to be figured into the offset that is returned (in other |
779
|
|
|
* words, what is the adjusted GMT offset in this time zone at this particular |
780
|
|
|
* date and time?). For the time zones produced by createTimeZone(), the |
781
|
|
|
* reference data is specified according to the Gregorian calendar, and the |
782
|
|
|
* date and time fields are in GMT, NOT local time. |
783
|
|
|
* |
784
|
|
|
* @param int $era The reference date's era |
785
|
|
|
* @param int $year The reference date's year |
786
|
|
|
* @param int $month The reference date's month (0-based; 0 is January) |
787
|
|
|
* @param int $day The reference date's day-in-month (1-based) |
788
|
|
|
* @param int $dayOfWeek The reference date's day-of-week (1-based; 1 is Sunday) |
789
|
|
|
* @param int $millis The reference date's milliseconds in day, UTT (NOT local |
790
|
|
|
* time). |
791
|
|
|
* |
792
|
|
|
* @return int The offset in milliseconds to add to GMT to get local time. |
793
|
|
|
* |
794
|
|
|
* @author Dominik del Bondio <[email protected]> |
795
|
|
|
* @author The ICU Project |
796
|
|
|
* @since 0.11.0 |
797
|
|
|
*/ |
798
|
|
View Code Duplication |
public function getOffsetIIIIII($era, $year, $month, $day, $dayOfWeek, $millis) |
|
|
|
|
799
|
|
|
{ |
800
|
|
|
// Check the month before calling Grego::monthLength(). This |
801
|
|
|
// duplicates the test that occurs in the 7-argument getOffset(), |
802
|
|
|
// however, this is unavoidable. We don't mind because this method, in |
803
|
|
|
// fact, should not be called; internal code should always call the |
804
|
|
|
// 7-argument getOffset(), and outside code should use Calendar.get(int |
805
|
|
|
// field) with fields ZONE_OFFSET and DST_OFFSET. We can't get rid of |
806
|
|
|
// this method because it's public API. - liu 8/10/98 |
807
|
|
|
if ($month < DateDefinitions::JANUARY || $month > DateDefinitions::DECEMBER) { |
808
|
|
|
throw new \InvalidArgumentException('Month out of range'); |
809
|
|
|
} |
810
|
|
|
|
811
|
|
|
return $this->getOffsetIIIIIII($era, $year, $month, $day, $dayOfWeek, $millis, CalendarGrego::monthLength($year, $month)); |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
/** |
815
|
|
|
* Gets the time zone offset, for current date, modified in case of |
816
|
|
|
* daylight savings. This is the offset to add *to* UTC to get local time. |
817
|
|
|
* |
818
|
|
|
* @param int $era The era of the given date. |
819
|
|
|
* @param int $year The year in the given date. |
820
|
|
|
* @param int $month The month in the given date. |
821
|
|
|
* Month is 0-based. e.g., 0 for January. |
822
|
|
|
* @param int $day The day-in-month of the given date. |
823
|
|
|
* @param int $dayOfWeek The day-of-week of the given date. |
824
|
|
|
* @param int $millis The millis in day in <em>standard</em> local time. |
825
|
|
|
* @param int $monthLength The length of the given month in days. |
826
|
|
|
* |
827
|
|
|
* @return int The offset to add *to* GMT to get local time. |
828
|
|
|
* |
829
|
|
|
* @author Dominik del Bondio <[email protected]> |
830
|
|
|
* @author The ICU Project |
831
|
|
|
* @since 0.11.0 |
832
|
|
|
*/ |
833
|
|
View Code Duplication |
public function getOffsetIIIIIII($era, $year, $month, $day, $dayOfWeek, $millis, $monthLength) |
|
|
|
|
834
|
|
|
{ |
835
|
|
|
// Check the month before calling Grego::monthLength(). This |
836
|
|
|
// duplicates a test that occurs in the 9-argument getOffset(), |
837
|
|
|
// however, this is unavoidable. We don't mind because this method, in |
838
|
|
|
// fact, should not be called; internal code should always call the |
839
|
|
|
// 9-argument getOffset(), and outside code should use Calendar.get(int |
840
|
|
|
// field) with fields ZONE_OFFSET and DST_OFFSET. We can't get rid of |
841
|
|
|
// this method because it's public API. - liu 8/10/98 |
842
|
|
|
if ($month < DateDefinitions::JANUARY || $month > DateDefinitions::DECEMBER) { |
843
|
|
|
throw new \InvalidArgumentException('Month out of range'); |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
// We ignore monthLength because it can be derived from year and month. |
847
|
|
|
// This is so that February in leap years is calculated correctly. |
848
|
|
|
// We keep this argument in this function for backwards compatibility. |
849
|
|
|
return $this->getOffsetIIIIIIII($era, $year, $month, $day, $dayOfWeek, $millis, CalendarGrego::monthLength($year, $month), CalendarGrego::previousMonthLength($year, $month)); |
850
|
|
|
} |
851
|
|
|
|
852
|
|
|
/** |
853
|
|
|
* Gets the time zone offset, for current date, modified in case of |
854
|
|
|
* daylight savings. This is the offset to add *to* UTC to get local time. |
855
|
|
|
* |
856
|
|
|
* @param int $era The era of the given date. |
857
|
|
|
* @param int $year The year in the given date. |
858
|
|
|
* @param int $month The month in the given date. |
859
|
|
|
* Month is 0-based. e.g., 0 for January. |
860
|
|
|
* @param int $day The day-in-month of the given date. |
861
|
|
|
* @param int $dayOfWeek The day-of-week of the given date. |
862
|
|
|
* @param int $millis The millis in day in <em>standard</em> local time. |
863
|
|
|
* @param int $monthLengthThe length of the given month in days. |
|
|
|
|
864
|
|
|
* @param int $prevMonthLength Length of the previous month in days. |
865
|
|
|
* |
866
|
|
|
* @return int The offset to add *to* GMT to get local time. |
867
|
|
|
* |
868
|
|
|
* @author Dominik del Bondio <[email protected]> |
869
|
|
|
* @author The ICU Project |
870
|
|
|
* @since 0.11.0 |
871
|
|
|
*/ |
872
|
|
|
public function getOffsetIIIIIIII($era, $year, $month, $day, $dayOfWeek, $millis, $monthLength, $prevMonthLength) |
873
|
|
|
{ |
874
|
|
|
if (($era != GregorianCalendar::AD && $era != GregorianCalendar::BC) |
875
|
|
|
|| $month < DateDefinitions::JANUARY |
876
|
|
|
|| $month > DateDefinitions::DECEMBER |
877
|
|
|
|| $day < 1 |
878
|
|
|
|| $day > $monthLength |
879
|
|
|
|| $dayOfWeek < DateDefinitions::SUNDAY |
880
|
|
|
|| $dayOfWeek > DateDefinitions::SATURDAY |
881
|
|
|
|| $millis < 0 |
882
|
|
|
|| $millis >= DateDefinitions::MILLIS_PER_DAY |
883
|
|
|
|| $monthLength < 28 |
884
|
|
|
|| $monthLength > 31 |
885
|
|
|
|| $prevMonthLength < 28 |
886
|
|
|
|| $prevMonthLength > 31 |
887
|
|
|
) { |
888
|
|
|
throw new \InvalidArgumentException('One of the supplied parameters is out of range'); |
889
|
|
|
} |
890
|
|
|
|
891
|
|
|
$result = $this->rawOffset; |
892
|
|
|
|
893
|
|
|
// Bail out if we are before the onset of daylight savings time |
894
|
|
|
if (!$this->useDaylight || $year < $this->startYear || $era != GregorianCalendar::AD) { |
895
|
|
|
return $result; |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
// Check for southern hemisphere. We assume that the start and end |
899
|
|
|
// month are different. |
900
|
|
|
$southern = ($this->startMonth > $this->endMonth); |
901
|
|
|
|
902
|
|
|
// Compare the date to the starting and ending rules.+1 = date>rule, -1 |
903
|
|
|
// = date<rule, 0 = date==rule. |
904
|
|
|
$startCompare = self::compareToRule($month, $monthLength, $prevMonthLength, $day, $dayOfWeek, |
905
|
|
|
$millis, $this->startTimeMode == self::UTC_TIME ? -$this->rawOffset : 0, |
906
|
|
|
$this->startMode, $this->startMonth, $this->startDayOfWeek, $this->startDay, $this->startTime); |
907
|
|
|
$endCompare = 0; |
908
|
|
|
|
909
|
|
|
/* We don't always have to compute endCompare. For many instances, |
910
|
|
|
* startCompare is enough to determine if we are in DST or not. In the |
911
|
|
|
* northern hemisphere, if we are before the start rule, we can't have |
912
|
|
|
* DST. In the southern hemisphere, if we are after the start rule, we |
913
|
|
|
* must have DST. This is reflected in the way the next if statement |
914
|
|
|
* (not the one immediately following) short circuits. */ |
915
|
|
|
if ($southern != ($startCompare >= 0)) { |
916
|
|
|
$endCompare = self::compareToRule($month, $monthLength, $prevMonthLength, $day, $dayOfWeek, $millis, |
917
|
|
|
$this->endTimeMode == self::WALL_TIME ? $this->dstSavings : ($this->endTimeMode == self::UTC_TIME ? -$this->rawOffset : 0), |
918
|
|
|
$this->endMode, $this->endMonth, $this->endDayOfWeek, $this->endDay, $this->endTime); |
919
|
|
|
} |
920
|
|
|
|
921
|
|
|
// Check for both the northern and southern hemisphere cases. We |
922
|
|
|
// assume that in the northern hemisphere, the start rule is before the |
923
|
|
|
// end rule within the calendar year, and vice versa for the southern |
924
|
|
|
// hemisphere. |
925
|
|
|
if ((!$southern && ($startCompare >= 0 && $endCompare < 0)) || ($southern && ($startCompare >= 0 || $endCompare < 0))) { |
926
|
|
|
$result += $this->dstSavings; |
927
|
|
|
} |
928
|
|
|
|
929
|
|
|
return $result; |
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
/** |
933
|
|
|
* Returns the TimeZone's raw GMT offset (i.e., the number of milliseconds to |
934
|
|
|
* add to GMT to get local time, before taking daylight savings time into |
935
|
|
|
* account). |
936
|
|
|
* |
937
|
|
|
* @return int The TimeZone's raw GMT offset. |
938
|
|
|
* |
939
|
|
|
* @author Dominik del Bondio <[email protected]> |
940
|
|
|
* @author The ICU Project |
941
|
|
|
* @since 0.11.0 |
942
|
|
|
*/ |
943
|
|
|
public function getRawOffset() |
944
|
|
|
{ |
945
|
|
|
return $this->rawOffset; |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
/** |
949
|
|
|
* Sets the TimeZone's raw GMT offset (i.e., the number of milliseconds to |
950
|
|
|
* add to GMT to get local time, before taking daylight savings time into |
951
|
|
|
* account). |
952
|
|
|
* |
953
|
|
|
* @param int $offsetMillis The new raw GMT offset for this time zone. |
954
|
|
|
* |
955
|
|
|
* @author Dominik del Bondio <[email protected]> |
956
|
|
|
* @author The ICU Project |
957
|
|
|
* @since 0.11.0 |
958
|
|
|
*/ |
959
|
|
|
public function setRawOffset($offsetMillis) |
960
|
|
|
{ |
961
|
|
|
$this->rawOffset = $offsetMillis; |
962
|
|
|
} |
963
|
|
|
|
964
|
|
|
/** |
965
|
|
|
* Sets the amount of time in ms that the clock is advanced during DST. |
966
|
|
|
* |
967
|
|
|
* @param int $millisSavedDuringDST The number of milliseconds the time is advanced with |
968
|
|
|
* respect to standard time when the daylight savings rules |
969
|
|
|
* are in effect. A positive number, typically one hour |
970
|
|
|
* (3600000). |
971
|
|
|
* |
972
|
|
|
* @author Dominik del Bondio <[email protected]> |
973
|
|
|
* @author The ICU Project |
974
|
|
|
* @since 0.11.0 |
975
|
|
|
*/ |
976
|
|
|
public function setDSTSavings($millisSavedDuringDST) |
977
|
|
|
{ |
978
|
|
|
if ($millisSavedDuringDST <= 0) { |
979
|
|
|
throw new \InvalidArgumentException('The amount must be a positive number'); |
980
|
|
|
} else { |
981
|
|
|
$this->dstSavings = $millisSavedDuringDST; |
982
|
|
|
} |
983
|
|
|
} |
984
|
|
|
|
985
|
|
|
/** |
986
|
|
|
* Returns the amount of time in ms that the clock is advanced during DST. |
987
|
|
|
* |
988
|
|
|
* @return int The number of milliseconds the time is advanced with |
989
|
|
|
* respect to standard time when the daylight savings rules |
990
|
|
|
* are in effect. A positive number, typically one hour |
991
|
|
|
* (3600000). |
992
|
|
|
* |
993
|
|
|
* @author Dominik del Bondio <[email protected]> |
994
|
|
|
* @author The ICU Project |
995
|
|
|
* @since 0.11.0 |
996
|
|
|
*/ |
997
|
|
|
public function getDSTSavings() |
998
|
|
|
{ |
999
|
|
|
return $this->dstSavings; |
1000
|
|
|
} |
1001
|
|
|
|
1002
|
|
|
/** |
1003
|
|
|
* Queries if this TimeZone uses Daylight Savings Time. |
1004
|
|
|
* |
1005
|
|
|
* @return bool True if this TimeZone uses Daylight Savings Time; |
1006
|
|
|
* false otherwise. |
1007
|
|
|
* |
1008
|
|
|
* @author Dominik del Bondio <[email protected]> |
1009
|
|
|
* @author The ICU Project |
1010
|
|
|
* @since 0.11.0 |
1011
|
|
|
*/ |
1012
|
|
|
public function useDaylightTime() |
1013
|
|
|
{ |
1014
|
|
|
return $this->useDaylight; |
1015
|
|
|
} |
1016
|
|
|
|
1017
|
|
|
/** |
1018
|
|
|
* Return true if this zone has the same rules and offset as another zone. |
1019
|
|
|
* |
1020
|
|
|
* @param TimeZone $other The TimeZone object to be compared with |
1021
|
|
|
* |
1022
|
|
|
* @return bool True if the given zone has the same rules and offset as |
1023
|
|
|
* this one |
1024
|
|
|
* |
1025
|
|
|
* @author Dominik del Bondio <[email protected]> |
1026
|
|
|
* @author The ICU Project |
1027
|
|
|
* @since 0.11.0 |
1028
|
|
|
*/ |
1029
|
|
|
public function hasSameRules(TimeZone $other) |
1030
|
|
|
{ |
1031
|
|
|
if ($this === $other) { |
1032
|
|
|
return true; |
1033
|
|
|
} |
1034
|
|
|
if (get_class($this) != get_class($other)) { |
1035
|
|
|
return false; |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
return true; |
1039
|
|
|
// TODO: implement properly |
1040
|
|
|
/* |
|
|
|
|
1041
|
|
|
return $this->rawOffset == $that->rawOffset && |
1042
|
|
|
$this->useDaylight == $that->useDaylight && |
1043
|
|
|
(!$this->useDaylight |
1044
|
|
|
// Only check rules if using DST |
1045
|
|
|
|| ($this->dstSavings == $that->dstSavings && |
1046
|
|
|
$this->startMode == $that->startMode && |
1047
|
|
|
$this->startMonth == $that->startMonth && |
1048
|
|
|
$this->startDay == $that->startDay && |
1049
|
|
|
$this->startDayOfWeek == $that->startDayOfWeek && |
1050
|
|
|
$this->startTime == $that->startTime && |
1051
|
|
|
$this->startTimeMode == $that->startTimeMode && |
1052
|
|
|
$this->endMode == $that->endMode && |
1053
|
|
|
$this->endMonth == $that->endMonth && |
1054
|
|
|
$this->endDay == $that->endDay && |
1055
|
|
|
$this->endDayOfWeek == $that->endDayOfWeek && |
1056
|
|
|
$this->endTime == $that->endTime && |
1057
|
|
|
$this->endTimeMode == $that->endTimeMode && |
1058
|
|
|
$this->startYear == $that->startYear)); |
1059
|
|
|
*/ |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
/** |
1063
|
|
|
* Constants specifying values of startMode and endMode. |
1064
|
|
|
*/ |
1065
|
|
|
const DOM_MODE = 1; |
1066
|
|
|
const DOW_IN_MONTH_MODE = 2; |
1067
|
|
|
const DOW_GE_DOM_MODE = 3; |
1068
|
|
|
const DOW_LE_DOM_MODE = 4; |
1069
|
|
|
|
1070
|
|
|
/** |
1071
|
|
|
* Internal construction method. |
1072
|
|
|
* @param int $rawOffsetGMT The new SimpleTimeZone's raw GMT offset |
1073
|
|
|
* @param int $startMonth the month DST starts |
1074
|
|
|
* @param int $startDay the day DST starts |
1075
|
|
|
* @param int $startDayOfWeek the DOW DST starts |
1076
|
|
|
* @param int $startTime the time DST starts |
1077
|
|
|
* @param int $startTimeMode Whether the start time is local wall time, local |
1078
|
|
|
* standard time, or UTC time. Default is local wall time. |
1079
|
|
|
* @param int $endMonth the month DST ends |
1080
|
|
|
* @param int $endDay the day DST ends |
1081
|
|
|
* @param int $endDayOfWeek ythe DOW DST ends |
1082
|
|
|
* @param int $endTime the time DST ends |
1083
|
|
|
* @param int $endTimeMode Whether the end time is local wall time, local |
1084
|
|
|
* standard time, or UTC time. Default is local wall time. |
1085
|
|
|
* @param int $dstSavings The number of milliseconds added to standard time |
1086
|
|
|
* to get DST time. Default is one hour. |
1087
|
|
|
* |
1088
|
|
|
* @author Dominik del Bondio <[email protected]> |
1089
|
|
|
* @author The ICU Project |
1090
|
|
|
* @since 0.11.0 |
1091
|
|
|
*/ |
1092
|
|
|
private function construct($rawOffsetGMT, $startMonth, $startDay, $startDayOfWeek, $startTime, $startTimeMode, $endMonth, $endDay, $endDayOfWeek, $endTime, $endTimeMode, $dstSavings) |
1093
|
|
|
{ |
1094
|
|
|
$this->rawOffset = $rawOffsetGMT; |
1095
|
|
|
$this->startMonth = $startMonth; |
1096
|
|
|
$this->startDay = $startDay; |
1097
|
|
|
$this->startDayOfWeek = $startDayOfWeek; |
1098
|
|
|
$this->startTime = $startTime; |
1099
|
|
|
$this->startTimeMode = $startTimeMode; |
1100
|
|
|
$this->endMonth = $endMonth; |
1101
|
|
|
$this->endDay = $endDay; |
1102
|
|
|
$this->endDayOfWeek = $endDayOfWeek; |
1103
|
|
|
$this->endTime = $endTime; |
1104
|
|
|
$this->endTimeMode = $endTimeMode; |
1105
|
|
|
$this->dstSavings = $dstSavings; |
1106
|
|
|
$this->startYear = 0; |
1107
|
|
|
$this->startMode = self::DOM_MODE; |
1108
|
|
|
$this->endMode = self::DOM_MODE; |
1109
|
|
|
|
1110
|
|
|
$this->decodeRules(); |
1111
|
|
|
|
1112
|
|
|
if ($dstSavings <= 0) { |
1113
|
|
|
throw new \InvalidArgumentException('The DST savings amount must be a positive number'); |
1114
|
|
|
} |
1115
|
|
|
} |
1116
|
|
|
|
1117
|
|
|
/** |
1118
|
|
|
* Compare a given date in the year to a rule. Return 1, 0, or -1, depending |
1119
|
|
|
* on whether the date is after, equal to, or before the rule date. The |
1120
|
|
|
* millis are compared directly against the ruleMillis, so any |
1121
|
|
|
* standard-daylight adjustments must be handled by the caller. |
1122
|
|
|
* |
1123
|
|
|
* @return int 1 if the date is after the rule date, -1 if the date is |
1124
|
|
|
* before the rule date, or 0 if the date is equal to the rule |
1125
|
|
|
* date. |
1126
|
|
|
* |
1127
|
|
|
* @author Dominik del Bondio <[email protected]> |
1128
|
|
|
* @author The ICU Project |
1129
|
|
|
* @since 0.11.0 |
1130
|
|
|
*/ |
1131
|
|
|
private static function compareToRule($month, $monthLen, $prevMonthLen, $dayOfMonth, $dayOfWeek, $millis, $millisDelta, $ruleMode, $ruleMonth, $ruleDayOfWeek, $ruleDay, $ruleMillis) |
1132
|
|
|
{ |
1133
|
|
|
// Make adjustments for startTimeMode and endTimeMode |
1134
|
|
|
$millis += $millisDelta; |
1135
|
|
|
while ($millis >= DateDefinitions::MILLIS_PER_DAY) { |
1136
|
|
|
$millis -= DateDefinitions::MILLIS_PER_DAY; |
1137
|
|
|
++$dayOfMonth; |
1138
|
|
|
$dayOfWeek = 1 + ($dayOfWeek % 7); // dayOfWeek is one-based |
1139
|
|
|
if ($dayOfMonth > $monthLen) { |
1140
|
|
|
$dayOfMonth = 1; |
1141
|
|
|
/* When incrementing the month, it is desirable to overflow |
1142
|
|
|
* from DECEMBER to DECEMBER+1, since we use the result to |
1143
|
|
|
* compare against a real month. Wraparound of the value |
1144
|
|
|
* leads to bug 4173604. */ |
1145
|
|
|
++$month; |
1146
|
|
|
} |
1147
|
|
|
} |
1148
|
|
|
while ($millis < 0) { |
1149
|
|
|
$millis += DateDefinitions::MILLIS_PER_DAY; |
1150
|
|
|
--$dayOfMonth; |
1151
|
|
|
$dayOfWeek = 1 + (($dayOfWeek + 5) % 7); // dayOfWeek is one-based |
1152
|
|
|
if ($dayOfMonth < 1) { |
1153
|
|
|
$dayOfMonth = $prevMonthLen; |
1154
|
|
|
--$month; |
1155
|
|
|
} |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
// first compare months. If they're different, we don't have to worry about |
1159
|
|
|
// days and times |
1160
|
|
|
if ($month < $ruleMonth) { |
1161
|
|
|
return -1; |
1162
|
|
|
} elseif ($month > $ruleMonth) { |
1163
|
|
|
return 1; |
1164
|
|
|
} |
1165
|
|
|
|
1166
|
|
|
// calculate the actual day of month for the rule |
1167
|
|
|
$ruleDayOfMonth = 0; |
1168
|
|
|
// Adjust the ruleDay to the monthLen, for non-leap year February 29 rule days. |
1169
|
|
|
if ($ruleDay > $monthLen) { |
1170
|
|
|
$ruleDay = $monthLen; |
1171
|
|
|
} |
1172
|
|
|
|
1173
|
|
|
switch ($ruleMode) { |
1174
|
|
|
// if the mode is day-of-month, the day of month is given |
1175
|
|
|
case self::DOM_MODE: |
1176
|
|
|
$ruleDayOfMonth = $ruleDay; |
1177
|
|
|
break; |
1178
|
|
|
|
1179
|
|
|
// if the mode is day-of-week-in-month, calculate the day-of-month from it |
1180
|
|
|
case self::DOW_IN_MONTH_MODE: |
1181
|
|
|
// In this case ruleDay is the day-of-week-in-month (this code is using |
1182
|
|
|
// the dayOfWeek and dayOfMonth parameters to figure out the day-of-week |
1183
|
|
|
// of the first day of the month, so it's trusting that they're really |
1184
|
|
|
// consistent with each other) |
1185
|
|
|
if ($ruleDay > 0) { |
1186
|
|
|
$ruleDayOfMonth = 1 + ($ruleDay - 1) * 7 + (7 + $ruleDayOfWeek - ($dayOfWeek - $dayOfMonth + 1)) % 7; |
1187
|
|
|
|
1188
|
|
|
// if ruleDay is negative (we assume it's not zero here), we have to |
1189
|
|
|
// do the same calculation figuring backward from the last day of the |
1190
|
|
|
// month. |
1191
|
|
|
} else { |
1192
|
|
|
// (again, this code is trusting that dayOfWeek and dayOfMonth are |
1193
|
|
|
// consistent with each other here, since we're using them to figure |
1194
|
|
|
// the day of week of the first of the month) |
1195
|
|
|
$ruleDayOfMonth = $monthLen + ($ruleDay + 1) * 7 - (7 + ($dayOfWeek + $monthLen - $dayOfMonth) - $ruleDayOfWeek) % 7; |
1196
|
|
|
} |
1197
|
|
|
break; |
1198
|
|
|
|
1199
|
|
View Code Duplication |
case self::DOW_GE_DOM_MODE: |
|
|
|
|
1200
|
|
|
$ruleDayOfMonth = $ruleDay + (49 + $ruleDayOfWeek - $ruleDay - $dayOfWeek + $dayOfMonth) % 7; |
1201
|
|
|
break; |
1202
|
|
|
|
1203
|
|
View Code Duplication |
case self::DOW_LE_DOM_MODE: |
|
|
|
|
1204
|
|
|
$ruleDayOfMonth = $ruleDay - (49 - $ruleDayOfWeek + $ruleDay + $dayOfWeek - $dayOfMonth) % 7; |
1205
|
|
|
// Note at this point ruleDayOfMonth may be <1, although it will |
1206
|
|
|
// be >=1 for well-formed rules. |
1207
|
|
|
break; |
1208
|
|
|
} |
1209
|
|
|
|
1210
|
|
|
// now that we have a real day-in-month for the rule, we can compare days... |
1211
|
|
|
if ($dayOfMonth < $ruleDayOfMonth) { |
1212
|
|
|
return -1; |
1213
|
|
|
} elseif ($dayOfMonth > $ruleDayOfMonth) { |
1214
|
|
|
return 1; |
1215
|
|
|
} |
1216
|
|
|
|
1217
|
|
|
// ...and if they're equal, we compare times |
1218
|
|
|
if ($millis < $ruleMillis) { |
1219
|
|
|
return -1; |
1220
|
|
|
} elseif ($millis > $ruleMillis) { |
1221
|
|
|
return 1; |
1222
|
|
|
} else { |
1223
|
|
|
return 0; |
1224
|
|
|
} |
1225
|
|
|
} |
1226
|
|
|
|
1227
|
|
|
//---------------------------------------------------------------------- |
1228
|
|
|
// Rule representation |
1229
|
|
|
// |
1230
|
|
|
// We represent the following flavors of rules: |
1231
|
|
|
// 5 the fifth of the month |
1232
|
|
|
// lastSun the last Sunday in the month |
1233
|
|
|
// lastMon the last Monday in the month |
1234
|
|
|
// Sun>=8 first Sunday on or after the eighth |
1235
|
|
|
// Sun<=25 last Sunday on or before the 25th |
1236
|
|
|
// This is further complicated by the fact that we need to remain |
1237
|
|
|
// backward compatible with the 1.1 FCS. Finally, we need to minimize |
1238
|
|
|
// API changes. In order to satisfy these requirements, we support |
1239
|
|
|
// three representation systems, and we translate between them. |
1240
|
|
|
// |
1241
|
|
|
// INTERNAL REPRESENTATION |
1242
|
|
|
// This is the format SimpleTimeZone objects take after construction or |
1243
|
|
|
// streaming in is complete. Rules are represented directly, using an |
1244
|
|
|
// unencoded format. We will discuss the start rule only below; the end |
1245
|
|
|
// rule is analogous. |
1246
|
|
|
// startMode Takes on enumerated values DAY_OF_MONTH, |
1247
|
|
|
// DOW_IN_MONTH, DOW_AFTER_DOM, or DOW_BEFORE_DOM. |
1248
|
|
|
// startDay The day of the month, or for DOW_IN_MONTH mode, a |
1249
|
|
|
// value indicating which DOW, such as +1 for first, |
1250
|
|
|
// +2 for second, -1 for last, etc. |
1251
|
|
|
// startDayOfWeek The day of the week. Ignored for DAY_OF_MONTH. |
1252
|
|
|
// |
1253
|
|
|
// ENCODED REPRESENTATION |
1254
|
|
|
// This is the format accepted by the constructor and by setStartRule() |
1255
|
|
|
// and setEndRule(). It uses various combinations of positive, negative, |
1256
|
|
|
// and zero values to encode the different rules. This representation |
1257
|
|
|
// allows us to specify all the different rule flavors without altering |
1258
|
|
|
// the API. |
1259
|
|
|
// MODE startMonth startDay startDayOfWeek |
1260
|
|
|
// DOW_IN_MONTH_MODE >=0 !=0 >0 |
1261
|
|
|
// DOM_MODE >=0 >0 ==0 |
1262
|
|
|
// DOW_GE_DOM_MODE >=0 >0 <0 |
1263
|
|
|
// DOW_LE_DOM_MODE >=0 <0 <0 |
1264
|
|
|
// (no DST) don't care ==0 don't care |
1265
|
|
|
// |
1266
|
|
|
// STREAMED REPRESENTATION |
1267
|
|
|
// We must retain binary compatibility with the 1.1 FCS. The 1.1 code only |
1268
|
|
|
// handles DOW_IN_MONTH_MODE and non-DST mode, the latter indicated by the |
1269
|
|
|
// flag useDaylight. When we stream an object out, we translate into an |
1270
|
|
|
// approximate DOW_IN_MONTH_MODE representation so the object can be parsed |
1271
|
|
|
// and used by 1.1 code. Following that, we write out the full |
1272
|
|
|
// representation separately so that contemporary code can recognize and |
1273
|
|
|
// parse it. The full representation is written in a "packed" format, |
1274
|
|
|
// consisting of a version number, a length, and an array of bytes. Future |
1275
|
|
|
// versions of this class may specify different versions. If they wish to |
1276
|
|
|
// include additional data, they should do so by storing them after the |
1277
|
|
|
// packed representation below. |
1278
|
|
|
//---------------------------------------------------------------------- |
1279
|
|
|
|
1280
|
|
|
/** |
1281
|
|
|
* Given a set of encoded rules in startDay and startDayOfMonth, decode |
1282
|
|
|
* them and set the startMode appropriately. Do the same for endDay and |
1283
|
|
|
* endDayOfMonth. |
1284
|
|
|
* <P> |
1285
|
|
|
* Upon entry, the day of week variables may be zero or |
1286
|
|
|
* negative, in order to indicate special modes. The day of month |
1287
|
|
|
* variables may also be negative. |
1288
|
|
|
* <P> |
1289
|
|
|
* Upon exit, the mode variables will be |
1290
|
|
|
* set, and the day of week and day of month variables will be positive. |
1291
|
|
|
* <P> |
1292
|
|
|
* This method also recognizes a startDay or endDay of zero as indicating |
1293
|
|
|
* no DST. |
1294
|
|
|
* |
1295
|
|
|
* @author Dominik del Bondio <[email protected]> |
1296
|
|
|
* @author The ICU Project |
1297
|
|
|
* @since 0.11.0 |
1298
|
|
|
*/ |
1299
|
|
|
private function decodeRules() |
1300
|
|
|
{ |
1301
|
|
|
$this->decodeStartRule(); |
1302
|
|
|
$this->decodeEndRule(); |
1303
|
|
|
} |
1304
|
|
|
|
1305
|
|
|
/** |
1306
|
|
|
* Decode the start rule and validate the parameters. The parameters are |
1307
|
|
|
* expected to be in encoded form, which represents the various rule modes |
1308
|
|
|
* by negating or zeroing certain values. Representation formats are: |
1309
|
|
|
* <p> |
1310
|
|
|
* <pre> |
1311
|
|
|
* DOW_IN_MONTH DOM DOW>=DOM DOW<=DOM no DST |
1312
|
|
|
* ------------ ----- -------- -------- ---------- |
1313
|
|
|
* month 0..11 same same same don't care |
1314
|
|
|
* day -5..5 1..31 1..31 -1..-31 0 |
1315
|
|
|
* dayOfWeek 1..7 0 -1..-7 -1..-7 don't care |
1316
|
|
|
* time 0..ONEDAY same same same don't care |
1317
|
|
|
* </pre> |
1318
|
|
|
* The range for month does not include UNDECIMBER since this class is |
1319
|
|
|
* really specific to GregorianCalendar, which does not use that month. |
1320
|
|
|
* The range for time includes ONEDAY (vs. ending at ONEDAY-1) because the |
1321
|
|
|
* end rule is an exclusive limit point. That is, the range of times that |
1322
|
|
|
* are in DST include those >= the start and < the end. For this reason, |
1323
|
|
|
* it should be possible to specify an end of ONEDAY in order to include the |
1324
|
|
|
* entire day. Although this is equivalent to time 0 of the following day, |
1325
|
|
|
* it's not always possible to specify that, for example, on December 31. |
1326
|
|
|
* While arguably the start range should still be 0..ONEDAY-1, we keep |
1327
|
|
|
* the start and end ranges the same for consistency. |
1328
|
|
|
* |
1329
|
|
|
* @author Dominik del Bondio <[email protected]> |
1330
|
|
|
* @author The ICU Project |
1331
|
|
|
* @since 0.11.0 |
1332
|
|
|
*/ |
1333
|
|
View Code Duplication |
private function decodeStartRule() |
|
|
|
|
1334
|
|
|
{ |
1335
|
|
|
$this->useDaylight = (($this->startDay != 0) && ($this->endDay != 0) ? true : false); |
1336
|
|
|
if ($this->useDaylight && $this->dstSavings == 0) { |
1337
|
|
|
$this->dstSavings = DateDefinitions::MILLIS_PER_HOUR; |
1338
|
|
|
} |
1339
|
|
|
if ($this->startDay != 0) { |
1340
|
|
|
if ($this->startMonth < DateDefinitions::JANUARY || $this->startMonth > DateDefinitions::DECEMBER) { |
1341
|
|
|
throw new \InvalidArgumentException('startMonth out of range'); |
1342
|
|
|
} |
1343
|
|
|
if ($this->startTime < 0 || $this->startTime > DateDefinitions::MILLIS_PER_DAY || $this->startTimeMode < self::WALL_TIME || $this->startTimeMode > self::UTC_TIME) { |
1344
|
|
|
throw new \InvalidArgumentException('startTime out of range'); |
1345
|
|
|
} |
1346
|
|
|
if ($this->startDayOfWeek == 0) { |
1347
|
|
|
$this->startMode = self::DOM_MODE; |
1348
|
|
|
} else { |
1349
|
|
|
if ($this->startDayOfWeek > 0) { |
1350
|
|
|
$this->startMode = self::DOW_IN_MONTH_MODE; |
1351
|
|
|
} else { |
1352
|
|
|
$this->startDayOfWeek = -$this->startDayOfWeek; |
1353
|
|
|
if ($this->startDay > 0) { |
1354
|
|
|
$this->startMode = self::DOW_GE_DOM_MODE; |
1355
|
|
|
} else { |
1356
|
|
|
$this->startDay = -$this->startDay; |
1357
|
|
|
$this->startMode = self::DOW_LE_DOM_MODE; |
1358
|
|
|
} |
1359
|
|
|
} |
1360
|
|
|
if ($this->startDayOfWeek > DateDefinitions::SATURDAY) { |
1361
|
|
|
throw new \InvalidArgumentException('startDayOfWeek out of range'); |
1362
|
|
|
} |
1363
|
|
|
} |
1364
|
|
|
if ($this->startMode == self::DOW_IN_MONTH_MODE) { |
1365
|
|
|
if ($this->startDay < -5 || $this->startDay > 5) { |
1366
|
|
|
throw new \InvalidArgumentException('startDay out of range'); |
1367
|
|
|
} |
1368
|
|
|
} elseif ($this->startDay < 1 || $this->startDay > self::$STATICMONTHLENGTH[$this->startMonth]) { |
1369
|
|
|
throw new \InvalidArgumentException('startDay out of range'); |
1370
|
|
|
} |
1371
|
|
|
} |
1372
|
|
|
} |
1373
|
|
|
|
1374
|
|
|
/** |
1375
|
|
|
* Decode the end rule and validate the parameters. This method is exactly |
1376
|
|
|
* analogous to decodeStartRule(). |
1377
|
|
|
* |
1378
|
|
|
* @see AgaviSimpleTimeZone::decodeStartRule |
1379
|
|
|
* |
1380
|
|
|
* @author Dominik del Bondio <[email protected]> |
1381
|
|
|
* @author The ICU Project |
1382
|
|
|
* @since 0.11.0 |
1383
|
|
|
*/ |
1384
|
|
View Code Duplication |
private function decodeEndRule() |
|
|
|
|
1385
|
|
|
{ |
1386
|
|
|
$this->useDaylight = (($this->startDay != 0) && ($this->endDay != 0) ? true : false); |
1387
|
|
|
if ($this->useDaylight && $this->dstSavings == 0) { |
1388
|
|
|
$this->dstSavings = DateDefinitions::MILLIS_PER_HOUR; |
1389
|
|
|
} |
1390
|
|
|
if ($this->endDay != 0) { |
1391
|
|
|
if ($this->endMonth < DateDefinitions::JANUARY || $this->endMonth > DateDefinitions::DECEMBER) { |
1392
|
|
|
throw new \InvalidArgumentException('endMonth out of range'); |
1393
|
|
|
} |
1394
|
|
|
if ($this->endTime < 0 || $this->endTime > DateDefinitions::MILLIS_PER_DAY || $this->endTimeMode < self::WALL_TIME || $this->endTimeMode > self::UTC_TIME) { |
1395
|
|
|
throw new \InvalidArgumentException('endTime out of range'); |
1396
|
|
|
} |
1397
|
|
|
if ($this->endDayOfWeek == 0) { |
1398
|
|
|
$this->endMode = self::DOM_MODE; |
1399
|
|
|
} else { |
1400
|
|
|
if ($this->endDayOfWeek > 0) { |
1401
|
|
|
$this->endMode = self::DOW_IN_MONTH_MODE; |
1402
|
|
|
} else { |
1403
|
|
|
$this->endDayOfWeek = -$this->endDayOfWeek; |
1404
|
|
|
if ($this->endDay > 0) { |
1405
|
|
|
$this->endMode = self::DOW_GE_DOM_MODE; |
1406
|
|
|
} else { |
1407
|
|
|
$this->endDay = -$this->endDay; |
1408
|
|
|
$this->endMode = self::DOW_LE_DOM_MODE; |
1409
|
|
|
} |
1410
|
|
|
} |
1411
|
|
|
if ($this->endDayOfWeek > DateDefinitions::SATURDAY) { |
1412
|
|
|
throw new \InvalidArgumentException('endDayOfWeek out of range'); |
1413
|
|
|
} |
1414
|
|
|
} |
1415
|
|
|
if ($this->endMode == self::DOW_IN_MONTH_MODE) { |
1416
|
|
|
if ($this->endDay < -5 || $this->endDay > 5) { |
1417
|
|
|
throw new \InvalidArgumentException('endDay out of range'); |
1418
|
|
|
} |
1419
|
|
|
} elseif ($this->endDay < 1 || $this->endDay > self::$STATICMONTHLENGTH[$this->endMonth]) { |
1420
|
|
|
throw new \InvalidArgumentException('endDay out of range'); |
1421
|
|
|
} |
1422
|
|
|
} |
1423
|
|
|
} |
1424
|
|
|
|
1425
|
|
|
private $startMonth, $startDay, $startDayOfWeek; // the month, day, DOW, and time DST starts |
|
|
|
|
1426
|
|
|
private $startTime; |
1427
|
|
|
private $startTimeMode, $endTimeMode; // Mode for startTime, endTime; see TimeMode |
|
|
|
|
1428
|
|
|
private $endMonth, $endDay, $endDayOfWeek; // the month, day, DOW, and time DST ends |
|
|
|
|
1429
|
|
|
private $endTime; |
1430
|
|
|
private $startYear; // the year these DST rules took effect |
1431
|
|
|
private $rawOffset; // the TimeZone's raw GMT offset |
1432
|
|
|
private $useDaylight; // flag indicating whether this TimeZone uses DST |
1433
|
|
|
private static $STATICMONTHLENGTH = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
1434
|
|
|
private $startMode, $endMode; // flags indicating what kind of rules the DST rules are |
|
|
|
|
1435
|
|
|
|
1436
|
|
|
/** |
1437
|
|
|
* A positive value indicating the amount of time saved during DST in ms. |
1438
|
|
|
* Typically one hour; sometimes 30 minutes. |
1439
|
|
|
*/ |
1440
|
|
|
private $dstSavings; |
1441
|
|
|
} |
1442
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.