]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Add a prettydate plugin that formats dates in a more readable fashion.
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Thu, 15 Feb 2007 07:53:04 +0000 (07:53 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Thu, 15 Feb 2007 07:53:04 +0000 (07:53 +0000)
  (I had to get a pretty date somehow today..)

IkiWiki/Plugin/prettydate.pm [new file with mode: 0644]
debian/changelog
doc/plugins/prettydate.mdwn [new file with mode: 0644]
po/ikiwiki.pot

diff --git a/IkiWiki/Plugin/prettydate.pm b/IkiWiki/Plugin/prettydate.pm
new file mode 100644 (file)
index 0000000..1fa5e91
--- /dev/null
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+package IkiWiki::Plugin::prettydate;
+use IkiWiki;
+use warnings;
+use strict;
+
+# Blanks duplicate the time before.
+my $default_timetable=[
+       "late at night on",     # 12
+       "",                     # 1
+       "in the wee hours of",  # 2
+       "",                     # 3
+       "",                     # 4
+       "terribly early in the morning of", # 5
+       "",                     # 6
+       "in early morning on",  # 7
+       "",                     # 8
+       "",                     # 9
+       "in mid-morning of",    # 10
+       "in late morning of",   # 11
+       "at lunch time on",     # 12
+       "",                     # 1
+       "in the afternoon of",  # 2
+       "",                     # 3
+       "",                     # 4
+       "in late afternoon of", # 5
+       "in the evening of",    # 6
+       "",                     # 7
+       "in late evening on",   # 8
+       "",                     # 9
+       "at night on",          # 10
+       "",                     # 11
+];
+
+sub import { #{{{
+       hook(type => "checkconfig", id => "skeleton", call => \&checkconfig);
+} # }}}
+
+sub checkconfig () { #{{{
+       if (! defined $config{prettydateformat} ||
+           $config{prettydateformat} eq '%c') {
+               $config{prettydateformat}='%X %B %o, %Y';
+       }
+
+       if (! ref $config{timetable}) {
+               $config{timetable}=$default_timetable;
+       }
+
+       # Fill in the blanks.
+       for (my $h=0; $h < 24; $h++) {
+               if (! length $config{timetable}[$h]) {
+                       $config{timetable}[$h] = $config{timetable}[$h - 1];
+               }
+       }
+} #}}}
+
+sub IkiWiki::displaytime ($) { #{{{
+       my $time=shift;
+
+       my @t=localtime($time);
+       my ($h, $m)=@t[2, 1];
+       if ($h == 16 && $m < 30) {
+               $time = "at teatime on";
+       }
+       elsif (($h == 0 && $m < 30) || ($h == 23 && $m > 50)) {
+               # well, at 40 minutes it's more like the martian timeslip..
+               $time = "at midnight on";
+       }
+       elsif (($h == 12 && $m < 15) || ($h == 11 && $m > 50)) {
+               $time = "at noon on";
+       }
+       # TODO: sunrise and sunset, but to be right I need to do it based on
+       # lat and long, and calculate the appropriate one for the actual
+       # time of year using Astro::Sunrise. Not tonight, it's wee hours
+       # already..
+       else {
+               $time = $config{timetable}[$h];
+               if (! length $time) {
+                       $time = "sometime";
+               }
+       }
+
+       eval q{use Date::Format};
+       error($@) if $@;
+       my $format=$config{prettydateformat};
+       $format=~s/\%X/$time/g;
+       return strftime($format, \@t);
+} #}}}
+
+1
index 9a58ab43708cc426e24b8370ce936eee45a34593..9d71980e5d36fd8f6260a28e1e271a9ae88b263e 100644 (file)
@@ -23,6 +23,8 @@ ikiwiki (1.43) UNRELEASED; urgency=low
     Inspired by the many ways Moin Moin destroys itself when out of disk. :-)
   * Fix syslogging of errors.
   * Patch from Ethan to allow using meta tags to set creation dates of pages.
+  * Add a prettydate plugin that formats dates in a more readable fashion.
+    (I had to get a pretty date somehow today..)
 
  -- Joey Hess <joeyh@debian.org>  Thu, 15 Feb 2007 00:44:29 -0500
 
diff --git a/doc/plugins/prettydate.mdwn b/doc/plugins/prettydate.mdwn
new file mode 100644 (file)
index 0000000..59fa96d
--- /dev/null
@@ -0,0 +1,18 @@
+[[template id=plugin name=prettydate author="[[Joey]]"]]
+[[tag type/format]]
+
+Enabling this plugin changes the dates displayed on pages in the wiki to
+a format that is nice and easy to read.
+
+The names given to each of the hours in the day can be customised by
+setting the `timetable` configuration variable in ikiwiki's setup file.
+The default value of this configuration value can be seen near the top of
+`prettydate.pm`. Note that hours can be left blank, to make it display the
+same as the hour before. Midnight, noon, and teatime are all hardcoded,
+since they do not occupy the whole hour.
+
+The format used for the date can be customised using the `prettydateformat`
+configuration variable in the setup file. `%X` will be expanded to the
+prettified time value. The default prettydateformat is `"%X %B %o, %Y"`.
+
+This plugin uses the [[cpan TimeDate]] perl module.
index 972319eb8f1e2fcbe5e9dc053ddb0b8a9a3bd9a2..ae31b366bc581b53853b6feaaf53321eb23b1cde 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2007-02-15 00:47-0500\n"
+"POT-Creation-Date: 2007-02-15 02:44-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"