Hi list.  Apologies in advance if the formatting is skewed -- using Outlook web 
access.
 
Is there a way to format dates for a specific locale or time zone without 
actually modifying the DateTime object itself?  For example, if I have a 
function whose job is to return a formatted date, given a DateTime, locale and 
time zone:
 
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.

Thanks,
Philip

Reply via email to