aboutsummaryrefslogtreecommitdiffstats
path: root/english/template/debian/ctime.wml
blob: 1d4263bd5345aa958333452a9dd6edd157643369 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#use wml::std::tags
#use wml::debian::common_tags

<bind-gettext-domain domain="date" />

<perl>
use Time::Local;

@dow = (
# List of weekday names (used in modification dates)
                '<gettext domain="date">Sun</gettext>',
                '<gettext domain="date">Mon</gettext>',
                '<gettext domain="date">Tue</gettext>',
                '<gettext domain="date">Wed</gettext>',
                '<gettext domain="date">Thu</gettext>',
                '<gettext domain="date">Fri</gettext>',
                '<gettext domain="date">Sat</gettext>'
);

@moy = (
# List of month names (used in modification dates, and may be used in news 
# listings)
                '<gettext domain="date">Jan</gettext>',
                '<gettext domain="date">Feb</gettext>',
                '<gettext domain="date">Mar</gettext>',
                '<gettext domain="date">Apr</gettext>',
                '<gettext domain="date">May</gettext>',
                '<gettext domain="date">Jun</gettext>',
                '<gettext domain="date">Jul</gettext>',
                '<gettext domain="date">Aug</gettext>',
                '<gettext domain="date">Sep</gettext>',
                '<gettext domain="date">Oct</gettext>',
                '<gettext domain="date">Nov</gettext>',
                '<gettext domain="date">Dec</gettext>'
);

@longmoy = (
# List of long month names (may be used in "spoken" dates and date ranges).
                '<gettext domain="date">January</gettext>',
                '<gettext domain="date">February</gettext>',
                '<gettext domain="date">March</gettext>',
                '<gettext domain="date">April</gettext>',
# The <void> tag is to distinguish short and long forms of May.
# Do not put it in msgstr.
                '<gettext domain="date"><void id="fullname" />May</gettext>',
                '<gettext domain="date">June</gettext>',
                '<gettext domain="date">July</gettext>',
                '<gettext domain="date">August</gettext>',
                '<gettext domain="date">September</gettext>',
                '<gettext domain="date">October</gettext>',
                '<gettext domain="date">November</gettext>',
                '<gettext domain="date">December</gettext>'
);

# $dateform: Date format (sprintf) for modification dates.
# Available variables are: $mday = day-of-month, $monnr = month number,
# $mon = month string (from @moy), $year = year number.
# Percent signs are escaped because they are special during pass 2,
# replace all % by [%]
$dateform = '<gettext domain="date">q{[%]s, [%]s [%]2d [%]02d:[%]02d:[%]02d [%]s [%]04d}, $wday, $mon, $mday, $hour, $min, $sec, q{UTC}, 1900+$year</gettext>';
$dateform =~ s/\[%\]/%/g;

# $newsdateform: Date format (sprintf) for news items.
# Available variables are: $mday = day-of-month, $mon = month number,
# $mon_str = month string (from @moy), $year = year number.
# Percent signs are escaped because they are special during pass 2,
# replace all % by [%]
$newsdateform = '<gettext domain="date">q{[%]02d [%]s [%]04d}, $mday, $mon_str, $year</gettext>';
$newsdateform =~ s/\[%\]/%/g;

# $spokendateform: Date format (sprintf) for "spoken" dates
# (such as the current release date).
# Any special cases (such as the st/nd/rd/th suffixes in English) are
# handled in the spokendate subroutine below.
# Available variables are: $mday = day-of-month, $mon = month number,
# $mon_str = month string (from @longmoy), $year = year number.
# Percent signs are escaped because they are special during pass 2,
# replace all % by [%]
$spokendateform = '<gettext domain="date">q{[%]02d [%]s [%]d}, $mday, $mon_str, $year</gettext>';
$spokendateform =~ s/\[%\]/%/g;

# $spokendateform_noyear: Date format (sprintf) for "spoken" dates
# (such as the current release date), without the year.
# Any special cases (such as the st/nd/rd/th suffixes in English) are
# handled in the spokendate subroutine below.
# Available variables are: $mday = day-of-month, $mon = month number,
# $mon_str = month string (from @longmoy).
# Percent signs are escaped because they are special during pass 2,
# replace all % by [%]
$spokendateform_noyear = '<gettext domain="date">q{[%]d [%]s}, $mday, $mon_str</gettext>';
$spokendateform_noyear =~ s/\[%\]/%/g;

# $spokendateform_noday: Date format (sprintf) for "spoken" dates
# (such a conference event), without the day.
# Available variables are: $mon = month number,
# $mon_str = month string (from @longmoy), $year = year number.
# Percent signs are escaped because they are special during pass 2,
# replace all % by [%]
$spokendateform_noday = '<gettext domain="date">q{[%]s [%]s}, $mon_str, $year</gettext>';
$spokendateform_noday =~ s/\[%\]/%/g;

# $rangeform_samemonth: Date format (sprintf) for date ranges
# (used mainly for events pages), for ranges within the same month.
# Any special cases (such as the st/nd/rd/th suffixes in English) are
# handled in the spokendate subroutine below.
# Available variables are: $sday = start day-of-month, $eday = end
# day-of-month, $smon = month number, $smon_str = month string (from @longmoy)
# Percent signs are escaped because they are special during pass 2,
# replace all % by [%]
$rangeform_samemonth = '<gettext domain="date">q{[%]d-[%]d [%]s}, $sday, $eday, $smon_str</gettext>';
$rangeform_samemonth =~ s/\[%\]/%/g;

# $rangeform_severalmonths: Date format (sprintf) for date ranges
# (used mainly for events pages), for ranges spanning the end of a month.
# Any special cases (such as the st/nd/rd/th suffixes in English) are
# handled in the spokendate subroutine below.
# Available variables are: $sday = start day-of-month, $eday, end
# day-of-month, $smon = start month number, $emon = end month number,
# $smon_str = start month string (from @longmoy), $emon_str = end month string
# Percent signs are escaped because they are special during pass 2,
# replace all % by [%]
$rangeform_severalmonths = '<gettext domain="date">q{[%]d [%]s-[%]d [%]s}, $sday, $smon_str, $eday, $emon_str</gettext>';
$rangeform_severalmonths =~ s/\[%\]/%/g;

# This function creates a last *built* time stamp for a web page.
sub webwml_built_time {
	my ($sec, $min, $hour, $mday, $monnr, $year, $wday, $yday, $isdst, $mon);
	($sec, $min, $hour, $mday, $monnr, $year, $wday, $yday, $isdst) = gmtime();
	$wday = $dow[$wday];
	$mon = $moy[$monnr];
	return eval("sprintf($dateform)");
}

# This function creates a last *modified* time stamp for the source of a web page.
sub webwml_modified_time {
	my ($time, $sec, $min, $hour, $mday, $monnr, $year, $wday, $yday, $isdst, $mon);
	# The last modification time of inputfile in ISO dd-mm-yyyy hh:mm:ss format.
	$WML_SRC_ISOTIME =~ /(\d+)-(..)-(\d+) (..):(..):(..)/;
	if ($1 <= 31) { # for WML 1.x
	    $time = timelocal($6, $5, $4, $1, $2-1, $3);
	} else { # for WML 2.x
	    $time = timelocal($6, $5, $4, $3, $2-1, $1);
	}
	# $lday=$1; $lmon=$2; $lyear=$3; $lhr=$4; $lmin=$5; $lsec=$6;
	# if ($lyear > 19000) { $lyear = 1900+($lyear-19000); }
	# $time = timelocal($lsec, $lmin, $lhr, $lday, $lmon-1, $lyear);
	($sec, $min, $hour, $mday, $monnr, $year, $wday, $yday, $isdst) = gmtime($time);
	$wday = $dow[$wday];
	$mon = $moy[$monnr];
	return eval("sprintf($dateform)");
}

# creates a timestamp in "W3C Date and Time Format"
# see http://www.w3.org/TR/NOTE-datetime
sub rdf_ctime {
	$WML_GEN_ISOTIME =~ /(\d+)-(..)-(\d+) (..):(..):(..)/;
	if ($1 <= 31) { # for WML 1.x
		$time = timelocal($6, $5, $4, $1, $2-1, $3);
	} else { # for WML 2.x
		$time = timelocal($6, $5, $4, $3, $2-1, $1);
	}
	my ($sec, $min, $hour, $mday, $monnr, $year, $wday, $yday, $isdst) = gmtime($time);
	$year += 1900;
	$monnr += 1;
	return sprintf( "%04d-%02d-%02dT%02d:%02d:%02d+00:00", $year, $monnr, $mday, $hour, $min, $sec );
}

# This function creates a terse date string for use in news articles.
# Input: A date in ISO format (YYYY-MM-DD).
sub newsdate {
	my ($year, $mon, $mday) = split /-/, $_[0];
	# Make sure the date is in the YYYY-MM-DD format
	return $_[0] unless $mday;
	return $_[0] if ($year < 1900);

	# Expand month number to string
	$mon_str = $moy[$mon - 1];

	# Return translated date
	return eval("sprintf($newsdateform)");
}

# Utility function for spokendate and daterange: Return the correct order
# suffix for a date in English (i.e 24 => "th").
sub englishsuffix {
	my $mday = shift;

	return 'st' if $mday % 10 == 1 && $mday != 11;
	return 'nd' if $mday % 10 == 2 && $mday != 12;
	return 'rd' if $mday % 10 == 3 && $mday != 13;
	return 'th';
}

