Lukas Kahwe Smith wrote:
> Hello,
>
> I am properly overlooking some obvious API call. With format_date() you
> get things nicely i18n'ed, but I need to pass in a format parameter.
> However how do I figure out how to the proper order in the format should be?
>
> In my case I need the following:
> 23-Feb-2007 (Europe)
> Feb-23-2007 (US)
>
> I will happily RTFM with a little pointer :)
After talking to Derick (maintainer of the Date extension in php) it
seems there is no native function to get this information. There will be
in PHP6 most likely. Until then I have added the following helper to my
application:
function is_month_first($culture = null)
{
$culture = is_null($culture) ?
sfContext::getInstance()->getUser()->getCulture() : $culture;
$language = substr($culture, 0, 2);
// lets compute the third day of 1970 just so that there are never
any suprises
$time = 60*60*24*3;
$locale = setlocale(LC_TIME, 0);
setlocale(LC_TIME, $culture, $language,
strtolower(format_language($language, 'en')));
$date = strftime('%x', $time);
$locale = setlocale(LC_TIME, $locale);
// if the first part is 01, 1/, 1. etc .. it will always cast to 1
// denoting that the month does not come first
return (((int)substr($date, 0, 2)) == 1);
}
BTW: I do not know if there is any speed difference, but I think its a
good programming practice to use is_null() rather than === null, which I
saw in the symfony code base.
regards,
Lukas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---