Thomas Weidner wrote:
> 
>>> It's a regional topic.
>>> For more informations look into unicodes database: 
>>> http://unicode.org/cldr
>>>
>>
>>It a little bit off topic already :)
>>
>>I'm interested in function like:
>>
>>function getFirstDayOfTheWeek($country)
>>...
>>Of course, I can allow user to set this manually,
>>but I'm just looking for sane defaults.
> 
> As written before it's all available within Zend_Locale when you look at
> the 
> token "week".
> 
> And as mentioned in past the first day of week is NOT related to a
> language 
> but to a region. So "en" would not work but "US" would.
> 
> 

Thank you Thomas.
Localization in ZF is great, indeed.

I've been looking in Zend_Locale and Zend_Date,
but the key was Zend_Locale_Data.

I wrote a function I needed:

/**
     * Get localized array of the weekdays, starting from the first day of
the week, depending on region
     *
     * @param string|Zend_Locale $locale Locale with region, e.g. pl_PL
     * @param string|int $format
     * @return array
     */
    public function getWeekdays($locale, $format = null)
    {
        if (is_string($locale)) {
            $locale = new Zend_Locale($locale);
        }

        $days = Zend_Locale_Data::getList($locale, 'days');

        switch ($format) {
            case 'abbreviated':
            case Zend_Date::WEEKDAY_SHORT:
                $daysDisplayed = $days['format']['abbreviated']; // Sun,
Mon, Tue
                break;
            case 'wide':
            case Zend_Date::WEEKDAY_NAME:
                $daysDisplayed = $dayInfo['format']['wide']; // Sunday,
Monday, Tuesday
                break;
            case 'narrow':
            case Zend_Date::WEEKDAY_NARROW:
                $daysDisplayed = $dayInfo['stand-alone']['narrow']; // S, M,
T,
                break;
            default:
                $daysDisplayed = $dayInfo['stand-alone']['narrow']; // 
        }

        $weekInfo = Zend_Locale_Data::getList($locale, 'week');
        $firstDayAbbr = $weekInfo['firstDay'];
        $firstDayNr = (int)$days['format']['narrow'][$firstDayAbbr];

        for ($i=1; $i<$firstDayNr; $i++) {
            $e = array_shift($daysDisplayed);
            array_push($daysDisplayed, $e);
        }

        return array_values($daysDisplayed);
    }

-- 
regards
takeshin
-- 
View this message in context: 
http://n4.nabble.com/Zend-Date-first-day-of-the-week-tp954180p956558.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to