views:

45

answers:

2

I want to get the week number of a particular date , using Zend_Date

My local is setted as English(IN) [en_IN], in Opera browser

I am using the following code

$date = new Zend_Date('22 Mar, 2010', null, Zend_Registry::get('Zend_Locale'));
echo $date->get(Zend_Date::WEEK); //output 12, correct

But if we give a sunday , it will not work correctly

for example

$date = new Zend_Date('21 Mar, 2010', null, Zend_Registry::get('Zend_Locale'));
echo $date->get(Zend_Date::WEEK); //output 11,  not correct

it should output 12

What is wrong with this?

A: 

This should work fine:

$locale = new Zend_Locale('en_IN');
Zend_Registry::set('Zend_Locale', $locale);

$date = new Zend_Date('22 Mar, 2010', null, Zend_Registry::get('Zend_Locale'));
echo $date->get(Zend_Date::WEEK); 

If not, try to determine it directly, using Zend_Locale_Data. Sometimes data provided by Unicode are not exactly as we expect for our region.

takeshin
+1  A: 

For the Locale of English (India), 'en_IN', the first day of the week is Monday. Zend_Date is giving you the correct value.

EDIT: I just did a quick test using the 'en_US' locale, and I'm getting the same behavior. It looks like Zend_Date may be ignoring the locale for this calculation.

$locale = new Zend_Locale('en_US');
Zend_Registry::set('Zend_Locale', $locale);

$date = new Zend_Date('2010-03-22', null, Zend_Registry::get('Zend_Locale'));
echo $date->get(Zend_Date::WEEK); //outputs 12, correct
$date = new Zend_Date('2010-03-21', null, Zend_Registry::get('Zend_Locale'));
echo $date->get(Zend_Date::WEEK); //outputs 11, not correct
Sonny
I also think that Zend_Date may be ignoring the locale for this calculation.
Linto davis