[Home]WikiPatches/LocalisedCalcDay

UseModWiki | WikiPatches | RecentChanges | Preferences

I wanted CalcDay to return a German Date, so I rewrote it. There is a new global variable $DateFormat? and $NumberedDate? is now useless. This CalcDay accepts in $DateFormat? a similiar format like the POSIX strftime (but only %deBmY?).

Replace the original CalcDay by this:

sub CalcDay {
  my ($ts) = @_;
  my $result = '';

  $ts += $TimeZoneOffset;
  my ($sec, $min, $hour, $mday, $mon, $year) = localtime($ts);
  # similiar to strftime
  while($DateFormat =~ m/([^%]*)%([a-zA-Z%+])/g) {
    $result .= $1;
    if($2 eq '%') {
      $result .= '%'; }
    elsif($2 eq 'd') {
      $result .= sprintf('%02d', $mday); }
    elsif($2 eq 'e') {
      $result .= $mday; }
    elsif($2 eq 'B') {
      $result .= (T('January'), T('February'), T('March'), T('April'), T('May'), T('June'), 
                T('July'), T('August'), T('September'), T('October'), T('November'), T('December'))[$mon]; }
    elsif($2 eq 'm') {
      $result .= ($mon+1); }
    elsif($2 eq 'Y') {
      $result .= ($year+1900); }
  }
  
  $DateFormat =~ m/%[a-zA-Z%+]([^%]*)$/;
  $result .= $1;
  return $result;
}
--FerdinandIhringer?


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited August 27, 2005 3:41 am by FerdinandIhringer (diff)
Search: