2 package IkiWiki::Plugin::prettydate;
5 no warnings 'redefine';
8 sub default_timetable {
9 # Blanks duplicate the time before.
11 #translators: These descriptions of times of day are used
12 #translators: in messages like "last edited <description>".
13 #translators: %A is the name of the day of the week, while
14 #translators: %A- is the name of the previous day.
15 gettext("late %A- night"), # 12
17 gettext("in the wee hours of %A- night"), # 2
20 gettext("terribly early %A morning"), # 5
22 gettext("early %A morning"), # 7
25 gettext("mid-morning %A"), # 10
26 gettext("late %A morning"), # 11
27 gettext("at lunch time on %A"), # 12
29 gettext("%A afternoon"), # 2
32 gettext("late %A afternoon"), # 5
33 gettext("%A evening"), # 6
35 gettext("late %A evening"), # 8
37 gettext("%A night"), # 10
43 hook(type => "checkconfig", id => "prettydate", call => \&checkconfig);
46 sub checkconfig () { #{{{
47 if (! defined $config{prettydateformat} ||
48 $config{prettydateformat} eq '%c') {
49 $config{prettydateformat}='%X, %B %o, %Y';
52 if (! ref $config{timetable}) {
53 $config{timetable}=default_timetable();
57 for (my $h=0; $h < 24; $h++) {
58 if (! length $config{timetable}[$h]) {
59 $config{timetable}[$h] = $config{timetable}[$h - 1];
64 sub IkiWiki::displaytime ($;$) { #{{{
67 if (! defined $format) {
68 $format=$config{prettydateformat};
71 eval q{use Date::Format};
74 my @t=localtime($time);
75 my ($h, $m, $wday)=@t[2, 1, 6];
77 if ($h == 16 && $m < 30) {
78 $t = gettext("at teatime on %A");
80 elsif (($h == 0 && $m < 30) || ($h == 23 && $m > 50)) {
81 # well, at 40 minutes it's more like the martian timeslip..
82 $t = gettext("at midnight");
84 elsif (($h == 12 && $m < 15) || ($h == 11 && $m > 50)) {
85 $t = gettext("at noon on %A");
87 # TODO: sunrise and sunset, but to be right I need to do it based on
88 # lat and long, and calculate the appropriate one for the actual
89 # time of year using Astro::Sunrise. Not tonight, it's wee hours
92 $t = $config{timetable}[$h];
98 $t=~s{\%A-}{my @yest=@t; $yest[6]--; strftime("%A", \@yest)}eg;
101 return strftime($format, \@t);