Skip to content
Browse files

Improvements to the timed-display usertag

  • Loading branch information...
1 parent ec0c42d commit 1748c01907b5974f9f6f346a226bd2a1c4838d36 @machack666 machack666 committed Jun 12, 2011
Showing with 38 additions and 10 deletions.
  1. +38 −10 code/UserTag/timed_display.tag
View
48 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 AddAttr 1
UserTag timed-display Routine <<EOR
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);
if (!$start){
@@ -14,19 +23,25 @@ sub {
$stop = '599900010000';#forever or at least after I die.
}
- $start = $Tag->convert_date({ fmt => '%Y%m%d%H%M%S', body => $start,});
- $stop = $Tag->convert_date({ fmt => '%Y%m%d%H%M%S', body => $stop,});
-
+ $start = $Tag->convert_date({
+ fmt => '%Y%m%d%H%M',
+ body => $start,
+ });
+ $stop = $Tag->convert_date({
+ fmt => '%Y%m%d%H%M',
+ body => $stop,
+ });
return $body if !$start;
- if ($start < $now and $now < $stop){
+ if ($start <= $now and $now <= $stop){
return $body;
}
else {
return $else;
}
}
+
EOR
UserTag timed-display Documentation <<EOD
@@ -39,10 +54,23 @@ Usage:
Some text/code to display between June 06, 2007 between 8am and Noon.
[/timed-display]
-For open ended display you can just specify a start date.
-To start immediately and end on a specific date you can just specify a stop date.
+For open ended display you can just specify a start date. To start
+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

0 comments on commit 1748c01

Please sign in to comment.
Something went wrong with that request. Please try again.