Is there any info on the date - time capabilities of Agavi?
I've managed to get a localised date by doing (in a template): echo
$tm->_d($date);
Can I specify a certain format or can I only use the formats specified
in the locale files? Can I e.g. override the medium format for a locale?
Greetings,
Koen
_______________________________________________
users mailing list
us...@lists.agavi.org
http://lists.agavi.org/mailman/listinfo/users
sure, that's possible, but I have no clue how. Dominik will post a
detailed reply later. He's ze i18n hero.
Cheers,
David
Agavi has its complete own date and time handling supporting dates
ranging from 50000 B.C. to 50000 A.D. in millisecond precision. To
achieve this we ported the calendar part of the ICU Library
(www.icu-project.org) to PHP. Thats the library which handles the
unicode support in php 6 in the background.
Our calendar class supports the most stuff you would expect.
You can create new calendar objects initialized with the current time
using $translation_manager->createCalendar(). The most important methods
of the calendar are set(field, value) and get(field) which should be
used with the constants defined in AgaviDateDefinitions.
$cal = $tm->createCalendar();
$cal->set(AgaviDateDefinitions::MONTH, AgaviDateDefinitions::FEBURARY);
$cal->set(AgaviDateDefinitions::DATE, 7);
$cal->get(AgaviDateDefinitions::DATE); // 7
...
The phpdocs of AgaviCalendar explains the stuff quite well. The most
important methods to look for are get, set, roll, add, before, after and
fieldDifference.
Of course you can define custom formats as well. How the format string
should look like is described in the ldml specification
http://www.unicode.org/reports/tr35/#Date_Format_Patterns
While you _can_ override any format from a locale we have implemented
some better way to do that. You can let the format parameter of the
date_formatter configuration be translated in a custom domain. In
combination with the SimpleTranslator you can therefor define your
different date formats centrally for all languages on the
translation.xml. Note that the result of the translation can be one of
the standard pattern identifiers (short, medium, long, full)
Here is small sample how it should look like
<translator domain="dates">
<message_translator class="AgaviSimpleTranslator">
<parameter name="my_dates">
<parameter name="de_DE">
<parameter name="my_format">dd.MM.yyyy G 'um' HH:mm:ss zzz</parameter>
</parameter>
<parameter name="en_US">
<parameter name="my_format">long</parameter>
</parameter>
</parameter>
</message_translator>
</translator>
<translator domain="default">
<date_formatter translation_domain="dates.my_dates">
<parameters>
<parameter name="type">datetime</parameter>
<parameter name="format">my_format</parameter>
</parameters>
</date_formatter>
</translator>
i hope that helps a bit, if you have any further questions don't
hesitate to ask
regards,
Dominik
Van Daele, Koen wrote:
> Hi,
>
> Is there any info on the date - time capabilities of Agavi?
>
> I've managed to get a localised date by doing (in a template): echo
> $tm->_d($date);
>
> Can I specify a certain format or can I only use the formats specified
> in the locale files? Can I e.g. override the medium format for a locale?
_______________________________________________
Thanks for the info.
It doesn't seem to work completely like this. I'm getting a:
Notice: Object of class AgaviGregorianCalendar could not be converted to
int in /data/projects/agavi/0.11/src/date/AgaviCalendar.class.php on
line 246
The resulting date ends up being a zero-timestamp (01-01-1970). The
formatting does seem to be correct, but maybe i'm calling it wrong?
Right now I do (in a template):
<pre>
<?php
echo $tm->_d(strtotime($date));
?>
</pre>
While I'm at it. Here's another question. For some parts of the app I'd
like to use one format, for others another. Do I have to define domains
for both of them and then decide in the template in which domain the
date should be translated?
Greetings,
Koen
> -----Oorspronkelijk bericht-----
> Van: users-...@lists.agavi.org
> [mailto:users-...@lists.agavi.org] Namens Dominik del Bondio
> Verzonden: donderdag 8 februari 2007 16:11
> Aan: Agavi Users Mailing List
> Onderwerp: Re: [Agavi-Users] Dates
Hi,
it seems an error was introduced in some changes during the weekend,
this patch should resolve the issue:
- ------------------
Index: src/translation/AgaviDateFormatter.class.php
===================================================================
- --- src/translation/AgaviDateFormatter.class.php (revision 1689)
+++ src/translation/AgaviDateFormatter.class.php (working copy)
@@ -115,8 +115,9 @@
}
if(is_int($message)) {
- - $message = $this->context-
>getTranslationManager()->createCalendar($locale);
- - $message->setUnixTimestamp($message);
+ $calendar = $this->context-
>getTranslationManager()->createCalendar($locale);
+ $calendar->setUnixTimestamp($message);
+ $message = $calendar;
} elseif(!($message instanceof AgaviCalendar)) {
// convert unix timestamp to calendar
$message = $this->context-
>getTranslationManager()->createCalendar($message);
- ------------------
see http://trac.agavi.org/ticket/421 for further information.
regards
felix
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)
iD8DBQFF0D4OGLZ/2ixjPUARAoCEAJ9SmPBBWi8JkIhawYxEmY6ISgborQCfY7iV
YaTH10qJ2GpksjH/Eml7b7k=
=a5Tb
-----END PGP SIGNATURE-----
Koen
> -----Oorspronkelijk bericht-----
> Van: users-...@lists.agavi.org
> [mailto:users-...@lists.agavi.org] Namens Felix Gilcher
> Verzonden: maandag 12 februari 2007 11:15
In the latest svn version i added support for supplying extra domains
when using the formatters. So when using my previous configuration
example and $tm->_d($time, 'default.my_extra.stuff'); the translation
domain used to translate the format would be
dates.my_dates.my_extra.stuff (so, i would change the translation_domain
to "dates" and use _d($time, 'default.my_dates'); and add any more
formats to the simple translator
regards,
Dominik
Van Daele, Koen wrote:
> Hi Dominik,
>
>
> While I'm at it. Here's another question. For some parts of the app I'd
> like to use one format, for others another. Do I have to define domains
> for both of them and then decide in the template in which domain the
> date should be translated?
>
it is now possible to nest <translator> tags, no need to specify all
formatters in there. So you don't have to create totally different
domains anymore.
David
RC3 has support for this:
<date_formatter>
<parameter name="format">
<parameter name="nl_BE">d-MMM-yy</parameter>
<parameter name="nl">d MMM yyyy</parameter>
<parameter name="en">M/d/yy</parameter>
</parameter>
</date_formatter>
It falls back to the default for locales where you didn't supply a
format.
This does, of course, also work for <number_formatter> and
<currency_formatter> (very handy in that case because the en_US
locale information we ship has the accounting style pattern for
negative money amounts, with braces, not with a leading minus).
Cheers,
David
P.S: the above patterns are just examples - they're exactly the same
as those for "medium" or "short" in the respective locale definition ;)
That does seem to be the cleanest solution. I'll try it out and let you know if I have any problems.
Koen
> -----Oorspronkelijk bericht-----
> Van: users-...@lists.agavi.org
> [mailto:users-...@lists.agavi.org] Namens David Zülke
> Verzonden: vrijdag 23 februari 2007 3:36
> Aan: Agavi Users Mailing List
> Onderwerp: Re: [Agavi-Users] Dates
>