# Utility function for spokendate and daterange: Contract "de " followed by
# a vowel into "d'" for Catalan
sub contractcatalan {
	my $str = shift;
	$str =~ s/\bde ([aáàeéèiïíoóòuúü])/d'$1/g;
	return $str;
}

# Utility function for spokendate and daterange: Return "^er""
# suffix for the first date of month in French.
sub frenchsuffix {
        my $mday = shift;

        return '<sup>er</sup>' if $mday == 1;
}


# This function creates a "spoken" date string for use in text, for example
# the date of the previous release.
# Input: A date in ISO format (YYYY-MM-DD). 
sub spokendate {
	my ($year, $mon, $mday) = split /-/, $_[0];
	my $appday;
	# Make sure the date is in the YYYY-MM-DD format
	return $_[0] unless $mon;
	return $_[0] if ($year < 1900);

	# Expand month string
	$mon_str = $longmoy[$mon - 1];

	return eval("sprintf($spokendateform_noday)") unless $mday;

	# Return translated date
	if ($CUR_ISO_LANG eq "en")
	{
		# Special handling of English: suffix the date with "st", "nd", "rd"
		# or "th", according to the numeric date.

		return sprintf("%s %d%s, %d", $mon_str, $mday, &englishsuffix($mday), $year);
	}
	elsif ($CUR_ISO_LANG eq "ca")
	{
		# Special handling of Catalan: "de " followed by a vowel should be
		# contracted to "d'" in the spoken date form

		my $date = sprintf("%d de %s de %d", $mday, $mon_str, $year);
		return &contractcatalan($date);
	}
	# Add any other special cases here as elsif cases
	else
	{
		# Return translated date,
		return eval("sprintf($spokendateform)");
	}
}

# This function creates a "spoken" date string for use in text, without the
# year.
# Input: A date in ISO format (YYYY-MM-DD).
sub spokendate_noyear {
	my (undef, $mon, $mday) = split /-/, $_[0];
	my $appday;

	# Expand month string
	$mon_str = $longmoy[$mon - 1];

	# Return translated date
	if ($CUR_ISO_LANG eq "en")
	{
		# Special handling of English: suffix the date with "st", "nd", "rd"
		# or "th", according to the numeric date.

		return sprintf("%s %d%s", $mon_str, $mday, &englishsuffix($mday));
	}
	elsif ($CUR_ISO_LANG eq "ca")
	{
		# Special handling of Catalan: "de " followed by a vowel should be
		# contracted to "d'" in the spoken date form

		my $date = sprintf("%d de %s", $mday, $mon_str);
		return &contractcatalan($date);
        }
	# Add any other special cases here as elsif cases
	else
	{
		# Return translated date,
		return eval("sprintf($spokendateform_noyear)");
	}
}

# This function creates a string describing a date range for use in text,
# mainly used in the events pages. There are three string forms: One for
# one-day ranges, one for ranges inside one month, and one for ranges
# covering two months. The year(s) are not used by this function.
# Input: Two dates in ISO format (YYYY-MM-DD).
sub daterange {
	my (undef, $smon, $sday) = split /-/, $_[0]; # Start date
	my (undef, $emon, $eday) = split /-/, $_[1]; # End date

	my $samemonth = $smon == $emon;

	if ($samemonth && $sday == $eday)
	{
		return spokendate_noyear($_[0]); # Single day
	}

	# Expand month strings
	$smon_str = $longmoy[$smon - 1];
	$emon_str = $longmoy[$emon - 1];

	# Return translated date range
	if ($CUR_ISO_LANG eq "en")
	{
		# Special handling of English: suffix the date with "st", "nd", "rd"
		# or "th", according to the numeric date.

		return sprintf("%s %d%s - %d%s", $smon_str,
		               $sday, &englishsuffix($sday),
		               $eday, &englishsuffix($eday))
			if $samemonth;

		return sprintf("%s %d%s - %s %d%s", $smon_str,
		               $sday, &englishsuffix($sday), $emon_str,
		               $eday, &englishsuffix($eday))
	}
	elsif ($CUR_ISO_LANG eq "ca")
	{
		# Special handling of Catalan: "de " followed by a vowel should be
		# contracted to "d'" in the spoken date form

		my $str;
		$str = sprintf("%d-%d de %s", $sday, $eday, $smon_str)
			if $samemonth;
		$str = sprintf("%d de %s-%d de %s", $sday, $smon_str, $eday, $emon_str)
			if !$samemonth;

		return &contractcatalan($str);
	}
	# Add any other special cases here as elsif cases
	else
	{
		# Return translated range,
		return $samemonth ?
			eval("sprintf($rangeform_samemonth)") :
			eval("sprintf($rangeform_severalmonths)");
	}
}
</perl>

© 2014-2024 Faster IT GmbH | imprint | privacy policy