/** * Sets the GregorianCalendar change date. This is the point when the switch * from Julian dates to Gregorian dates occurred. Default is 00:00:00 local * time, October 15, 1582. Previous to this time and date will be Julian * dates. * * @param float The given Gregorian cutover date. * * @author Dominik del Bondio <*****@*****.**> * @author The ICU Project * @since 0.11.0 */ public function setGregorianChange($date) { $this->fGregorianCutover = $date; // Precompute two internal variables which we use to do the actual // cutover computations. These are the normalized cutover, which is the // midnight at or before the cutover, and the cutover year. The // normalized cutover is in pure date milliseconds; it contains no time // of day or timezone component, and it used to compare against other // pure date values. $cutoverDay = (int) floor($this->fGregorianCutover / AgaviDateDefinitions::MILLIS_PER_DAY); $this->fNormalizedGregorianCutover = $cutoverDay * AgaviDateDefinitions::MILLIS_PER_DAY; // Handle the rare case of numeric overflow. If the user specifies a // change of UDate(Long.MIN_VALUE), in order to get a pure Gregorian // calendar, then the epoch day is -106751991168, which when multiplied // by ONE_DAY gives 9223372036794351616 -- the negative value is too // large for 64 bits, and overflows into a positive value. We correct // this by using the next day, which for all intents is semantically // equivalent. if ($cutoverDay < 0 && $this->fNormalizedGregorianCutover > 0) { $this->fNormalizedGregorianCutover = ($cutoverDay + 1) * AgaviDateDefinitions::MILLIS_PER_DAY; } // Normalize the year so BC values are represented as 0 and negative // values. $cal = new AgaviGregorianCalendar($this->getTimeZone()); $cal->setTime($date); $this->fGregorianCutoverYear = $cal->get(AgaviDateDefinitions::YEAR); if ($cal->get(AgaviDateDefinitions::ERA) == self::BC) { $this->fGregorianCutoverYear = 1 - $this->fGregorianCutoverYear; } $this->fCutoverJulianDay = $cutoverDay; }
/** * Verify that various fields on a known date are set correctly. */ public function testFields060() { $year = 1997; $month = AgaviDateDefinitions::OCTOBER; $dDate = 22; $calendar = new AgaviGregorianCalendar($this->tm, $year, $month, $dDate); $expectedFields = array(AgaviDateDefinitions::YEAR => 1997, AgaviDateDefinitions::MONTH => AgaviDateDefinitions::OCTOBER, AgaviDateDefinitions::DATE => 22, AgaviDateDefinitions::DAY_OF_WEEK => AgaviDateDefinitions::WEDNESDAY, AgaviDateDefinitions::DAY_OF_WEEK_IN_MONTH => 4, AgaviDateDefinitions::DAY_OF_YEAR => 295); foreach ($expectedFields as $field => $value) { $fieldValue = $calendar->get($field); $this->assertEquals($value, (int) $fieldValue); } }