summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/ddate.pm
blob: 2ec1228333c591baeb0288cd80f9972efc15b52d (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 => "getsetup", id => "ddate", call => \&getsetup);
  8. hook(type => "checkconfig", id => "ddate", call => \&checkconfig);
  9. } # }}}
  10. sub getsetup { #{{{
  11. return
  12. plugin => {
  13. safe => 1,
  14. rebuild => 1,
  15. },
  16. } #}}}
  17. sub checkconfig () { #{{{
  18. if (! defined $config{timeformat} ||
  19. $config{timeformat} eq '%c') {
  20. $config{timeformat}='on %A, the %e of %B, %Y. %N%nCelebrate %H';
  21. }
  22. } #}}}
  23. sub IkiWiki::displaytime ($;$) { #{{{
  24. my $time=shift;
  25. my $format=shift;
  26. if (! defined $format) {
  27. $format=$config{timeformat};
  28. }
  29. eval q{
  30. use DateTime;
  31. use DateTime::Calendar::Discordian;
  32. };
  33. if ($@) {
  34. return "some time or other ($@ -- hail Eris!)";
  35. }
  36. my $dt = DateTime->from_epoch(epoch => $time);
  37. my $dd = DateTime::Calendar::Discordian->from_object(object => $dt);
  38. return $dd->strftime($format);
  39. } #}}}
  40. 5