summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/ddate.pm
blob: d081cb5094d56b5030ba54f7504d911785000643 (plain)
  1. #!/usr/bin/perl
  2. # Discordian date support fnord ikiwiki.
  3. package IkiWiki::Plugin::ddate;
  4. use IkiWiki 2.00;
  5. no warnings;
  6. sub import { #{{{
  7. hook(type => "checkconfig", id => "ddate", call => \&checkconfig);
  8. } # }}}
  9. sub checkconfig () { #{{{
  10. if (! defined $config{timeformat} ||
  11. $config{timeformat} eq '%c') {
  12. $config{timeformat}='on %A, the %e of %B, %Y. %N%nCelebrate %H';
  13. }
  14. } #}}}
  15. sub IkiWiki::displaytime ($;$) { #{{{
  16. my $time=shift;
  17. my $format=shift;
  18. if (! defined $format) {
  19. $format=$config{timeformat};
  20. }
  21. eval q{
  22. use DateTime;
  23. use DateTime::Calendar::Discordian;
  24. };
  25. if ($@) {
  26. return "some time or other ($@ -- hail Eris!)";
  27. }
  28. my $dt = DateTime->from_epoch(epoch => $time);
  29. my $dd = DateTime::Calendar::Discordian->from_object(object => $dt);
  30. return $dd->strftime($format);
  31. } #}}}
  32. 5