2 package IkiWiki::Plugin::prettydate;
7 # Blanks duplicate the time before.
8 my $default_timetable=[
9 "late at night on", # 12
11 "in the wee hours of", # 2
14 "terribly early in the morning of", # 5
16 "in early morning on", # 7
19 "in mid-morning of", # 10
20 "in late morning of", # 11
21 "at lunch time on", # 12
23 "in the afternoon of", # 2
26 "in late afternoon of", # 5
27 "in the evening of", # 6
29 "in late evening on", # 8
36 hook(type => "checkconfig", id => "skeleton", call => \&checkconfig);
39 sub checkconfig () { #{{{
40 if (! defined $config{prettydateformat} ||
41 $config{prettydateformat} eq '%c') {
42 $config{prettydateformat}='%X %B %o, %Y';
45 if (! ref $config{timetable}) {
46 $config{timetable}=$default_timetable;
50 for (my $h=0; $h < 24; $h++) {
51 if (! length $config{timetable}[$h]) {
52 $config{timetable}[$h] = $config{timetable}[$h - 1];
57 sub IkiWiki::displaytime ($) { #{{{
60 my @t=localtime($time);
62 if ($h == 16 && $m < 30) {
63 $time = "at teatime on";
65 elsif (($h == 0 && $m < 30) || ($h == 23 && $m > 50)) {
66 # well, at 40 minutes it's more like the martian timeslip..
67 $time = "at midnight on";
69 elsif (($h == 12 && $m < 15) || ($h == 11 && $m > 50)) {
72 # TODO: sunrise and sunset, but to be right I need to do it based on
73 # lat and long, and calculate the appropriate one for the actual
74 # time of year using Astro::Sunrise. Not tonight, it's wee hours
77 $time = $config{timetable}[$h];
83 eval q{use Date::Format};
85 my $format=$config{prettydateformat};
86 $format=~s/\%X/$time/g;
87 return strftime($format, \@t);