Swat/SwatDate.php
public static function getIntervalFromSeconds($seconds)
    {
        // don't care about micro-seconds.
        $seconds = floor(abs($seconds));

        $minute = 60;
        $hour = $minute * 60;
        $day = $hour * 24;
        $month = $day * 30;
        $year = $day * 365;

        $interval_spec = 'P';

        if ($seconds > $year) {
            $years = floor($seconds / $year);
            $seconds -= $year * $years;
            $interval_spec .= $years . 'Y';
        }

        if ($seconds > $month) {
            $months = floor($seconds / $month);
            $seconds -= $month * $months;
            $interval_spec .= $months . 'M';
        }

        if ($seconds > $day) {
            $days = floor($seconds / $day);
            $seconds -= $day * $days;
            $interval_spec .= $days . 'D';
        }

        if ($seconds > 0 || $interval_spec === 'P') {
            $interval_spec .= 'T';

            if ($seconds > $hour) {
                $hours = floor($seconds / $hour);
                $seconds -= $hour * $hours;
                $interval_spec .= $hours . 'H';
            }

            if ($seconds > $minute) {
                $minutes = floor($seconds / $minute);
                $seconds -= $minute * $minutes;
                $interval_spec .= $minutes . 'M';
            }

            $interval_spec .= $seconds . 'S';
        }

        return new DateInterval($interval_spec);
    }
public static function getIntervalFromSeconds($seconds)
    {
        // don't care about micro-seconds.
        $seconds = floor(abs($seconds));

        $minute = 60;
        $hour = $minute * 60;
        $day = $hour * 24;
        $month = $day * 30;
        $year = $day * 365;

        $interval_spec = 'P';

        if ($seconds > $year) {
            $years = floor($seconds / $year);
            $seconds -= $year * $years;
            $interval_spec .= $years . 'Y';
        }

        if ($seconds > $month) {
            $months = floor($seconds / $month);
            $seconds -= $month * $months;
            $interval_spec .= $months . 'M';
        }

        if ($seconds > $day) {
            $days = floor($seconds / $day);
            $seconds -= $day * $days;
            $interval_spec .= $days . 'D';
        }

        if ($seconds > 0 || $interval_spec === 'P') {
            $interval_spec .= 'T';

            if ($seconds > $hour) {
                $hours = floor($seconds / $hour);
                $seconds -= $hour * $hours;
                $interval_spec .= $hours . 'H';
            }

            if ($seconds > $minute) {
                $minutes = floor($seconds / $minute);
                $seconds -= $minute * $minutes;
                $interval_spec .= $minutes . 'M';
            }

            $interval_spec .= $seconds . 'S';
        }

        return new DateInterval($interval_spec);
    }
public static function getIntervalFromSeconds ( $ seconds ) { // don't care about micro-seconds. $ seconds = floor ( abs ( $ seconds ) ) ; $ minute = 60 ; $ hour = $ minute * 60 ; $ day = $ hour * 24 ; $ month = $ day * 30 ; $ year = $ day * 365 ; $ interval_spec = 'P' ; if ( $ seconds > $ year ) { $ years = floor ( $ seconds / $ year ) ; $ seconds -= $ year * $ years ; $ interval_spec .= $ years . 'Y' ; } if ( $ seconds > $ month ) { $ months = floor ( $ seconds / $ month ) ; $ seconds -= $ month * $ months ; $ interval_spec .= $ months . 'M' ; } if ( $ seconds > $ day ) { $ days = floor ( $ seconds / $ day ) ; $ seconds -= $ day * $ days ; $ interval_spec .= $ days . 'D' ; } if ( $ seconds > 0 || $ interval_spec === 'P' ) { $ interval_spec .= 'T' ; if ( $ seconds > $ hour ) { $ hours = floor ( $ seconds / $ hour ) ; $ seconds -= $ hour * $ hours ; $ interval_spec .= $ hours . 'H' ; } if ( $ seconds > $ minute ) { $ minutes = floor ( $ seconds / $ minute ) ; $ seconds -= $ minute * $ minutes ; $ interval_spec .= $ minutes . 'M' ; } $ interval_spec .= $ seconds . 'S' ; } return new DateInterval ( $ interval_spec ) ; }
Gets a date interval with appropriate values for the specified
number of seconds

As this method applies on seconds, no time zone considerations
are made. Years are assumed to be 365 days. Months are assumed
to be 30 days.

@param integer $seconds seconds for which to get interval.

@return DateInterval a date interval with the relevant parts
set.
Gets a date interval with appropriate values for the specified number of seconds