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!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 04:28:17
Script start
Timing: Jan 19 2025 04:28:17
Module start 'layout'
Timing: Jan 19 2025 04:28:17
Module start 'content'
Timing: Jan 19 2025 04:28:18
Module end 'content'
Timing: Jan 19 2025 04:28:18
Script end

Main resources:

Total runtime0.9039 sec
Peak memory usage4,096.0000 KB
Database Queries74

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0106 589.1719152.6250
Module start 'layout' 0.01060.0056 741.796939.4453
Module start 'content' 0.01620.8861 781.2422656.2656
Module end 'content' 0.90240.0015 1,437.507820.1563
Script end 0.9039  1,457.6641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.4285160.0002
Check MTime0.00150.1682160.0001
Mysql Total
Database connection0.00090.095210.0009
Mysqli_queries0.814690.1145740.0110
Looping result0.00070.0816720.0000
Template Total0.859895.120.4299
Template load0.00230.250220.0011
Template processing0.857594.868820.4288
Template load and register function0.00010.014810.0001
states
state_id_array0.00150.165810.0015
state_identifier_array0.00150.171020.0008
Override
Cache load0.00210.2302720.0000
Sytem overhead
Fetch class attribute can translate value0.00050.059030.0002
Fetch class attribute name0.00110.1175110.0001
XML
Image XML parsing0.00340.381630.0011
class_abstraction
Instantiating content class attribute0.00000.0035160.0000
General
dbfile0.00310.3442300.0001
String conversion0.00000.001740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 41
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs