I see, right way would be :

$date = new Zend_Date(null, null, $locale);
$date->setTimestamp(1256198496);
echo $date->toString(Zend_Date::DATES);

Big thanks Thomas!

Regards,
Saša Stamenković


On Wed, Nov 11, 2009 at 12:06 PM, Thomas Weidner <thomas.weid...@gmx.at>wrote:

> Looks like you didn't use my piece of code to reproduce the problem:
>>
>
> Look like you did not output all date parts.
> Why should I use your code when it's obviously wrong ?
>
> You set the actual date with time, timezone and DST.
> F.e. 2009-11-11 05:00:00+02:00
>
> Then you set a timestamp overwriting the previous date and time but leaving
> timezone and DST.
> This leads to 2009-10-22 10:01:36+02:00.
>
> Then you cut of the time from the instance but still using DST.
>
> Reason:
> You used getDate - this strips the time and returns ONLY date
> 2009-10-22 10:01:36+02:00 -> before
> 2009-10-22 00:00:00 (+02:00->trunking time internally by getDate())
> 2009-10-21 22:00:00 (+00:00-> trunking timezone and DST)
> 2009-10-21 23:00:00 (+01:00 -> trunking DST only by getDate() as a pure
> date without time can not have DST, but adding timezone as it is locale
> dependend, this value is set)
>
> Your problem is that you are mixing date only calculation with date/time
> calculation. By stripping parts in the middle of your calculation you get
> unexpected behaviour.
>
> Why don't you set the time to 0 (setTime() instead of getDate()) or simply
> use the instance as is and output the date only
> (toString(Zend_Date::DATES))?
>
>
> Greetings
> Thomas Weidner, I18N Team Leader, Zend Framework
> http://www.thomasweidner.com
>
> ----- Original Message ----- From: "Саша Стаменковић" <umpir...@gmail.com>
> To: "Thomas Weidner" <thomas.weid...@gmx.at>
> Cc: <fw-general@lists.zend.com>
> Sent: Wednesday, November 11, 2009 9:44 AM
>
> Subject: Re: [fw-general] Zend_Date problem
>
>
> Looks like you didn't use my piece of code to reproduce the problem:
>
> $date = new Zend_Date(null, null, $locale);
> $date->setTimestamp(1256198496);
> echo $date->getDate()->toString(Zend_Date::DATES);
>
> Using this:
>
> $date = new Zend_Date(null, null, $locale);
> $date->setTimestamp(1256198496);
> echo $date->getDate()->toString();
>
> I get
>
> 21 Oct 2009 23:00:00
>
> which is again wrong.
>
> If I understand well, Zend_Date is determining which timezone to use by
> locale passed in constructor. But by looking in constructor docblock I
> figured that it's read from PHP
>
> /**
>    * Generates the standard date object, could be a unix timestamp,
> localized date,
>    * string, integer, array and so on. Also parts of dates or time are
> supported
>    * Always set the default timezone:
> http://php.net/date_default_timezone_set
>    * For example, in your bootstrap:
> date_default_timezone_set('America/Los_Angeles');
>    * For detailed instructions please look in the docu.
>    *
>    * @param  string|integer|Zend_Date|array  $date    OPTIONAL Date value
> or value of date part to set
>    *                                                 ,depending on $part.
> If null the actual time is set
>    * @param  string                          $part    OPTIONAL Defines the
> input format of $date
>    * @param  string|Zend_Locale              $locale  OPTIONAL Locale for
> parsing input
>    * @return Zend_Date
>    * @throws Zend_Date_Exception
>    */
>   public function __construct($date = null, $part = null, $locale = null)
>
> and in line #184 it's obvious
>
> // set the timezone and offset for $this
> $zone = @date_default_timezone_get();
> $this->setTimezone($zone);
>
> I use zf 1.9.5.
>
> Regards,
> Saša Stamenković
>
>
> On Wed, Nov 11, 2009 at 9:32 AM, Thomas Weidner <thomas.weid...@gmx.at
> >wrote:
>
>  Creating the instance affects the timezone.
>> Using set methods affect the timezone.
>> The manual states multiple ways (more than 20?) to affect the timezone.
>>
>> In the code you gave the locale affects the timezone.
>> And we still don't know how your complete date looks like.
>> So all we can do is prediction.
>>
>> And using your code on both locales I get:
>> sr_RS: string '2009-10-22T10:01:36+02:00' (length=25)
>> en_GB:string '2009-10-22T10:01:36+02:00' (length=25)
>>
>>
>> Greetings
>> Thomas Weidner, I18N Team Leader, Zend Framework
>> http://www.thomasweidner.com
>>
>> ----- Original Message ----- From: "Саша Стаменковић" <umpir...@gmail.com
>> >
>> To: "Thomas Weidner" <thomas.weid...@gmx.at>
>>
>> Cc: <fw-general@lists.zend.com>
>> Sent: Wednesday, November 11, 2009 8:47 AM
>>
>> Subject: Re: [fw-general] Zend_Date problem
>>
>>
>> How do I set timezone to affect Zend_Date component?
>> I use zend date to create view helper for date formatting.
>>
>> Regards,
>> Saša Stamenković
>>
>>
>> On Wed, Nov 11, 2009 at 8:21 AM, Thomas Weidner <thomas.weid...@gmx.at
>> >wrote:
>>
>>  Sorry, but date_default_timezone_set has no effect on the timezone which
>>
>>> is
>>> actually used by the instance of Zend_Date nor has it effect on DST.
>>> My question was related to the instance not your environment.
>>>
>>> Why don't you output all dateparts from the instance instead of giving
>>> partitial informations ?
>>>
>>> Greetings
>>> Thomas Weidner, I18N Team Leader, Zend Framework
>>> http://www.thomasweidner.com
>>>
>>> ----- Original Message ----- From: "Саша Стаменковић" <
>>> umpir...@gmail.com
>>> >
>>> To: "kobsu" <ko...@iki.fi>
>>> Cc: <fw-general@lists.zend.com>
>>> Sent: Wednesday, November 11, 2009 7:59 AM
>>> Subject: Re: [fw-general] Zend_Date problem
>>>
>>>
>>>
>>> @Thomas Weidner
>>> *
>>> *
>>> date_default_timezone_set('Europe/Stockholm'); is in bootstrap.
>>>
>>> @kobsu
>>> *
>>> *
>>> *Same result :(
>>> *
>>> Regards,
>>> Saša Stamenković
>>>
>>>
>>> On Tue, Nov 10, 2009 at 6:20 PM, kobsu <ko...@iki.fi> wrote:
>>>
>>>
>>>  Try
>>>
>>>> Zend_Date::setOptions(array('fix_dst' => true));
>>>>
>>>> before
>>>> $date = new Zend_Date();
>>>>
>>>>
>>>> umpirsky wrote:
>>>> >
>>>> > Hi zf community.
>>>> >
>>>> > This code:
>>>> >
>>>> > $date = new Zend_Date(null, null, $locale);
>>>> > $date->setTimestamp(1256198496);
>>>> > echo $date->getDate()->toString(Zend_Date::DATES);
>>>> >
>>>> > gives date 21.10.2009. for sr_RS locale (similar for other locales), >
>>>> for
>>>> > en_GB it gives 21 Oct 2009.
>>>> > I expect 22 Oct 2009. it's whole day missed?!?!?
>>>> >
>>>> > Any idea?
>>>> >
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Zend_Date-problem-tp26283342p26287337.html
>>>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>
>

Reply via email to