/** * Rounds seconds up or down to the nearest specified unit * * @param int $pn_precision number of digits after the decimal point * @param int $pn_day the day of the month * @param int $pn_month the month * @param int $pn_year the year * @param int $pn_hour the hour * @param int $pn_minute the minute * @param mixed $pn_second the second as integer or float * @param bool $pb_countleap whether to count leap seconds (defaults to * DATE_COUNT_LEAP_SECONDS) * * @return array array of year, month, day, hour, minute, second * @access public * @static * @since Method available since Release 1.5.0 */ function roundSeconds($pn_precision, $pn_day, $pn_month, $pn_year, $pn_hour, $pn_minute, $pn_second, $pb_countleap = DATE_COUNT_LEAP_SECONDS) { return Date_Calc::round(DATE_PRECISION_SECOND + $pn_precision, $pn_day, $pn_month, $pn_year, $pn_hour, $pn_minute, $pn_second); }
/** * Rounds the date according to the specified precision (defaults * to nearest day) * * The precision parameter must be one of the following constants: * * <code>DATE_PRECISION_YEAR</code> * <code>DATE_PRECISION_MONTH</code> * <code>DATE_PRECISION_DAY</code> * <code>DATE_PRECISION_HOUR</code> * <code>DATE_PRECISION_10MINUTES</code> * <code>DATE_PRECISION_MINUTE</code> * <code>DATE_PRECISION_10SECONDS</code> * <code>DATE_PRECISION_SECOND</code> * * N.B. the default is DATE_PRECISION_DAY * * The precision can also be specified as an integral offset from * one of these constants, where the offset reflects a precision * of 10 to the power of the offset greater than the constant. * For example: * * <code>DATE_PRECISION_YEAR - 1</code> rounds the date to the nearest 10 * years * <code>DATE_PRECISION_YEAR - 3</code> rounds the date to the nearest 1000 * years * <code>DATE_PRECISION_SECOND + 1</code> rounds the date to 1 decimal * point of a second * <code>DATE_PRECISION_SECOND + 3</code> rounds the date to 3 decimal * points of a second * <code>DATE_PRECISION_SECOND - 1</code> rounds the date to the nearest 10 * seconds (thus it is equivalent to * DATE_PRECISION_10SECONDS) * * @param int $pn_precision a 'DATE_PRECISION_*' constant * @param bool $pb_correctinvalidtime whether to correct, by adding the * local Summer time offset, the rounded * time if it falls in the skipped hour * (defaults to * DATE_CORRECTINVALIDTIME_DEFAULT) * * @return void * @access public * @since Method available since Release 1.5.0 */ function round($pn_precision = DATE_PRECISION_DAY, $pb_correctinvalidtime = DATE_CORRECTINVALIDTIME_DEFAULT) { if ($pn_precision <= DATE_PRECISION_DAY) { list($hn_year, $hn_month, $hn_day, $hn_hour, $hn_minute, $hn_secondraw) = Date_Calc::round($pn_precision, $this->day, $this->month, $this->year, $this->hour, $this->minute, $this->partsecond == 0.0 ? $this->second : $this->second + $this->partsecond, $this->ob_countleapseconds); if (is_float($hn_secondraw)) { $hn_second = intval($hn_secondraw); $hn_partsecond = $hn_secondraw - $hn_second; } else { $hn_second = $hn_secondraw; $hn_partsecond = 0.0; } $this->setLocalTime($hn_day, $hn_month, $hn_year, $hn_hour, $hn_minute, $hn_second, $hn_partsecond, true, $pb_correctinvalidtime); return; } // ($pn_precision >= DATE_PRECISION_HOUR) // if ($this->tz->getDSTSavings() % 3600000 == 0 || $this->tz->getDSTSavings() % 60000 == 0 && $pn_precision >= DATE_PRECISION_MINUTE) { list($hn_year, $hn_month, $hn_day, $hn_hour, $hn_minute, $hn_secondraw) = Date_Calc::round($pn_precision, $this->on_standardday, $this->on_standardmonth, $this->on_standardyear, $this->on_standardhour, $this->on_standardminute, $this->on_standardpartsecond == 0.0 ? $this->on_standardsecond : $this->on_standardsecond + $this->on_standardpartsecond, $this->ob_countleapseconds); if (is_float($hn_secondraw)) { $hn_second = intval($hn_secondraw); $hn_partsecond = $hn_secondraw - $hn_second; } else { $hn_second = $hn_secondraw; $hn_partsecond = 0.0; } $this->setStandardTime($hn_day, $hn_month, $hn_year, $hn_hour, $hn_minute, $hn_second, $hn_partsecond); return; } // Very unlikely anyway (as I write, the only time zone like this // is Lord Howe Island in Australia (offset of half an hour)): // // (This algorithm could be better) // list($hn_year, $hn_month, $hn_day, $hn_hour, $hn_minute, $hn_secondraw) = Date_Calc::round($pn_precision, $this->day, $this->month, $this->year, $this->hour, $this->minute, $this->partsecond == 0.0 ? $this->second : $this->second + $this->partsecond, $this->ob_countleapseconds); if (is_float($hn_secondraw)) { $hn_second = intval($hn_secondraw); $hn_partsecond = $hn_secondraw - $hn_second; } else { $hn_second = $hn_secondraw; $hn_partsecond = 0.0; } $this->setLocalTime($hn_day, $hn_month, $hn_year, $hn_hour, $hn_minute, $hn_second, $hn_partsecond, false, $pb_correctinvalidtime); // This will be right // some of the time // (depends on Summer // time offset) }