public static function getTimePeriodParts($seconds, $interval_parts = null)
    {
        $interval = SwatDate::getIntervalFromSeconds($seconds);

        if ($interval_parts === null) {
            $interval_parts =
                SwatDate::DI_YEARS |
                SwatDate::DI_MONTHS |
                SwatDate::DI_DAYS |
                SwatDate::DI_HOURS |
                SwatDate::DI_MINUTES |
                SwatDate::DI_SECONDS;
        }

        // DateInterval cannot have overflow values for each part, so store
        // these in local variables.
        $years = $interval->y;
        $months = $interval->m;
        $days = $interval->d;
        $hours = $interval->h;
        $minutes = $interval->i;
        $seconds = $interval->s;

        $parts = array();

        if ($years > 0) {
            if ($interval_parts & SwatDate::DI_YEARS) {
                $parts['years'] = $years;
            } else {
                // SwatDate::getIntervalFromSeconds() treats years as 365 days,
                // so convert back to days, not months.
                $days += $years * 365;
            }
        }

        // Since years are converted into days above, when building months,
        // and there are enough days to make at least one month, convert those
        // days into months, and leave the remainder in the days variable.
        if ($months > 0 || $days >= 30) {
            if ($interval_parts & SwatDate::DI_MONTHS) {
                $months += (int) floor($days / 30);
                $days = $days % 30;

                $parts['months'] = $months;
            } else {
                $days += $months * 30;
            }
        }

        if ($days > 0) {
            if ($interval_parts & SwatDate::DI_WEEKS && $days >= 7) {
                $weeks = (int) floor($days / 7);
                $days = $days % 7;

                $parts['weeks'] = $weeks;
            }

            if ($days > 0) {
                if ($interval_parts & SwatDate::DI_DAYS) {
                    $parts['days'] = $days;
                } else {
                    $hours += $days * 24;
                }
            }
        }

        if ($hours > 0) {
            if ($interval_parts & SwatDate::DI_HOURS) {
                $parts['hours'] = $hours;
            } else {
                $minutes += $hours * 60;
            }
        }

        if ($minutes > 0) {
            if ($interval_parts & SwatDate::DI_MINUTES) {
                $parts['minutes'] = $minutes;
            } else {
                $seconds += $minutes * 60;
            }
        }

        if ($seconds > 0) {
            if ($interval_parts & SwatDate::DI_SECONDS) {
                $parts['seconds'] = $seconds;
            }
        }

        return $parts;
    }