[interchange] Improvements to the timed-display usertag

David Christensen interchange-cvs at icdevgroup.org
Sat Jun 18 23:55:16 UTC 2011


commit 1748c01907b5974f9f6f346a226bd2a1c4838d36
Author: David Christensen <david at endpoint.com>
Date:   Sun Jun 12 22:39:21 2011 -0500

    Improvements to the timed-display usertag

 code/UserTag/timed_display.tag |   48 +++++++++++++++++++++++++++++++--------
 1 files changed, 38 insertions(+), 10 deletions(-)
---
diff --git a/code/UserTag/timed_display.tag b/code/UserTag/timed_display.tag
index 6c4bb3d..357ee28 100644
--- a/code/UserTag/timed_display.tag
+++ b/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,12 +23,17 @@ 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 {
@@ -27,6 +41,7 @@ sub {
 	}
 }
 
+
 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
 



More information about the interchange-cvs mailing list