Replace compiled .html with .wml source from the db.d.o cvs repository
[mirror/userdir-ldap-cgi.git] / html / template / ctime.wml
1 #use wml::std::tags
2 #use wml::common_tags
3
4 <bind-gettext-domain domain="date" />
5
6 <perl>
7 use Time::Local;
8
9 @dow = (
10 # List of weekday names (used in modification dates)
11                 '<gettext domain="date">Sun</gettext>',
12                 '<gettext domain="date">Mon</gettext>',
13                 '<gettext domain="date">Tue</gettext>',
14                 '<gettext domain="date">Wed</gettext>',
15                 '<gettext domain="date">Thu</gettext>',
16                 '<gettext domain="date">Fri</gettext>',
17                 '<gettext domain="date">Sat</gettext>'
18 );
19
20 @moy = (
21 # List of month names (used in modification dates, and may be used in news 
22 # listings)
23                 '<gettext domain="date">Jan</gettext>',
24                 '<gettext domain="date">Feb</gettext>',
25                 '<gettext domain="date">Mar</gettext>',
26                 '<gettext domain="date">Apr</gettext>',
27                 '<gettext domain="date">May</gettext>',
28                 '<gettext domain="date">Jun</gettext>',
29                 '<gettext domain="date">Jul</gettext>',
30                 '<gettext domain="date">Aug</gettext>',
31                 '<gettext domain="date">Sep</gettext>',
32                 '<gettext domain="date">Oct</gettext>',
33                 '<gettext domain="date">Nov</gettext>',
34                 '<gettext domain="date">Dec</gettext>'
35 );
36
37 @longmoy = (
38 # List of long month names (may be used in "spoken" dates and date ranges).
39                 '<gettext domain="date">January</gettext>',
40                 '<gettext domain="date">February</gettext>',
41                 '<gettext domain="date">March</gettext>',
42                 '<gettext domain="date">April</gettext>',
43 # The <void> tag is to distinguish short and long forms of May.
44 # Do not put it in msgstr.
45                 '<gettext domain="date"><void id="fullname" />May</gettext>',
46                 '<gettext domain="date">June</gettext>',
47                 '<gettext domain="date">July</gettext>',
48                 '<gettext domain="date">August</gettext>',
49                 '<gettext domain="date">September</gettext>',
50                 '<gettext domain="date">October</gettext>',
51                 '<gettext domain="date">November</gettext>',
52                 '<gettext domain="date">December</gettext>'
53 );
54
55 # $dateform: Date format (sprintf) for modification dates.
56 # Available variables are: $mday = day-of-month, $monnr = month number,
57 # $mon = month string (from @moy), $year = year number.
58 # Percent signs are escaped because they are special during pass 2,
59 # replace all % by [%]
60 $dateform = '<gettext domain="date">q{[%]s, [%]s [%]2d [%]02d:[%]02d:[%]02d [%]s [%]04d}, $wday, $mon, $mday, $hour, $min, $sec, q{UTC}, 1900+$year</gettext>';
61 $dateform =~ s/\[%\]/%/g;
62
63 # $newsdateform: Date format (sprintf) for news items.
64 # Available variables are: $mday = day-of-month, $mon = month number,
65 # $mon_str = month string (from @moy), $year = year number.
66 # Percent signs are escaped because they are special during pass 2,
67 # replace all % by [%]
68 $newsdateform = '<gettext domain="date">q{[%]02d [%]s [%]04d}, $mday, $mon_str, $year</gettext>';
69 $newsdateform =~ s/\[%\]/%/g;
70
71 # $spokendateform: Date format (sprintf) for "spoken" dates
72 # (such as the current release date).
73 # Any special cases (such as the st/nd/rd/th suffixes in English) are
74 # handled in the spokendate subroutine below.
75 # Available variables are: $mday = day-of-month, $mon = month number,
76 # $mon_str = month string (from @longmoy), $year = year number.
77 # Percent signs are escaped because they are special during pass 2,
78 # replace all % by [%]
79 $spokendateform = '<gettext domain="date">q{[%]02d [%]s [%]d}, $mday, $mon_str, $year</gettext>';
80 $spokendateform =~ s/\[%\]/%/g;
81
82 # $spokendateform_noyear: Date format (sprintf) for "spoken" dates
83 # (such as the current release date), without the year.
84 # Any special cases (such as the st/nd/rd/th suffixes in English) are
85 # handled in the spokendate subroutine below.
86 # Available variables are: $mday = day-of-month, $mon = month number,
87 # $mon_str = month string (from @longmoy).
88 # Percent signs are escaped because they are special during pass 2,
89 # replace all % by [%]
90 $spokendateform_noyear = '<gettext domain="date">q{[%]d [%]s}, $mday, $mon_str</gettext>';
91 $spokendateform_noyear =~ s/\[%\]/%/g;
92
93 # $rangeform_samemonth: Date format (sprintf) for date ranges
94 # (used mainly for events pages), for ranges within the same month.
95 # Any special cases (such as the st/nd/rd/th suffixes in English) are
96 # handled in the spokendate subroutine below.
97 # Available variables are: $sday = start day-of-month, $eday = end
98 # day-of-month, $smon = month number, $smon_str = month string (from @longmoy)
99 # Percent signs are escaped because they are special during pass 2,
100 # replace all % by [%]
101 $rangeform_samemonth = '<gettext domain="date">q{[%]d-[%]d [%]s}, $sday, $eday, $smon_str</gettext>';
102 $rangeform_samemonth =~ s/\[%\]/%/g;
103
104 # $rangeform_severalmonths: Date format (sprintf) for date ranges
105 # (used mainly for events pages), for ranges spanning the end of a month.
106 # Any special cases (such as the st/nd/rd/th suffixes in English) are
107 # handled in the spokendate subroutine below.
108 # Available variables are: $sday = start day-of-month, $eday, end
109 # day-of-month, $smon = start month number, $emon = end month number,
110 # $smon_str = start month string (from @longmoy), $emon_str = end month string
111 # Percent signs are escaped because they are special during pass 2,
112 # replace all % by [%]
113 $rangeform_severalmonths = '<gettext domain="date">q{[%]d [%]s-[%]d [%]s}, $sday, $smon_str, $eday, $emon_str</gettext>';
114 $rangeform_severalmonths =~ s/\[%\]/%/g;
115
116
117 # This function creates a last modification time stamp for the web pages.
118 sub webwml_ctime {
119         my ($time, $sec, $min, $hour, $mday, $monnr, $year, $wday, $yday, $isdst, $mon);
120         # The last modification time of inputfile in ISO dd-mm-yyyy hh:mm:ss format.
121         if (defined $(GEN_TIME)) {
122                 $WML_GEN_ISOTIME =~ /(\d+)-(..)-(\d+) (..):(..):(..)/;
123                 if ($1 <= 31) { # for WML 1.x
124                         $time = timelocal($6, $5, $4, $1, $2-1, $3);
125                 } else { # for WML 2.x
126                         $time = timelocal($6, $5, $4, $3, $2-1, $1);
127                 }
128                 # $lday=$1; $lmon=$2; $lyear=$3; $lhr=$4; $lmin=$5; $lsec=$6;
129                 # if ($lyear > 19000) { $lyear = 1900+($lyear-19000); }
130                 # $time = timelocal($lsec, $lmin, $lhr, $lday, $lmon-1, $lyear);
131         }
132         else {
133                 $WML_SRC_ISOTIME =~ /(\d+)-(..)-(\d+) (..):(..):(..)/;
134                 if ($1 <= 31) { # for WML 1.x
135                         $time = timelocal($6, $5, $4, $1, $2-1, $3);
136                 } else { # for WML 2.x
137                         $time = timelocal($6, $5, $4, $3, $2-1, $1);
138                 }
139                 # $lday=$1; $lmon=$2; $lyear=$3; $lhr=$4; $lmin=$5; $lsec=$6;
140                 # if ($lyear > 19000) { $lyear = 1900+($lyear-19000); }
141                 # $time = timelocal($lsec, $lmin, $lhr, $lday, $lmon-1, $lyear);
142         }
143         ($sec, $min, $hour, $mday, $monnr, $year, $wday, $yday, $isdst) = gmtime($time);
144         $wday = $dow[$wday];
145         $mon = $moy[$monnr];
146         return eval("sprintf($dateform)");
147 }
148
149 # This function creates a terse date string for use in news articles.
150 # Input: A date in ISO format (YYYY-MM-DD).
151 sub newsdate {
152         my ($year, $mon, $mday) = split /-/, $_[0];
153         # Make sure the date is in the YYYY-MM-DD format
154         return $_[0] unless $mday;
155         return $_[0] if ($year < 1900);
156
157         # Expand month number to string
158         $mon_str = $moy[$mon - 1];
159
160         # Return translated date
161         return eval("sprintf($newsdateform)");
162 }
163
164 # Utility function for spokendate and daterange: Return the correct order
165 # suffix for a date in English (i.e 24 => "th").
166 sub englishsuffix {
167         my $mday = shift;
168
169         return 'st' if $mday % 10 == 1 && $mday != 11;
170         return 'nd' if $mday % 10 == 2 && $mday != 12;
171         return 'rd' if $mday % 10 == 3 && $mday != 13;
172         return 'th';
173 }
174
175 # Utility function for spokendate and daterange: Contract "de " followed by
176 # a vowel into "d'" for Catalan
177 sub contractcatalan {
178         my $str = shift;
179         $str =~ s/\bde ([aáàeéèiïíoóòuúü])/d'$1/g;
180         return $str;
181 }
182
183 # This function creates a "spoken" date string for use in text, for example
184 # the date of the previous release.
185 # Input: A date in ISO format (YYYY-MM-DD). 
186 sub spokendate {
187         my ($year, $mon, $mday) = split /-/, $_[0];
188         my $appday;
189         # Make sure the date is in the YYYY-MM-DD format
190         return $_[0] unless $mday;
191         return $_[0] if ($year < 1900);
192
193         # Expand month string
194         $mon_str = $longmoy[$mon - 1];
195
196         # Return translated date
197         if ($CUR_ISO_LANG eq "en")
198         {
199                 # Special handling of English: suffix the date with "st", "nd", "rd"
200                 # or "th", according to the numeric date.
201
202                 return sprintf("%s %d%s, %d", $mon_str, $mday, &englishsuffix($mday), $year);
203         }
204         elsif ($CUR_ISO_LANG eq "ca")
205         {
206                 # Special handling of Catalan: "de " followed by a vowel should be
207                 # contracted to "d'" in the spoken date form
208
209                 my $date = sprintf("%d de %s de %d", $mday, $mon_str, $year);
210                 return &contractcatalan($date);
211         }
212         # Add any other special cases here as elsif cases
213         else
214         {
215                 # Return translated date,
216                 return eval("sprintf($spokendateform)");
217         }
218 }
219
220 # This function creates a "spoken" date string for use in text, without the
221 # year.
222 # Input: A date in ISO format (YYYY-MM-DD).
223 sub spokendate_noyear {
224         my (undef, $mon, $mday) = split /-/, $_[0];
225         my $appday;
226
227         # Expand month string
228         $mon_str = $longmoy[$mon - 1];
229
230         # Return translated date
231         if ($CUR_ISO_LANG eq "en")
232         {
233                 # Special handling of English: suffix the date with "st", "nd", "rd"
234                 # or "th", according to the numeric date.
235
236                 return sprintf("%s %d%s", $mon_str, $mday, &englishsuffix($mday));
237         }
238         elsif ($CUR_ISO_LANG eq "ca")
239         {
240                 # Special handling of Catalan: "de " followed by a vowel should be
241                 # contracted to "d'" in the spoken date form
242
243                 my $date = sprintf("%d de %s", $mday, $mon_str);
244                 return &contractcatalan($date);
245         }
246         # Add any other special cases here as elsif cases
247         else
248         {
249                 # Return translated date,
250                 return eval("sprintf($spokendateform_noyear)");
251         }
252 }
253
254 # This function creates a string describing a date range for use in text,
255 # mainly used in the events pages. There are three string forms: One for
256 # one-day ranges, one for ranges inside one month, and one for ranges
257 # covering two months. The year(s) are not used by this function.
258 # Input: Two dates in ISO format (YYYY-MM-DD).
259 sub daterange {
260         my (undef, $smon, $sday) = split /-/, $_[0]; # Start date
261         my (undef, $emon, $eday) = split /-/, $_[1]; # End date
262
263         my $samemonth = $smon == $emon;
264
265         if ($samemonth && $sday == $eday)
266         {
267                 return spokendate_noyear($_[0]); # Single day
268         }
269
270         # Expand month strings
271         $smon_str = $longmoy[$smon - 1];
272         $emon_str = $longmoy[$emon - 1];
273
274         # Return translated date range
275         if ($CUR_ISO_LANG eq "en")
276         {
277                 # Special handling of English: suffix the date with "st", "nd", "rd"
278                 # or "th", according to the numeric date.
279
280                 return sprintf("%s %d%s - %d%s", $smon_str,
281                                $sday, &englishsuffix($sday),
282                                $eday, &englishsuffix($eday))
283                         if $samemonth;
284
285                 return sprintf("%s %d%s - %s %d%s", $smon_str,
286                                $sday, &englishsuffix($sday), $emon_str,
287                                $eday, &englishsuffix($eday))
288         }
289         elsif ($CUR_ISO_LANG eq "ca")
290         {
291                 # Special handling of Catalan: "de " followed by a vowel should be
292                 # contracted to "d'" in the spoken date form
293
294                 my $str;
295                 $str = sprintf("%d-%d de %s", $sday, $eday, $smon_str)
296                         if $samemonth;
297                 $str = sprintf("%d de %s-%d de %s", $sday, $smon_str, $eday, $emon_str)
298                         if !$samemonth;
299
300                 return &contractcatalan($str);
301         }
302         # Add any other special cases here as elsif cases
303         else
304         {
305                 # Return translated range,
306                 return $samemonth ?
307                         eval("sprintf($rangeform_samemonth)") :
308                         eval("sprintf($rangeform_severalmonths)");
309         }
310 }
311 </perl>