#use wml::std::tags
#use wml::debian::common_tags
use Time::Local;
@dow = (
# List of weekday names (used in modification dates)
'Sun',
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat'
);
@moy = (
# List of month names (used in modification dates, and may be used in news
# listings)
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
);
@longmoy = (
# List of long month names (may be used in "spoken" dates and date ranges).
'January',
'February',
'March',
'April',
# The tag is to distinguish short and long forms of May.
# Do not put it in msgstr.
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
);
# $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 = 'q{[%]s, [%]s [%]2d [%]02d:[%]02d:[%]02d [%]s [%]04d}, $wday, $mon, $mday, $hour, $min, $sec, q{UTC}, 1900+$year';
$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 = 'q{[%]02d [%]s [%]04d}, $mday, $mon_str, $year';
$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 = 'q{[%]02d [%]s [%]d}, $mday, $mon_str, $year';
$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 = 'q{[%]d [%]s}, $mday, $mon_str';
$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 = 'q{[%]s [%]s}, $mon_str, $year';
$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 = 'q{[%]d-[%]d [%]s}, $sday, $eday, $smon_str';
$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 = 'q{[%]d [%]s-[%]d [%]s}, $sday, $smon_str, $eday, $emon_str';
$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 'er' 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)");
}
}