Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like SimpleTimeZone often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SimpleTimeZone, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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) |
|
| 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() |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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() |
|
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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() |
|
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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() |
||
| 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) |
|
| 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) |
|
| 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) |
||
| 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() |
||
| 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) |
||
| 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) |
||
| 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() |
||
| 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() |
||
| 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) |
||
| 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) |
||
| 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) |
||
| 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() |
||
| 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() |
|
| 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() |
|
| 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.