Replace compiled .html with .wml source from the db.d.o cvs repository
[mirror/userdir-ldap-cgi.git] / html / template / ctime.wml
diff --git a/html/template/ctime.wml b/html/template/ctime.wml
new file mode 100644 (file)
index 0000000..a5c6950
--- /dev/null
@@ -0,0 +1,311 @@
+#use wml::std::tags
+#use wml::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;
+
+# $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 modification time stamp for the web pages.
+sub webwml_ctime {
+       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.
+       if (defined $(GEN_TIME)) {
+               $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);
+               }
+               # $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);
+       }
+       else {
+               $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)");
+}
+
+# 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;
+}
+
+# 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 $mday;
+       return $_[0] if ($year < 1900);
+
+       # 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, %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>