diff options
author | Joey Hess <joey@kitenet.net> | 2012-01-30 15:08:50 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-01-30 15:09:37 -0400 |
commit | a78126c55ecbe014ab2a214f324b32762e6a268d (patch) | |
tree | b8f128ff730f79d9573a867f8af880e0230f0903 /IkiWiki.pm | |
parent | 0ba0d0982455297446ed777aa89d1fbf8989d2ae (diff) | |
download | ikiwiki-a78126c55ecbe014ab2a214f324b32762e6a268d.tar ikiwiki-a78126c55ecbe014ab2a214f324b32762e6a268d.tar.gz |
calendar, prettydate: Fix strftime encoding bug
strftime is a C function, it does not return decoded utf8.
Several places in ikiwiki manually decoded it, but at least two
forgot to.
Also, strftime might not return even encoded utf8, if LC_TIME is set
to a non-utf8 value. Went ahead and supported decoding whatever encoding
it uses.
The remaining direct calls to strftime() are all ones that first set
LC_TIME=C, in order to get times that are not for human display.
Diffstat (limited to 'IkiWiki.pm')
-rw-r--r-- | IkiWiki.pm | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/IkiWiki.pm b/IkiWiki.pm index bc56501da..0a788f35b 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -20,7 +20,7 @@ use Exporter q{import}; our @EXPORT = qw(hook debug error htmlpage template template_depends deptype add_depends pagespec_match pagespec_match_list bestlink htmllink readfile writefile pagetype srcfile pagename - displaytime will_render gettext ngettext urlto targetpage + displaytime strftime_utf8 will_render gettext ngettext urlto targetpage add_underlay pagetitle titlepage linkpage newpagefile inject add_link add_autofile %config %links %pagestate %wikistate %renderedfiles @@ -1148,9 +1148,19 @@ sub formattime ($;$) { $format=$config{timeformat}; } + return strftime_utf8($format, localtime($time)); +} + +my $strftime_encoding; +sub strftime_utf8 { # strftime doesn't know about encodings, so make sure - # its output is properly treated as utf8 - return decode_utf8(POSIX::strftime($format, localtime($time))); + # its output is properly treated as utf8. + # Note that this does not handle utf-8 in the format string. + $strftime_encoding = POSIX::setlocale(&POSIX::LC_TIME) =~ m#\.([^@]+)# + unless defined $strftime_encoding; + $strftime_encoding + ? Encode::decode($strftime_encoding, POSIX::strftime(@_)) + : POSIX::strftime(@_); } sub date_3339 ($) { |