From: Crawford C. <cc...@c-...> - 2005-03-24 19:19:41
|
Hi Peter, That was Mario's code, as described on SearchBy Date. I was just tidying up. I put in a die so we wouldn't forget to ask the question you just asked (and which Mario has separately answered). Regards, C. On Thursday 24 March 2005 16:46, Peter Thoeny wrote: > Crawford, > > Is HTTP::Date a standard lib? Do we raise the requirements for env? > > Also, a "die" does not produce a friendly error message to the end > user. > > Can we add the functionality needed to TWiki::Time to avoid this? > > Regards, > Peter > > Cra...@nt... wrote: > > Author: CrawfordCurrie > > Date: 2005-03-24 01:43:47 -0800 (Thu, 24 Mar 2005) > > New Revision: 3860 > > > > Modified: > > twiki/branches/DEVELOP/lib/TWiki/Time.pm > > twiki/branches/DEVELOP/lib/TWiki/UI/View.pm > > Log: > > SearchByDate: eliminated warning, and made require HTTP::Date only if > > really needed. > > > > Modified: twiki/branches/DEVELOP/lib/TWiki/Time.pm > > =================================================================== > > --- twiki/branches/DEVELOP/lib/TWiki/Time.pm 2005-03-24 09:00:54 UTC > > (rev 3859) +++ twiki/branches/DEVELOP/lib/TWiki/Time.pm 2005-03-24 > > 09:43:47 UTC (rev 3860) @@ -35,12 +35,15 @@ > > use TWiki; > > > > # Constants > > -use vars qw( @ISOMONTH @WEEKDAY %MON2NUM ); > > +use vars qw( @ISOMONTH @WEEKDAY @MONTHLENS %MON2NUM ); > > > > @ISOMONTH = > > ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', > > 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ); > > > > +# SMELL: does not account for leap years > > +@MONTHLENS = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); > > + > > @WEEKDAY = > > ( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ); > > > > @@ -272,17 +275,16 @@ > > sub parseInterval{ > > my ($theInterval) = @_; > > > > - use HTTP::Date; > > my @lt = localtime(); > > - my $today = sprintf("%04d-%02d-%02d",$lt[5]+1900, $lt[4]+1, $lt[3]); > > - my $now = $today . sprintf("T%02d:%02d:02d",$lt[2], $lt[1], $lt[0]); > > + my $today = sprintf('%04d-%02d-%02d',$lt[5]+1900, $lt[4]+1, $lt[3]); > > + my $now = $today . sprintf('T%02d:%02d:02d',$lt[2], $lt[1], $lt[0]); > > > > # replace $now and $today shortcuts > > $theInterval =~ s/\$today/$today/g; > > $theInterval =~ s/\$now/$now/g; > > > > # if $theDate does not contain a '/': force it to do so. > > - $theInterval = $theInterval."/".$theInterval unless ($theInterval =~ > > /\// ); + $theInterval = $theInterval.'/'.$theInterval unless > > ($theInterval =~ /\// ); > > > > my @ends = split(/\//, $theInterval); > > > > @@ -291,7 +293,7 @@ > > > > foreach my $i (0,1) { > > # if not a period of time: > > - next if ($ends[$i] =~ "^P"); > > + next if ($ends[$i] =~ /^P/); > > > > # TODO assert(must include the year) > > if($i) { > > @@ -301,8 +303,7 @@ > > # TODO: do we do leap years? > > if (length($ends[$i]) == 7){ > > my $month = substr($ends[$i],5); > > - my @monthLens = (31,28,31,30,31,30,31,31,30,31,30,31); > > - $ends[$i] .= @monthLens[$month-1]; > > + $ends[$i] .= $MONTHLENS[$month-1]; > > } > > $ends[$i] .= > > substr("0000-12-31T23:59:59",length($ends[$i])); } else { > > @@ -314,7 +315,9 @@ > > # convert the string into integer amount of seconds > > # from 1970-01-01T00:00:00.00 UTC > > > > - $ends[$i] = &HTTP::Date::str2time($ends[$i]); > > + require HTTP::Date; > > + die "Cannot find HTTP::Date: $@" if $@; > > + $ends[$i] = HTTP::Date::str2time($ends[$i]); > > } > > > > # now we're ready to translate interval durations... > > @@ -345,9 +348,9 @@ > > # point, it must be added to the previously computed > > # starting point. > > $ends[$i] = eval($ends[1-$i].$oper[$i].$ends[$i]); > > - # in case the user specified both start and end as a > > - # time duration, some kind of error must be reported. > > - } > > + # SMELL: if the user specified both start and end as a > > + # time duration, some kind of error must be reported. > > + } > > return @ends; > > } > > > > > > Modified: twiki/branches/DEVELOP/lib/TWiki/UI/View.pm > > =================================================================== > > --- twiki/branches/DEVELOP/lib/TWiki/UI/View.pm 2005-03-24 09:00:54 UTC > > (rev 3859) +++ twiki/branches/DEVELOP/lib/TWiki/UI/View.pm 2005-03-24 > > 09:43:47 UTC (rev 3860) @@ -190,7 +190,7 @@ > > # disable edit and attach > > # FIXME: won't work with non-default skins, see %EDITURL% > > $tmpl =~ s/%EDITTOPIC%/$mirrorLink.' | '.CGI::strike('Edit')/ge; > > - $tmpl =~ s/<a [^>]*?>Attach<\/a>/CGI::strike('Attach')/gei; > > + $tmpl =~ s/<a [^>]*?>(Attach)<\/a>/CGI::strike($1)/gei; > > if( $topicExists ) { > > # allow view to be indexed > > $indexableView = 1; > > @@ -203,8 +203,8 @@ > > # to use two templates > > # SMELL: won't work with non-default skins, see %EDITURL% > > $tmpl =~ s/%EDITTOPIC%/CGI::strike('Edit')/ge; > > - $tmpl =~ s/<a [^>]*?>(Attach)<\/a>/CGI::strike($1)/gei; > > - $tmpl =~ s!<a [^>]*?>(Rename\/move)</a>!CGI::strike($1)!gei; > > +print STDERR $tmpl; > > + $tmpl =~ > > s/<a\s[^>]*href="[^"]*\/(attach|rename)\b[^>]*>(.*?)<\/a>/CGI::strike($2) > >/gei; $tmpl =~ s/%REVTITLE%/(r$rev)/go; > > $tmpl =~ s/%REVARG%/&rev=$rev/go; > > } else { > > > > ------------------------------------------------------- > > This SF.net email is sponsored by Microsoft Mobile & Embedded DevCon 2005 > > Attend MEDC 2005 May 9-12 in Vegas. Learn more about the latest Windows > > Embedded(r) & Windows Mobile(tm) platforms, applications & content. > > Register by 3/29 & save $300 > > http://ads.osdn.com/?ad_id=6883&alloc_id=15149&op=click > > _______________________________________________ > > TWiki-Dev mailing list > > TWi...@li... > > https://lists.sourceforge.net/lists/listinfo/twiki-dev > > -- > * Peter Thoeny Peter@Thoeny.com > * Is your team already TWiki enabled? http://TWiki.org > * This e-mail is: (_) public (x) ask first (_) private > > > ------------------------------------------------------- > This SF.net email is sponsored by Microsoft Mobile & Embedded DevCon 2005 > Attend MEDC 2005 May 9-12 in Vegas. Learn more about the latest Windows > Embedded(r) & Windows Mobile(tm) platforms, applications & content. > Register by 3/29 & save $300 > http://ads.osdn.com/?ad_id=6883&alloc_id=15149&op=click > _______________________________________________ > TWiki-Dev mailing list > TWi...@li... > https://lists.sourceforge.net/lists/listinfo/twiki-dev -- C-dot Groupware Consultants http://www.c-dot.co.uk |