Little help with Zend Date

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

Little help with Zend Date

Razorblade

Hi All,
I have a little problem with Zend Date and date conversion using translated date strings.
Actually I'm doing tests using italian and english locale

If I do:

        $lcode = 'it_IT';
        $value = '11 Aprile 2011';
        $inputFormat = 'dd MMMM yyyy';
        $outputFormat = 'yyyy-MM-dd';

        $locale = new Zend_Locale( $lcode );
        $date = new Zend_Date($value, $inputFormat, $locale);
        echo ucwords( $date->toString( $outputFormat ) );

I get the error: Unable to parse date '11 Aprile 2011' using 'dd MMMM yyyy' (M <> d)

while if I use lowercase date value it works.



If I use english locale and string

        $lcode = 'en_EN';
        $value = '11 april 2011';
        $inputFormat = 'dd MMMM yyyy';
        $outputFormat = 'yyyy-MM-dd';
       
        $locale = new Zend_Locale( $lcode );
        $date = new Zend_Date($value, $inputFormat, $locale);
        echo $date->toString( $outputFormat );

I get the error: Unable to parse date '11 april 2011' using 'dd MMMM yyyy' (M <> d)

while if I use first letter capitalized date value it works.


Is this a normal behaviour? Any advices on how to fix?


Thanks



Sergio Rinaudo


     
Reply | Threaded
Open this post in threaded view
|

Re: Little help with Zend Date

Marco Pivetta
I usually parse such dates with \Zend_Date::DATE_LONG ('FFFF'), works fine
for me...
Marco Pivetta
@Ocramius <http://twitter.com/Ocramius>
http://marco-pivetta.com



On 11 April 2011 13:14, Sergio Rinaudo <[hidden email]> wrote:

>
> Hi All,
> I have a little problem with Zend Date and date conversion using translated
> date strings.
> Actually I'm doing tests using italian and english locale
>
> If I do:
>
>        $lcode = 'it_IT';
>        $value = '11 Aprile 2011';
>        $inputFormat = 'dd MMMM yyyy';
>        $outputFormat = 'yyyy-MM-dd';
>
>        $locale = new Zend_Locale( $lcode );
>        $date = new Zend_Date($value, $inputFormat, $locale);
>        echo ucwords( $date->toString( $outputFormat ) );
>
> I get the error: Unable to parse date '11 Aprile 2011' using 'dd MMMM yyyy'
> (M <> d)
>
> while if I use lowercase date value it works.
>
>
>
> If I use english locale and string
>
>        $lcode = 'en_EN';
>        $value = '11 april 2011';
>        $inputFormat = 'dd MMMM yyyy';
>        $outputFormat = 'yyyy-MM-dd';
>
>        $locale = new Zend_Locale( $lcode );
>        $date = new Zend_Date($value, $inputFormat, $locale);
>        echo $date->toString( $outputFormat );
>
> I get the error: Unable to parse date '11 april 2011' using 'dd MMMM yyyy'
> (M <> d)
>
> while if I use first letter capitalized date value it works.
>
>
> Is this a normal behaviour? Any advices on how to fix?
>
>
> Thanks
>
>
>
> Sergio Rinaudo
>
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Little help with Zend Date

Razorblade
In reply to this post by Razorblade

At the moment I've fixed it using try-catch

Sergio

> From: [hidden email]
> To: [hidden email]
> Date: Mon, 11 Apr 2011 13:14:46 +0200
> Subject: [fw-general] Little help with Zend Date
>
>
> Hi All,
> I have a little problem with Zend Date and date conversion using translated date strings.
> Actually I'm doing tests using italian and english locale
>
> If I do:
>
>         $lcode = 'it_IT';
>         $value = '11 Aprile 2011';
>         $inputFormat = 'dd MMMM yyyy';
>         $outputFormat = 'yyyy-MM-dd';
>
>         $locale = new Zend_Locale( $lcode );
>         $date = new Zend_Date($value, $inputFormat, $locale);
>         echo ucwords( $date->toString( $outputFormat ) );
>
> I get the error: Unable to parse date '11 Aprile 2011' using 'dd MMMM yyyy' (M <> d)
>
> while if I use lowercase date value it works.
>
>
>
> If I use english locale and string
>
>         $lcode = 'en_EN';
>         $value = '11 april 2011';
>         $inputFormat = 'dd MMMM yyyy';
>         $outputFormat = 'yyyy-MM-dd';
>        
>         $locale = new Zend_Locale( $lcode );
>         $date = new Zend_Date($value, $inputFormat, $locale);
>         echo $date->toString( $outputFormat );
>
> I get the error: Unable to parse date '11 april 2011' using 'dd MMMM yyyy' (M <> d)
>
> while if I use first letter capitalized date value it works.
>
>
> Is this a normal behaviour? Any advices on how to fix?
>
>
> Thanks
>
>
>
> Sergio Rinaudo
>
>
>