On Tue, 21 Mar 2006, Garrett, Philip (MAN-Corporate) wrote:

sub locale_date {
    my ($date,$locale,$time_zone) = @_;
    my $fmt = DateTime::Format::Strptime->new(pattern => '%b %Y',
        locale => $locale, time_zone => $time_zone);
    return $fmt->format_datetime($date); }

$d = DateTime->now;
$str = locale_date($d, 'fr_FR', 'Europe/Paris'); # "Mar 2005"

$d = DateTime->now(locale => 'fr_FR', time_zone => 'Europe/Paris');
$str = locale_date($d, 'fr_FR', 'Europe/Paris'); # "mars 2006"

Is there a way to change this code to use the correct locale for the
formatting, but without modifying the original date? (And without
cloning it -- that's cheating ;-) The locale doesn't seem so much a
property of the date, but of the way it's being presented.

So is cloning really the only way to do this?

I'm afraid so. But that's what the clone api is for. I'm not sure why you're averse to it, it's actually implemented in a way that should be quite fast.


-dave

/*===================================================
VegGuide.Org                        www.BookIRead.com
Your guide to all that's veg.       My book blog
===================================================*/

Reply via email to