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