Skip to content

Commit

Permalink
Improvements to the timed-display usertag
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christensen committed Jun 13, 2011
1 parent ec0c42d commit 1748c01
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions code/UserTag/timed_display.tag
@@ -1,10 +1,19 @@
UserTag timed-display Order start stop UserTag timed-display Order start stop
UserTag timed-display HasEndTag UserTag timed-display HasEndTag
UserTag timed-display AddAttr 1
UserTag timed-display Routine <<EOR UserTag timed-display Routine <<EOR
sub { sub {
my ($start, $stop, $body) = @_; my ($start, $stop, $opt, $body) = @_;


my $now = $Tag->convert_date({ fmt => '%Y%m%d%H%M%S',}); my $tv = $opt->{tv};
my $adjust = $opt->{adjust};
my $currtime = $tv && ($CGI->{$tv} || $Scratch->{$tv});

my $now = $Tag->convert_date({
fmt => '%Y%m%d%H%M',
body => $currtime,
adjust => $adjust,
});
my $else = pull_else($body); my $else = pull_else($body);


if (!$start){ if (!$start){
Expand All @@ -14,19 +23,25 @@ sub {
$stop = '599900010000';#forever or at least after I die. $stop = '599900010000';#forever or at least after I die.
} }


$start = $Tag->convert_date({ fmt => '%Y%m%d%H%M%S', body => $start,}); $start = $Tag->convert_date({
$stop = $Tag->convert_date({ fmt => '%Y%m%d%H%M%S', body => $stop,}); fmt => '%Y%m%d%H%M',

body => $start,
});
$stop = $Tag->convert_date({
fmt => '%Y%m%d%H%M',
body => $stop,
});
return $body if !$start; return $body if !$start;


if ($start < $now and $now < $stop){ if ($start <= $now and $now <= $stop){
return $body; return $body;
} }
else { else {
return $else; return $else;
} }
} }



EOR EOR


UserTag timed-display Documentation <<EOD UserTag timed-display Documentation <<EOD
Expand All @@ -39,10 +54,23 @@ Usage:
Some text/code to display between June 06, 2007 between 8am and Noon. Some text/code to display between June 06, 2007 between 8am and Noon.
[/timed-display] [/timed-display]


For open ended display you can just specify a start date. For open ended display you can just specify a start date. To start
To start immediately and end on a specific date you can just specify a stop date. immediately and end on a specific date you can just specify a stop
date.

The start and stop date use the convert_date tag, so you can use any
format acceptable by that tag to specify your start and stop
dates. (See convert_date documentation for details.)

If the 'timevar' parameter is provided, instead of the current time
look first in the CGI and the Scratch variables with the provided name
for a date string to convert. This allows you to provide a way to
test this behavior outside of the wall-clock time and see the actual
behavior at a specific time.


The start and stop date use the convert_date tag, so you can use any format acceptable by that tag to specify your start and stop dates. (see convert_date documentation) You can also use the 'adjust' parameter, which will pass its argument
directly on to the convert_date calls; this can be used to localize
the timezone relative to the server time.


EOD EOD


Expand Down

0 comments on commit 1748c01

Please sign in to comment.