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 GregorianCalendar 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 GregorianCalendar, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 39 | class GregorianCalendar extends Calendar |
||
| 40 | { |
||
| 41 | const CUTOVER_JULIAN_DAY = 2299161; |
||
| 42 | //const kPapalCutover = (2299161.0 - kEpochStartAsJulianDay) * AgaviDateDefinitions::MILLIS_PER_DAY; |
||
| 43 | const PAPAL_CUTOVER = -12219292800000.0; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Overloaded. |
||
| 47 | * |
||
| 48 | * @see AgaviGregorianCalendar::constructorO() |
||
| 49 | * @see AgaviGregorianCalendar::constructorOO() |
||
| 50 | * @see AgaviGregorianCalendar::constructorOIII() |
||
| 51 | * @see AgaviGregorianCalendar::constructorOIIIII() |
||
| 52 | * @see AgaviGregorianCalendar::constructorOIIIIII() |
||
| 53 | * |
||
| 54 | * @author Dominik del Bondio <[email protected]> |
||
| 55 | * @author The ICU Project |
||
| 56 | * @since 0.11.0 |
||
| 57 | */ |
||
| 58 | public function __construct() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Initialize all variables to default values. |
||
| 94 | * |
||
| 95 | * @author Dominik del Bondio <[email protected]> |
||
| 96 | * @author The ICU Project |
||
| 97 | * @since 0.11.0 |
||
| 98 | */ |
||
| 99 | protected function initVariables() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Constructor. |
||
| 113 | * |
||
| 114 | * @param TimeZone|Locale|TranslationManager |
||
| 115 | * |
||
| 116 | * @author Dominik del Bondio <[email protected]> |
||
| 117 | * @author The ICU Project |
||
| 118 | * @since 0.11.0 |
||
| 119 | */ |
||
| 120 | protected function constructorO($zoneOrLocale) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Constructor. |
||
| 148 | * |
||
| 149 | * @param TimeZone $zone |
||
| 150 | * @param Locale $locale |
||
| 151 | * |
||
| 152 | * @author Dominik del Bondio <[email protected]> |
||
| 153 | * @author The ICU Project |
||
| 154 | * @since 0.11.0 |
||
| 155 | */ |
||
| 156 | protected function constructorOO(TimeZone $zone, Locale $locale) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Constructor. |
||
| 165 | * |
||
| 166 | * @param TranslationManager $tm |
||
| 167 | * @param int $year |
||
| 168 | * @param int $month |
||
| 169 | * @param int $date |
||
| 170 | * |
||
| 171 | * @author Dominik del Bondio <[email protected]> |
||
| 172 | * @author The ICU Project |
||
| 173 | * @since 0.11.0 |
||
| 174 | */ |
||
| 175 | protected function constructorOIII(TranslationManager $tm, $year, $month, $date) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Constructor. |
||
| 186 | * |
||
| 187 | * @param TranslationManager $tm |
||
| 188 | * @param int $year |
||
| 189 | * @param int $month |
||
| 190 | * @param int $date |
||
| 191 | * @param int $hour |
||
| 192 | * @param int $minute |
||
| 193 | * |
||
| 194 | * @author Dominik del Bondio <[email protected]> |
||
| 195 | * @author The ICU Project |
||
| 196 | * @since 0.11.0 |
||
| 197 | */ |
||
| 198 | View Code Duplication | protected function constructorOIIIII(TranslationManager $tm, $year, $month, $date, $hour, $minute) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * Constructor. |
||
| 211 | * |
||
| 212 | * @param TranslationManager $tm |
||
| 213 | * @param int $year |
||
| 214 | * @param int $month |
||
| 215 | * @param int $date |
||
| 216 | * @param int $hour |
||
| 217 | * @param int $minute |
||
| 218 | * @param int $second |
||
| 219 | * |
||
| 220 | * @author Dominik del Bondio <[email protected]> |
||
| 221 | * @author The ICU Project |
||
| 222 | * @since 0.11.0 |
||
| 223 | */ |
||
| 224 | View Code Duplication | protected function constructorOIIIIII(TranslationManager $tm, $year, $month, $date, $hour, $minute, $second) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * Useful constants for GregorianCalendar and TimeZone. |
||
| 238 | */ |
||
| 239 | const BC = 0; |
||
| 240 | const AD = 1; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Sets the GregorianCalendar change date. This is the point when the switch |
||
| 244 | * from Julian dates to Gregorian dates occurred. Default is 00:00:00 local |
||
| 245 | * time, October 15, 1582. Previous to this time and date will be Julian |
||
| 246 | * dates. |
||
| 247 | * |
||
| 248 | * @param float $date The given Gregorian cutover date. |
||
| 249 | * |
||
| 250 | * @author Dominik del Bondio <[email protected]> |
||
| 251 | * @author The ICU Project |
||
| 252 | * @since 0.11.0 |
||
| 253 | */ |
||
| 254 | public function setGregorianChange($date) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Gets the Gregorian Calendar change date. This is the point when the switch |
||
| 292 | * from Julian dates to Gregorian dates occurred. Default is 00:00:00 local |
||
| 293 | * time, October 15, 1582. Previous to this time and date will be Julian |
||
| 294 | * dates. |
||
| 295 | * |
||
| 296 | * @return float The Gregorian cutover time for this calendar. |
||
| 297 | * |
||
| 298 | * @author Dominik del Bondio <[email protected]> |
||
| 299 | * @author The ICU Project |
||
| 300 | * @since 0.11.0 |
||
| 301 | */ |
||
| 302 | public function getGregorianChange() |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Return true if the given year is a leap year. Determination of whether a |
||
| 309 | * year is a leap year is actually very complicated. We do something crude |
||
| 310 | * and mostly correct here, but for a real determination you need a lot of |
||
| 311 | * contextual information. For example, in Sweden, the change from Julian to |
||
| 312 | * Gregorian happened in a complex way resulting in missed leap years and |
||
| 313 | * double leap years between 1700 and 1753. Another example is that after the |
||
| 314 | * start of the Julian calendar in 45 B.C., the leap years did not regularize |
||
| 315 | * until 8 A.D. This method ignores these quirks, and pays attention only to |
||
| 316 | * the Julian onset date and the Gregorian cutover (which can be changed). |
||
| 317 | * |
||
| 318 | * @param int $year The given year. |
||
| 319 | * |
||
| 320 | * @return bool if the given year is a leap year; false otherwise. |
||
| 321 | * |
||
| 322 | * @author Dominik del Bondio <[email protected]> |
||
| 323 | * @author The ICU Project |
||
| 324 | * @since 0.11.0 |
||
| 325 | */ |
||
| 326 | public function isLeapYear($year) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Returns true if the given Calendar object is equivalent to this |
||
| 337 | * one. Calendar override. |
||
| 338 | * |
||
| 339 | * @param Calendar $other the Calendar to be compared with this Calendar |
||
| 340 | * |
||
| 341 | * @return bool |
||
| 342 | * |
||
| 343 | * @author Dominik del Bondio <[email protected]> |
||
| 344 | * @author The ICU Project |
||
| 345 | * @since 0.11.0 |
||
| 346 | */ |
||
| 347 | public function isEquivalentTo(Calendar $other) |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @see AgaviCalendar::getActualMinimum() |
||
| 355 | * |
||
| 356 | * @author Dominik del Bondio <[email protected]> |
||
| 357 | * @author The ICU Project |
||
| 358 | * @since 0.11.0 |
||
| 359 | */ |
||
| 360 | public function getActualMinimum($field) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @see AgaviCalendar::getActualMaximum() |
||
| 367 | * |
||
| 368 | * @author Dominik del Bondio <[email protected]> |
||
| 369 | * @author The ICU Project |
||
| 370 | * @since 0.11.0 |
||
| 371 | */ |
||
| 372 | public function getActualMaximum($field) |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @see AgaviCalendar::inDaylightTime |
||
| 448 | * |
||
| 449 | * @author Dominik del Bondio <[email protected]> |
||
| 450 | * @author The ICU Project |
||
| 451 | * @since 0.11.0 |
||
| 452 | */ |
||
| 453 | public function inDaylightTime() |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Return the ERA. We need a special method for this because the |
||
| 467 | * default ERA is AD, but a zero (unset) ERA is BC. |
||
| 468 | * |
||
| 469 | * @return int The ERA. |
||
| 470 | * |
||
| 471 | * @author Dominik del Bondio <[email protected]> |
||
| 472 | * @author The ICU Project |
||
| 473 | * @since 0.11.0 |
||
| 474 | */ |
||
| 475 | protected function internalGetEra() |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @see AgaviCalendar::handleComputeMonthStart |
||
| 482 | * |
||
| 483 | * @author Dominik del Bondio <[email protected]> |
||
| 484 | * @author The ICU Project |
||
| 485 | * @since 0.11.0 |
||
| 486 | */ |
||
| 487 | protected function handleComputeMonthStart($eyear, $month, $useMonth) |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @see AgaviCalendar::handleComputeJulianDay |
||
| 526 | * |
||
| 527 | * @author Dominik del Bondio <[email protected]> |
||
| 528 | * @author The ICU Project |
||
| 529 | * @since 0.11.0 |
||
| 530 | */ |
||
| 531 | protected function handleComputeJulianDay($bestField) |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @see AgaviCalendar::handleGetMonthLength |
||
| 567 | * |
||
| 568 | * @author Dominik del Bondio <[email protected]> |
||
| 569 | * @author The ICU Project |
||
| 570 | * @since 0.11.0 |
||
| 571 | */ |
||
| 572 | protected function handleGetMonthLength($extendedYear, $month) |
||
| 582 | |||
| 583 | /** |
||
| 584 | * @see AgaviCalendar::handleGetYearLength |
||
| 585 | * |
||
| 586 | * @author Dominik del Bondio <[email protected]> |
||
| 587 | * @author The ICU Project |
||
| 588 | * @since 0.11.0 |
||
| 589 | */ |
||
| 590 | protected function handleGetYearLength($eyear) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Return the length of the given month. |
||
| 597 | * |
||
| 598 | * @param int $month The given month. |
||
| 599 | * |
||
| 600 | * @return int The length of the given month. |
||
| 601 | * |
||
| 602 | * @author Dominik del Bondio <[email protected]> |
||
| 603 | * @author The ICU Project |
||
| 604 | * @since 0.11.0 |
||
| 605 | */ |
||
| 606 | protected function monthLength($month) |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Return the length of the month according to the given year. |
||
| 614 | * |
||
| 615 | * @param int $month The given month. |
||
| 616 | * @param int $year The given year. |
||
| 617 | * |
||
| 618 | * @return int The length of the month. |
||
| 619 | * |
||
| 620 | * @author Dominik del Bondio <[email protected]> |
||
| 621 | * @author The ICU Project |
||
| 622 | * @since 0.11.0 |
||
| 623 | */ |
||
| 624 | protected function monthLength1($month, $year) |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Return the length of the given year. |
||
| 631 | * |
||
| 632 | * @param int $year The given year. |
||
| 633 | * @return int The length of the given year. |
||
| 634 | * |
||
| 635 | * @author Dominik del Bondio <[email protected]> |
||
| 636 | * @author The ICU Project |
||
| 637 | * @since 0.11.0 |
||
| 638 | */ |
||
| 639 | protected function yearLength1($year) |
||
| 643 | |||
| 644 | /** |
||
| 645 | * Return the length of the year field. |
||
| 646 | * |
||
| 647 | * @return int The length of the year field |
||
| 648 | * |
||
| 649 | * @author Dominik del Bondio <[email protected]> |
||
| 650 | * @author The ICU Project |
||
| 651 | * @since 0.11.0 |
||
| 652 | */ |
||
| 653 | protected function yearLength() |
||
| 657 | |||
| 658 | /** |
||
| 659 | * After adjustments such as add(MONTH), add(YEAR), we don't want the |
||
| 660 | * month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar |
||
| 661 | * 3, we want it to go to Feb 28. Adjustments which might run into this |
||
| 662 | * problem call this method to retain the proper month. |
||
| 663 | * |
||
| 664 | * @author Dominik del Bondio <[email protected]> |
||
| 665 | * @author The ICU Project |
||
| 666 | * @since 0.11.0 |
||
| 667 | */ |
||
| 668 | protected function pinDayOfMonth() |
||
| 676 | |||
| 677 | /** |
||
| 678 | * Return the day number with respect to the epoch. |
||
| 679 | * January 1, 1970 (Gregorian) is day zero. |
||
| 680 | * |
||
| 681 | * @return float the day number with respect to the epoch. |
||
| 682 | * |
||
| 683 | * @author Dominik del Bondio <[email protected]> |
||
| 684 | * @author The ICU Project |
||
| 685 | * @since 0.11.0 |
||
| 686 | */ |
||
| 687 | protected function getEpochDay() |
||
| 696 | |||
| 697 | /** |
||
| 698 | * @see AgaviCalendar::handleGetLimit |
||
| 699 | * |
||
| 700 | * @author Dominik del Bondio <[email protected]> |
||
| 701 | * @author The ICU Project |
||
| 702 | * @since 0.11.0 |
||
| 703 | */ |
||
| 704 | protected function handleGetLimit($field, $limitType) |
||
| 708 | |||
| 709 | /** |
||
| 710 | * @see AgaviCalendar::handleGetExtendedYear |
||
| 711 | * |
||
| 712 | * @author Dominik del Bondio <[email protected]> |
||
| 713 | * @author The ICU Project |
||
| 714 | * @since 0.11.0 |
||
| 715 | */ |
||
| 716 | protected function handleGetExtendedYear() |
||
| 746 | |||
| 747 | /** |
||
| 748 | * @see AgaviCalendar::handleGetExtendedYearFromWeekFields |
||
| 749 | * |
||
| 750 | * @author Dominik del Bondio <[email protected]> |
||
| 751 | * @author The ICU Project |
||
| 752 | * @since 0.11.0 |
||
| 753 | */ |
||
| 754 | protected function handleGetExtendedYearFromWeekFields($yearWoy, $woy) |
||
| 763 | |||
| 764 | /** |
||
| 765 | * @see AgaviCalendar::handleComputeFields |
||
| 766 | * |
||
| 767 | * @author Dominik del Bondio <[email protected]> |
||
| 768 | * @author The ICU Project |
||
| 769 | * @since 0.11.0 |
||
| 770 | */ |
||
| 771 | protected function handleComputeFields($julianDay) |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Compute the julian day number of the given year. |
||
| 829 | * |
||
| 830 | * @param bool $isGregorian If true, using Gregorian calendar, otherwise using |
||
| 831 | * Julian calendar. |
||
| 832 | * @param int $year The given year. |
||
| 833 | * @param bool $isLeap True if the year is a leap year. |
||
| 834 | * |
||
| 835 | * @return double |
||
| 836 | * |
||
| 837 | * @author Dominik del Bondio <[email protected]> |
||
| 838 | * @author The ICU Project |
||
| 839 | * @since 0.11.0 |
||
| 840 | */ |
||
| 841 | private static function computeJulianDayOfYear($isGregorian, $year, &$isLeap) |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Validates the values of the set time fields. True if they're all valid. |
||
| 858 | * |
||
| 859 | * @return bool True if the set time fields are all valid. |
||
| 860 | * |
||
| 861 | * @author Dominik del Bondio <[email protected]> |
||
| 862 | * @author The ICU Project |
||
| 863 | * @since 0.11.0 |
||
| 864 | */ |
||
| 865 | private function validateFields() |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Validates the value of the given time field. True if it's valid. |
||
| 906 | * |
||
| 907 | * @param int $value |
||
| 908 | * @param int $field |
||
| 909 | * |
||
| 910 | * @return bool |
||
| 911 | * |
||
| 912 | * @author Dominik del Bondio <[email protected]> |
||
| 913 | * @author The ICU Project |
||
| 914 | * @since 0.11.0 |
||
| 915 | */ |
||
| 916 | private function boundsCheck($value, $field) |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Return the pseudo-time-stamp for two fields, given their |
||
| 923 | * individual pseudo-time-stamps. If either of the fields |
||
| 924 | * is unset, then the aggregate is unset. Otherwise, the |
||
| 925 | * aggregate is the later of the two stamps. |
||
| 926 | * |
||
| 927 | * @param int $stamp_a One given field. |
||
| 928 | * @param int $stamp_b Another given field. |
||
| 929 | * @return int The pseudo-time-stamp for two fields. |
||
| 930 | * |
||
| 931 | * @author Dominik del Bondio <[email protected]> |
||
| 932 | * @author The ICU Project |
||
| 933 | * @since 0.11.0 |
||
| 934 | */ |
||
| 935 | private function aggregateStamp($stamp_a, $stamp_b) |
||
| 942 | |||
| 943 | /** |
||
| 944 | * @var float The point at which the Gregorian calendar rules are used, |
||
| 945 | * measured in milliseconds from the standard epoch. Default |
||
| 946 | * is October 15, 1582 (Gregorian) 00:00:00 UTC, that is, |
||
| 947 | * October 4, 1582 (Julian) is followed by October 15, 1582 |
||
| 948 | * (Gregorian). This corresponds to Julian day number |
||
| 949 | * 2299161. This is measured from the standard epoch, not in |
||
| 950 | * Julian Days. |
||
| 951 | */ |
||
| 952 | private $fGregorianCutover; |
||
| 953 | |||
| 954 | /** |
||
| 955 | * @var int Julian day number of the Gregorian cutover |
||
| 956 | */ |
||
| 957 | private $fCutoverJulianDay; |
||
| 958 | |||
| 959 | /** |
||
| 960 | * @var float Midnight, local time (using this Calendar's TimeZone) |
||
| 961 | * at or before the gregorianCutover. This is a pure |
||
| 962 | * date value with no time of day or timezone component. |
||
| 963 | */ |
||
| 964 | private $fNormalizedGregorianCutover;// = gregorianCutover; |
||
| 965 | |||
| 966 | /** |
||
| 967 | * @var int The year of the gregorianCutover, with 0 representing |
||
| 968 | * 1 BC, -1 representing 2 BC, etc. |
||
| 969 | */ |
||
| 970 | private $fGregorianCutoverYear;// = 1582; |
||
| 971 | |||
| 972 | /** |
||
| 973 | * @var int The year of the gregorianCutover, with 0 representing |
||
| 974 | * 1 BC, -1 representing 2 BC, etc. |
||
| 975 | */ |
||
| 976 | private $fGregorianCutoverJulianDay;// = 2299161; |
||
| 977 | |||
| 978 | /** |
||
| 979 | * Converts time as milliseconds to Julian date. The Julian date used here is |
||
| 980 | * not a true Julian date, since it is measured from midnight, not noon. |
||
| 981 | * |
||
| 982 | * @param float $millis The given milliseconds. |
||
| 983 | * |
||
| 984 | * @return float The Julian date number. |
||
| 985 | * |
||
| 986 | * @author Dominik del Bondio <[email protected]> |
||
| 987 | * @author The ICU Project |
||
| 988 | * @since 0.11.0 |
||
| 989 | */ |
||
| 990 | private static function millisToJulianDay($millis) |
||
| 994 | |||
| 995 | /** |
||
| 996 | * Converts Julian date to time as milliseconds. The Julian date used here is |
||
| 997 | * not a true Julian date, since it is measured from midnight, not noon. |
||
| 998 | * |
||
| 999 | * @param float $julian The given Julian date number. |
||
| 1000 | * |
||
| 1001 | * @return float Time as milliseconds. |
||
| 1002 | * |
||
| 1003 | * @author Dominik del Bondio <[email protected]> |
||
| 1004 | * @author The ICU Project |
||
| 1005 | * @since 0.11.0 |
||
| 1006 | */ |
||
| 1007 | private static function julianDayToMillis($julian) |
||
| 1011 | |||
| 1012 | /** |
||
| 1013 | * @var bool Used by handleComputeJulianDay() and |
||
| 1014 | * handleComputeMonthStart(). Temporary field indicating |
||
| 1015 | * whether the calendar is currently Gregorian as opposed to |
||
| 1016 | * Julian. |
||
| 1017 | */ |
||
| 1018 | private $fIsGregorian; |
||
| 1019 | |||
| 1020 | /** |
||
| 1021 | * @var bool Used by handleComputeJulianDay() and |
||
| 1022 | * handleComputeMonthStart(). Temporary field indicating that |
||
| 1023 | * the sense of the gregorian cutover should be inverted to |
||
| 1024 | * handle certain calculations on and around the cutover |
||
| 1025 | * date. |
||
| 1026 | */ |
||
| 1027 | private $fInvertGregorian; |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * @see AgaviCalendar::haveDefaultCentury |
||
| 1031 | * |
||
| 1032 | * @author Dominik del Bondio <[email protected]> |
||
| 1033 | * @author The ICU Project |
||
| 1034 | * @since 0.11.0 |
||
| 1035 | */ |
||
| 1036 | public function haveDefaultCentury() |
||
| 1040 | |||
| 1041 | /** |
||
| 1042 | * @see AgaviCalendar::defaultCenturyStart |
||
| 1043 | * |
||
| 1044 | * @author Dominik del Bondio <[email protected]> |
||
| 1045 | * @author The ICU Project |
||
| 1046 | * @since 0.11.0 |
||
| 1047 | */ |
||
| 1048 | public function defaultCenturyStart() |
||
| 1052 | |||
| 1053 | /** |
||
| 1054 | * @see AgaviCalendar::defaultCenturyStartYear |
||
| 1055 | * |
||
| 1056 | * @author Dominik del Bondio <[email protected]> |
||
| 1057 | * @author The ICU Project |
||
| 1058 | * @since 0.11.0 |
||
| 1059 | */ |
||
| 1060 | public function defaultCenturyStartYear() |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * @see AgaviCalendar::getType |
||
| 1067 | * |
||
| 1068 | * @author Dominik del Bondio <[email protected]> |
||
| 1069 | * @since 0.11.0 |
||
| 1070 | */ |
||
| 1071 | public function getType() |
||
| 1075 | |||
| 1076 | /** |
||
| 1077 | * @var float The system maintains a static default century start date. |
||
| 1078 | * This is initialized the first time it is used. |
||
| 1079 | * Before then, it is set to SYSTEM_DEFAULT_CENTURY to |
||
| 1080 | * indicate an uninitialized state. Once the system default |
||
| 1081 | * century date and year are set, they do not change. |
||
| 1082 | */ |
||
| 1083 | private static $fgSystemDefaultCenturyStart; |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * @var int See documentation for systemDefaultCenturyStart. |
||
| 1087 | */ |
||
| 1088 | private static $fgSystemDefaultCenturyStartYear = -1; |
||
| 1089 | |||
| 1090 | /** |
||
| 1091 | * @var int Default value that indicates the defaultCenturyStartYear is |
||
| 1092 | * uninitialized |
||
| 1093 | */ |
||
| 1094 | private static $fgSystemDefaultCenturyYear = -1; |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * @var float Default value that indicates the UDate of the beginning |
||
| 1098 | * of the system default century |
||
| 1099 | */ |
||
| 1100 | private static $fgSystemDefaultCentury; |
||
| 1101 | |||
| 1102 | /** |
||
| 1103 | * Returns the beginning date of the 100-year window that dates with 2-digit |
||
| 1104 | * years are considered to fall within. |
||
| 1105 | * |
||
| 1106 | * @return float The beginning date of the 100-year window that dates |
||
| 1107 | * with 2-digit years are considered to fall within. |
||
| 1108 | * |
||
| 1109 | * @author Dominik del Bondio <[email protected]> |
||
| 1110 | * @author The ICU Project |
||
| 1111 | * @since 0.11.0 |
||
| 1112 | */ |
||
| 1113 | private function internalGetDefaultCenturyStart() |
||
| 1127 | |||
| 1128 | /** |
||
| 1129 | * Returns the first year of the 100-year window that dates with 2-digit years |
||
| 1130 | * are considered to fall within. |
||
| 1131 | * |
||
| 1132 | * @return int The first year of the 100-year window that dates with |
||
| 1133 | * 2-digit years are considered to fall within. |
||
| 1134 | * |
||
| 1135 | * @author Dominik del Bondio <[email protected]> |
||
| 1136 | * @author The ICU Project |
||
| 1137 | * @since 0.11.0 |
||
| 1138 | */ |
||
| 1139 | private function internalGetDefaultCenturyStartYear() |
||
| 1153 | |||
| 1154 | /** |
||
| 1155 | * Initializes the 100-year window that dates with 2-digit years are |
||
| 1156 | * considered to fall within so that its start date is 80 years before the |
||
| 1157 | * current time. |
||
| 1158 | * |
||
| 1159 | * @author Dominik del Bondio <[email protected]> |
||
| 1160 | * @author The ICU Project |
||
| 1161 | * @since 0.11.0 |
||
| 1162 | */ |
||
| 1163 | private static function initializeSystemDefaultCentury() |
||
| 1180 | |||
| 1181 | protected static $kNumDays = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334); // 0-based, for day-in-year |
||
| 1182 | protected static $kLeapNumDays = array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335); // 0-based, for day-in-year |
||
| 1183 | protected static $kMonthLength = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // 0-based |
||
| 1184 | protected static $kLeapMonthLength = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); // 0-based |
||
| 1185 | protected static $kGregorianCalendarLimits = array( |
||
| 1186 | // Minimum Greatest Least Maximum |
||
| 1187 | // Minimum Maximum |
||
| 1188 | array( 0, 0, 1, 1 ), // ERA |
||
| 1189 | array( 1, 1, 140742, 144683 ), // YEAR |
||
| 1190 | array( 0, 0, 11, 11 ), // MONTH |
||
| 1191 | array( 1, 1, 52, 53 ), // WEEK_OF_YEAR |
||
| 1192 | array( 0, 0, 4, 6 ), // WEEK_OF_MONTH |
||
| 1193 | array( 1, 1, 28, 31 ), // DAY_OF_MONTH |
||
| 1194 | array( 1, 1, 365, 366 ), // DAY_OF_YEAR |
||
| 1195 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // DAY_OF_WEEK |
||
| 1196 | array( -1, -1, 4, 5 ), // DAY_OF_WEEK_IN_MONTH |
||
| 1197 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // AM_PM |
||
| 1198 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // HOUR |
||
| 1199 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // HOUR_OF_DAY |
||
| 1200 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // MINUTE |
||
| 1201 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // SECOND |
||
| 1202 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // MILLISECOND |
||
| 1203 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // ZONE_OFFSET |
||
| 1204 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // DST_OFFSET |
||
| 1205 | array( -140742, -140742, 140742, 144683 ), // YEAR_WOY |
||
| 1206 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // DOW_LOCAL |
||
| 1207 | array( -140742, -140742, 140742, 144683 ), // EXTENDED_YEAR |
||
| 1208 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // JULIAN_DAY |
||
| 1209 | array(/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1 ), // MILLISECONDS_IN_DAY |
||
| 1210 | ); |
||
| 1211 | } |
||
| 1212 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.