Forums / General / Trying to get correct datetime format

Trying to get correct datetime format

Author Message

Massimiliano Bariola

Monday 20 June 2005 10:36:22 am

hi,

I am trying to get datetime fields correctly formatted as epr my regional settings (Italy, set as ita-IT in the Locale parameter of site.ini.append.php)

unfortunately, this line

{attribute_view_gui attribute=$race.object.data_map.data_inizio}

gives me a result like 2005.07.11 instead of 11/07/2005

while the following

{$race.object.data_map.data_inizio.content|l10n('shortdate')}

outputs 01/01/1970 .

Any help?

regards,

MB

Vjeran Vlahovic

Monday 20 June 2005 12:22:29 pm

Hi Massimiliano,

Try this:

{$race.object.data_map.data_inizio.data_int|l10n(shortdate)}

http://www.netgen.hr/eng

Daniel Beyer

Monday 20 June 2005 3:39:04 pm

Take a look to:
http://www.ez.no/ez_publish/documentation/development/libraries/ez_template/operators/miscellaneous

For $timestamp|l10n('shortdate') you can use this, too (instead of 'shortdate'):

-datetime
-shortdatetime
-time
-shorttime
-date
-shortdate

The format of those is defined in your locale config in file /share/local/YOUR-LOCALE.ini.

The reason, why {attribute_view_gui attribute=$race.object.data_map.data_inizio} gives an other output is, that attribute_view_gui uses a template to display results. Take a look to the following templates in folder /design/standard/templates/content/datatype/view:
-ezdate.tpl
-ezdatetime.tpl
-eztime.tpl

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Massimiliano Bariola

Tuesday 21 June 2005 1:20:47 am

Vjeran, Daniel,

I got it sorted thanks to your advice. It's strange, though, that even after setting the locale in my site.ini.append.php, the default output of a locale-dependent datum is not formatted according to the default chosen locale format.

Thanks again!

Daniel Beyer

Tuesday 21 June 2005 4:34:21 am

Hi,

try to add this to /settings/override/site.ini.append.php

[RegionalSettings]
# The primary language for your site
Locale=ita-IT

After that you should get the following formats:
-datetime: Martedì, 21 Giugno 2005 13:39:33
-shortdatetime: 21/06/2005 13:39
-time: 13:39:33
-shorttime: 13:39
-date: Martedì, 21 Giugno 2005
-shortdate: 21/06/2005

Assuming you use the following template-code:

-datetime: {currentdate()|l10n('datetime')} <br />
-shortdatetime: {currentdate()|l10n('shortdatetime')} <br />
-time: {currentdate()|l10n('time')} <br />
-shorttime: {currentdate()|l10n('shorttime')} <br />
-date: {currentdate()|l10n('date')} <br />
-shortdate: {currentdate()|l10n('shortdate')}

If it take long to load your page after you add the code to /settings/override/site.ini.append.php it's because the translations has to be generated. This is a sing that you did not set "Locale=ita-IT" anytime before (since you cleaned you cash last).

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Massimiliano Bariola

Tuesday 21 June 2005 5:34:49 am

Hi Daniel,

I had indeed put the configuration line you suggested in my site.ini.append.php, so I was puzzled to see that eZpublish is not really using that value to implicitly format the relevant datatypes - instead, I must explicitly call the i10n(...) operator.

Daniel Beyer

Tuesday 21 June 2005 7:02:48 am

That's true. You have to call the i10n operator if you want something formated for your locale. It's the same with eg. currencies, too. If you don't want to call the operator you can either change or override the accordant template in your design or formate the date by hand with datetime(custom,"FORMATOPTIONS"). For example:

{$currentdate()|datetime(custom,"%m %y")}

Which will result in:
06 05

You can use for "FORMATOPTIONS" the options mentioned in the date function of php:
http://www.php.net/date

Daniel Beyer
_________________________________
YMC AG
Kreuzlingen, Switzerland
web: www.ymc.ch
____________________________________

Massimiliano Bariola

Tuesday 21 June 2005 7:49:47 am

Well, as long as I know I have to remember to put the i10n I'll be fine ... just wondering whether I was missing something ...

Thanks!