/** * Calculates the offset of this time zone for a given Julian date. Accounts * for daylight savings time if relevant and based on the date. * * @param float $jd Julian date to check for * @return float Offset in hours including DST (if relevant) */ public function offset($jd) { // Is DST observed for this timezone? If no, return offset as is if ($this->dst == false) { return $this->offset; } // Get YMD for provided JD and day of year number (with fractional day) IAU::Jd2cal($jd, 0, $y, $m, $d, $fd); $dayN = static::dayOfYear($y, $m, $d) + $fd; // DST begins at 2:00 a.m. on the second Sunday of March and... IAU::Cal2jd($y, 3, 1, $djm0, $djm); $dayB = static::dayOfYear($y, 2, 1) + 14 - static::weekDayNum($djm0 + $djm) + 2 / 24; // ...ends at 2:00 a.m. on the first Sunday of November IAU::Cal2jd($y, 11, 1, $djm0, $djm); $dayE = static::dayOfYear($y, 11, 1) + 14 - static::weekDayNum($djm0 + $djm) + 2 / 24; // Check if the given JD falls with in the DST range for that year if ($dayN >= $dayB && $dayN < $dayE) { return $this->offset + 1; } else { return $this->offset; } }
/** * Sets the date for this instance * * @param int $year Year * @param int $month Month * @param int $day Day * @return static */ public function setDate($year, $month, $day) { $status = IAU::Cal2jd((int) $year, (int) $month, (int) $day, $djm0, $djm); $this->checkDate($status); // Check date is valid $this->jd = $djm0 + $djm; // Only set JD, keep day frac to save time return $this; }