aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/prettydate.pm
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-02-15 07:53:04 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-02-15 07:53:04 +0000
commit0cfc607314861a240638506741a2cc8fcf1d3b0b (patch)
tree1a9171fccf1eb9198806040e906a6ee1f84e1c14 /IkiWiki/Plugin/prettydate.pm
parentf850acc6ad8a780a6b913df1099b8563647de03d (diff)
downloadikiwiki-0cfc607314861a240638506741a2cc8fcf1d3b0b.tar
ikiwiki-0cfc607314861a240638506741a2cc8fcf1d3b0b.tar.gz
* Add a prettydate plugin that formats dates in a more readable fashion.
(I had to get a pretty date somehow today..)
Diffstat (limited to 'IkiWiki/Plugin/prettydate.pm')
-rw-r--r--IkiWiki/Plugin/prettydate.pm90
1 files changed, 90 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/prettydate.pm b/IkiWiki/Plugin/prettydate.pm
new file mode 100644
index 000000000..1fa5e9144
--- /dev/null
+++ b/IkiWiki/Plugin/prettydate.pm
@@ -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