Hello,
there are a couple of things that are still not clear to me, about best practices on how to internationalize an application…
The CDateFormatter provides me the methods format and formatDateTime…
If I have the date in database DATETIME format I’d have something like 2010-06-18 22:30:00 where the date is in YYYY-MM-DD format that it is a valid strtotime format…
So if I want to get this formatted with my locale settings I can just do:
Yii::app()->dateFormatter->format('2010-06-18 22:30:00');
or I can use formatDateTime for get it in a different format (and with this one I can also hide the time part if I want to)
But then let’s say that I want to use the jQuery ui calendar to have the user select another date having the date I’ve read from the db as the current selected date (value param)
Now I get two problems:
1- the jQuery ui calendar date format is different from the one I’ve specified in my locale file
2- if I want to convert back the date from my locale format to database format I should do something like this:
Yii::app()->dateFormatter->formatDateTime('yyyy-MM-dd',$new_date);
where the new date is like ‘18/06/2010’ if I’m using Italian locale…
at this point, if I’m not wrong, since I’m using slashes as date separators, strtotime will read it as a mm/dd/yyyy string instead of a dd/mm/yyyy as it actualy is… …while it reads it as dd/mm/yyyy if I do use the “-” separator (like: 18-06-2010)
So it would be useful to have the DateTime::createFromFormat method but it is only php >= 5.3.0 …
…so… am I missing something? how would you solve points 1 and 2?
thanks.
bye,
Giovanni.
[size="1"]p.s.
once I’ll get more info on this topic I’ll publish an example on the yii playground demo app [/size]