protected static function dayOfYear($y, $m, $d) {
    $l = ((int)$y % 4 == 0 && (int)$y % 100 != 0) || (int)$y % 400 == 0;
    $k = $l ? 1 : 2;
    $n = intval(275 * (int)$m / 9) -
            $k * intval(((int)$m + 9) / 12) +
            (int)$d - 30;

    return (int)$n;
  }