On Tue, 12 Dec 2005, Philip Garrett wrote:
> Does anyone know of a way to get strftime (or DateTime) to return the
> "appropriate" format for years, regardless whether the locale is in
> Common Era or Buddhist Era?
Just to follow up, I ended up solving this by subclassing DateTime. I
added a "buddhist_era_year" method to my subclass, and just replaced
%{ce_year} with %{buddhist_era_year} in my patterns for the Thai locale.
E.g.
package My::DateTime;
use base qw(DateTime);
sub buddhist_era_year { $_[0]->ce_year + 543 }
# then, in some Thai locale package:
my $pattern = DateTime::Locale->load('th')->long_datetime_format;
$pattern =~ s/ce_year/buddhist_era_year/g;
print My::DateTime->now->strftime($pattern);
All of my application modules use this class instead of using DateTime
directly, so if the current locale happens to be Thai, you'll get years
in B.E.
Philip