Zend_Date first day of the week

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Date first day of the week

takeshin
Is it possible to get first day of the week
for the specified locale using Zend_Date?
Zend_Date::WEEKDAY_FIRST ?

--
regards
takeshin
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

vince.
Hi,

Try:

date_default_timezone_set('Europe/Berlin');
        $date = new Zend_Date();

        // Output of the current timestamp
        print $date;
        print "<br />";
        print $date->get(Zend_Date::WEEKDAY);

On Mon, Dec 7, 2009 at 9:15 AM, takeshin <[hidden email]> wrote:

Is it possible to get first day of the week
for the specified locale using Zend_Date?
Zend_Date::WEEKDAY_FIRST ?

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



--
Vincent Gabriel.
Lead Developer, Senior Support.
Zend Certified Engineer.
Zend Framework Certified Engineer.
-- Email: [hidden email]
-- Phone: +972-52-3808258
-- Website: http://www.vadimg.com
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

takeshin

vince. wrote
Try:

date_default_timezone_set('Europe/Berlin');
        $date = new Zend_Date();

        // Output of the current timestamp
        print $date;
        print "<br />";
        print $date->get(Zend_Date::WEEKDAY);
Thanks.
I Always forget to set correct timezone…

--
regards
takeshin
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

takeshin
Sorry, but this is not what's I'm asking for.

The question is how to get first day of the week for the specified timezone,
which returns *always* 0 (Sunday) for America
and *always* 1 (Monday) for Poland.

--
regards
takeshin
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

Thomas Weidner
$date->getWeekday(0);

Note that NOT EVERY COUNTRY defines 0 to be sunday... it depends on the
country if 0 is a sunday or another day.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "takeshin" <[hidden email]>
To: <[hidden email]>
Sent: Monday, December 07, 2009 9:51 AM
Subject: Re: [fw-general] Zend_Date first day of the week


>
> Sorry, but this is not what's I'm asking for.
>
> The question is how to get first day of the week for the specified
> timezone,
> which returns *always* 0 (Sunday) for America
> and *always* 1 (Monday) for Poland.
>
> --
> regards
> takeshin
> --
> View this message in context:
> http://n4.nabble.com/Zend-Date-first-day-of-the-week-tp954180p954215.html
> Sent from the Zend Framework mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: [fw-general] Zend_Date first day of the week

takeshin
W dniu 2009-12-07 10:33, Thomas Weidner [via Zend Framework Community]
pisze:
> $date->getWeekday(0);
>
> Note that NOT EVERY COUNTRY defines 0 to be sunday... it depends on the
> country if 0 is a sunday or another day.
>    

Thank you. That's all in the manual.

But, simply put:
How to determine this is '0' should be 0 or other value for specified
locale?

I thought that Zend_Date might provide this information.

I'm creating a calendar. It would be nice, if calendar looked like this:

// for english speaking users
Zend_Locale::setLocale('en');
(0)Sunday, (1)Monday, (2)Tuesday, (3)Wednesday …

// for German speaking users
Zend_Locale::setLocale('de');
(1)Montag, (2)Dienstag, (3)Mittwoch, (4)Donnerstag…

//
Zend_Locale::setLocale('pl');
(1)Poniedziałek, (2)Wtorek, (3)Środa, (4)Czwartek…

--
regards
takeshin




Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

Thomas Weidner

----- Original Message -----
From: "takeshin" <[hidden email]>
To: <[hidden email]>
Sent: Monday, December 07, 2009 3:25 PM
Subject: Re: [fw-general] Zend_Date first day of the week



>> $date->getWeekday(0);
>>
>> Note that NOT EVERY COUNTRY defines 0 to be sunday... it depends on the
>> country if 0 is a sunday or another day.
>>
>
>Thank you. That's all in the manual.

Why have you asked when you knew it and all is within the manual ??

>But, simply put:
>How to determine this is '0' should be 0 or other value for specified
>locale?

Don't rely on "0"...
As said 0 can be sunday or saturday or monday.
But monday is always monday.

>I thought that Zend_Date might provide this information.

It does.

>I'm creating a calendar. It would be nice, if calendar looked like this:
>
>// for english speaking users
>Zend_Locale::setLocale('en');
>(0)Sunday, (1)Monday, (2)Tuesday, (3)Wednesday …
>
>// for German speaking users
>Zend_Locale::setLocale('de');
>(1)Montag, (2)Dienstag, (3)Mittwoch, (4)Donnerstag…
>
>//
>Zend_Locale::setLocale('pl');
>(1)Poniedziałek, (2)Wtorek, (3)Środa, (4)Czwartek…

As said before:
Don't rely on 0 being Sunday.
The 7.December.2009 is always monday regardless of the locale or if the used
calendar format defines 0 to be sunday.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com 

Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

A.J. Brown-3
I think his question is:

"How do I determine (automagically) what the first day of the week is,
for a given LOCALE?"

I think he wants something like this:

Zend_Locale::setLocale( <LOCALE> );
Zend_Date::getFirstWeekday(); // returns 0 for Americas, 1 for Germany



On Mon, Dec 7, 2009 at 11:07 AM, Thomas Weidner <[hidden email]> wrote:

>
> ----- Original Message ----- From: "takeshin" <[hidden email]>
> To: <[hidden email]>
> Sent: Monday, December 07, 2009 3:25 PM
> Subject: Re: [fw-general] Zend_Date first day of the week
>
>
>
>>> $date->getWeekday(0);
>>>
>>> Note that NOT EVERY COUNTRY defines 0 to be sunday... it depends on the
>>> country if 0 is a sunday or another day.
>>>
>>
>> Thank you. That's all in the manual.
>
> Why have you asked when you knew it and all is within the manual ??
>
>> But, simply put:
>> How to determine this is '0' should be 0 or other value for specified
>> locale?
>
> Don't rely on "0"...
> As said 0 can be sunday or saturday or monday.
> But monday is always monday.
>
>> I thought that Zend_Date might provide this information.
>
> It does.
>
>> I'm creating a calendar. It would be nice, if calendar looked like this:
>>
>> // for english speaking users
>> Zend_Locale::setLocale('en');
>> (0)Sunday, (1)Monday, (2)Tuesday, (3)Wednesday ...
>>
>> // for German speaking users
>> Zend_Locale::setLocale('de');
>> (1)Montag, (2)Dienstag, (3)Mittwoch, (4)Donnerstag...
>>
>> //
>> Zend_Locale::setLocale('pl');
>> (1)Poniedziałek, (2)Wtorek, (3)Środa, (4)Czwartek...
>
> As said before:
> Don't rely on 0 being Sunday.
> The 7.December.2009 is always monday regardless of the locale or if the used
> calendar format defines 0 to be sunday.
>
> Greetings
> Thomas Weidner, I18N Team Leader, Zend Framework
> http://www.thomasweidner.com
>



--
A.J. Brown
web | http://ajbrown.org
phone | (937) 660-3969
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

takeshin

A.J. Brown-3 wrote
I think his question is:

"How do I determine (automagically) what the first day of the week is,
for a given LOCALE?"

I think he wants something like this:

Zend_Locale::setLocale( <LOCALE> );
Zend_Date::getFirstWeekday(); // returns 0 for Americas, 1 for Germany
Yes. Thank you for helping me to precise the question.
Sorry for not being eloquent enough.

Correct me if I'm wrong,
but I think it's currently not possible with Zend_Date.

I looked into Zend/Locale/Data xmls,
but among lots of options there is no: <firstWorkDayOfTheWeek>
or anything similar to this.

BTW, Is it cultural / religion related/ local law  related topic?
For instance, see this article: http://www.cjvlang.com/Dow/SunMon.html

--
regards
takeshin
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

Thomas Weidner

----- Original Message -----
From: "takeshin" <[hidden email]>
To: <[hidden email]>
Sent: Monday, December 07, 2009 10:31 PM
Subject: Re: [fw-general] Zend_Date first day of the week


>
>
>
> A.J. Brown-3 wrote:
>>
>> I think his question is:
>>
>> "How do I determine (automagically) what the first day of the week is,
>> for a given LOCALE?"
>>
>> I think he wants something like this:
>>
>> Zend_Locale::setLocale( <LOCALE> );
>> Zend_Date::getFirstWeekday(); // returns 0 for Americas, 1 for Germany
>>
>
> Yes. Thank you for helping me to precise the question.
> Sorry for not being eloquent enough.
>
> Correct me if I'm wrong,
> but I think it's currently not possible with Zend_Date.

It is possible.
But your expectations are wrong. ;-)

> I looked into Zend/Locale/Data xmls,
> but among lots of options there is no: <firstWorkDayOfTheWeek>
> or anything similar to this.

Then take a deeper look into "week".

> BTW, Is it cultural / religion related/ local law  related topic?
> For instance, see this article: http://www.cjvlang.com/Dow/SunMon.html

It's a regional topic.
For more informations look into unicodes database: http://unicode.org/cldr

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

takeshin

Thomas Weidner wrote
It is possible.
But your expectations are wrong. ;-)
No comprendo, Senior ;)

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)
{

switch ($coutry) {
case 'pl':
case 'de':
case 'cz':
case other... (where to find the other?)
   return 1;
case some arabic…
case some jewish…
   return 6;
case some exotic ones:
   return (2 ÷ 5)

default:
 return 0;
}

}

Of course, I can allow user to set this manually,
but I'm just looking for sane defaults.

--
regards
takeshin
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

Thomas Weidner
>> 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.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com 

Reply | Threaded
Open this post in threaded view
|

Re: Zend_Date first day of the week

takeshin

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