From: ndparker <> Date: Mon, 11 Jun 2001 01:57:51 +0000 (+0000) Subject: added system independent German time support X-Git-Url: https://git.p6c8.net/selfforum.git/commitdiff_plain/84497798a93953681eec330e3fc98068adbff4d4?ds=inline added system independent German time support --- diff --git a/selfforum-cgi/shared/Posting/_lib.pm b/selfforum-cgi/shared/Posting/_lib.pm index 886d957..8c1364d 100644 --- a/selfforum-cgi/shared/Posting/_lib.pm +++ b/selfforum-cgi/shared/Posting/_lib.pm @@ -4,7 +4,7 @@ package Posting::_lib; # # # File: shared/Posting/_lib.pm # # # -# Authors: André Malo , 2001-03-03 # +# Authors: André Malo , 2001-06-11 # # Frank Schoenmann , 2001-06-04 # # # # Description: Message access interface, time format routines # @@ -15,6 +15,7 @@ use strict; use Encode::Plain; $Encode::Plain::utf8 = 1; +use Time::German; use XML::DOM; # ==================================================== @@ -481,14 +482,14 @@ sub delete_messages ($) { # # Read and Parse the main file (without any XML-module, they are too slow) # -# Params: $file /path/to/filename of the main file -# $deleted hold deleted (invisible) messages in result (1) oder not (0) -# $sorted direction of message sort: descending (0) (default) or ascending (1) -# Return: scalar context: hash reference +# Params: $file - /path/to/filename of the main file +# $deleted - hold deleted (invisible) messages in result (1) oder not (0) +# $sorted - direction of message sort: descending (0) (default) or ascending (1) +# +# Return: scalar context: hash reference (\%threads) # list context: list (\%threads, $last_thread, $last_message, $dtd, \@unids) # -sub get_all_threads ($$;$) -{ +sub get_all_threads ($$;$) { my ($file, $deleted, $sorted) = @_; my ($last_thread, $last_message, $dtd, @unids, %threads); local (*FILE, $/); @@ -497,8 +498,7 @@ sub get_all_threads ($$;$) my $xml = join '', ; close(FILE) or return; - if (wantarray) - { + if (wantarray) { ($dtd) = $xml =~ //; ($last_thread) = map {/(\d+)/} $xml =~ /]*>/; ($last_message) = map {/(\d+)/} $xml =~ /]*>/; @@ -608,49 +608,56 @@ sub get_all_threads ($$;$) : \%threads; } -########################### -# sub create_forum_xml_string +### create_forum_xml_string () ################################################# +# +# compose main file xml string +# +# Params: $threads - parsed threads (see also 'get_all_threads') +# $params - hashref (see doc for details) +# +# Return: scalarref of the xml string # -# Forumshauptdatei erzeugen -########################### - sub create_forum_xml_string ($$) { my ($threads, $param) = @_; my ($level, $thread, $msg); - my $xml = ''."\n" - .' {dtd}.'">'."\n" - .''; + my $xml = + ''."\n" + . ' {dtd}.'">'."\n" + . ''; - foreach $thread (sort {$b <=> $a} keys %$threads) { + for $thread (sort {$b <=> $a} keys %$threads) { $xml .= ''; $level = -1; - foreach $msg (@{$threads -> {$thread}}) { - $xml .= '' x ($level - $msg -> {level} + 1) if ($msg -> {level} <= $level); + for $msg (@{$threads -> {$thread}}) { + $xml .= '' x ($level - $msg -> {level} + 1) if ($msg -> {level} <= $level); + $level = $msg -> {level}; - $xml .= ' {deleted})?' invisible="1"':'') - .(($msg -> {archive})?' archive="1"':'') - .'>' - .'
' - .'' - .'' - .plain($msg -> {name}) - .'' - .'' - .'' - .'' - .((length $msg -> {cat})?plain($msg -> {cat}):'') - .'' - .'' - .plain($msg -> {subject}) - .'' - .'' - .'
';} + $xml .= + ' {deleted})?' invisible="1"':'') + . (($msg -> {archive})?' archive="1"':'') + . '>' + . '
' + . '' + . '' + . plain($msg -> {name}) + . '' + . '' + . '' + . '' + . ((length $msg -> {cat})?plain($msg -> {cat}):'') + . '' + . '' + . plain($msg -> {subject}) + . '' + . '' + . '
'; + } $xml .= '
' x ($level + 1); $xml .= '
';} @@ -688,64 +695,55 @@ sub save_file ($$) 1; } -# ==================================================== -# Zeitdarstellung -# ==================================================== - -########################### -# sub hr_time +################################################################################ +# +# several time formatting routines +# +# hr_time # 02. Januar 2001, 12:02 Uhr # -# sub short_hr_time +# short_hr_time # 02. 01. 2001, 12:02 Uhr # -# sub long_hr_time +# long_hr_time # Dienstag, 02. Januar 2001, 12:02:01 Uhr # -# formatierte Zeitangabe -########################### +# very_short_hr_time +# 02. 01. 2001 +# +sub month($) { + (qw(Januar Februar), "M\303\244rz", qw(April Mai Juni Juli August September Oktober November Dezember))[shift (@_) - 1]; + # ^^^^^^^^ - UTF8 # +} sub hr_time ($) { - my @month = (qw(Januar Februar), "M\303\244rz", qw(April Mai Juni Juli August September Oktober November Dezember)); - # ^^^^^^^^ - UTF8 # + my (undef, $min, $hour, $day, $mon, $year) = germantime (shift); - my (undef, $min, $hour, $day, $mon, $year) = localtime ($_[0]); - - sprintf ('%02d. %s %04d, %02d:%02d Uhr', $day, $month[$mon], $year+1900, $hour, $min); + sprintf ('%02d. %s %04d, %02d:%02d Uhr', $day, month($mon+1), $year+1900, $hour, $min); } sub short_hr_time ($) { - my (undef, $min, $hour, $day, $mon, $year) = localtime ($_[0]); + my (undef, $min, $hour, $day, $mon, $year) = germantime (shift); sprintf ('%02d. %02d. %04d, %02d:%02d Uhr', $day, $mon+1, $year+1900, $hour, $min); } sub long_hr_time ($) { - my @month = (qw(Januar Februar), "M\303\244rz", qw(April Mai Juni Juli August September Oktober November Dezember)); - # ^^^^^^^^ - UTF8 # - my @wday = qw(Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag); - my ($sek, $min, $hour, $day, $mon, $year, $wday) = localtime ($_[0]); + my ($sek, $min, $hour, $day, $mon, $year, $wday) = germantime (shift); - sprintf ('%s, %02d. %s %04d, %02d:%02d:%02d Uhr', $wday[$wday], $day, $month[$mon], $year+1900, $hour, $min, $sek); + sprintf ('%s, %02d. %s %04d, %02d:%02d:%02d Uhr', $wday[$wday], $day, month($mon+1), $year+1900, $hour, $min, $sek); } sub very_short_hr_time($) { - my (undef, $min, $hour, $day, $mon, $year) = localtime ($_[0]); + my (undef, $min, $hour, $day, $mon, $year) = germantime (shift); sprintf ('%02d. %02d. %04d', $day, $mon+1, $year+1900); } -sub month($) { - my @month = (qw(Januar Februar), "M\303\244rz", qw(April Mai Juni Juli August September Oktober November Dezember)); - # ^^^^^^^^ - UTF8 # - - return $month[$_[0]-1]; -} - -# ==================================================== -# Modulinitialisierung -# ==================================================== - -# making require happy +# keep 'require' happy 1; + +# +# +### end of Posting::_lib ####################################################### diff --git a/selfforum-cgi/shared/Time/German.pm b/selfforum-cgi/shared/Time/German.pm new file mode 100644 index 0000000..52d7153 --- /dev/null +++ b/selfforum-cgi/shared/Time/German.pm @@ -0,0 +1,118 @@ +package Time::German; + +################################################################################ +# # +# File: shared/Time/German.pm # +# # +# Authors: Andre Malo , 2001-06-10 # +# # +# Description: determine time offset German Time <=> GMT (seconds) # +# # +################################################################################ + +use strict; + +################################################################################ +# +# Export +# +use base 'Exporter'; +@Time::German::EXPORT = qw(germantime); + +################################################################################ +# +# german summertime 1980-1995 (ydays) +# +my %summertime = ( + 80 => [96, 271], + 81 => [87, 269], + 82 => [86, 268], + 83 => [85, 267], + 84 => [84, 273], + 85 => [89, 271], + 86 => [88, 270], + 87 => [87, 269], + 88 => [86, 268], + 89 => [84, 266], + 90 => [83, 272], + 91 => [89, 271], + 92 => [88, 270], + 93 => [86, 268], + 94 => [85, 267], + 95 => [84, 266] +); + +### germantime () ############################################################## +# +# like 'localtime', but system independent +# +# Params: $time - time since epoch (GMT) +# +# Return: same as localtime, but german time ;-) +# +sub germantime (;$) { + my $time = shift; + $time = time unless defined $time; + + my ($hour,$mday,$mon,$year,$wday,$yday) = (gmtime($time))[qw(2 3 4 5 6 7)]; + my $offset = 1; + + # 1980 - 1995 + # + if ($summertime{$year}) { + $offset++ if ( + ( + $yday > $summertime{$year} -> [0] and + $yday < $summertime{$year} -> [1] + ) or + ( + $yday == $summertime{$year} -> [0] and + $hour >= 1 + ) or + ( + $yday == $summertime{$year} -> [1] and + $hour <= 1 + ) + ); + } + + # > 1995 + # + elsif ($year > 95) { + # determine last Sunday in March or October + # + my $limit = $mday + int((31-$mday)/7) * 7 - $wday if ($mon == 2 or $mon == 9); + + $offset++ if ( + ( + $mon > 2 and + $mon < 9 + ) or + ( + $mon == 2 and + ( + $mday > $limit or + $mday == $limit and + $hour >= 1 + ) + ) or + ( + $mon == 9 and + ( + $mday < $limit or + $mday == $limit and + $hour <= 1 + ) + ) + ); + } + + return gmtime($time + $offset * 3600); +} + +# keep 'require' happy +1; + +# +# +### end of Time::German ######################################################## \ No newline at end of file