[interchange-cvs] interchange - kwalsh modified code/UserTag/convert_date.tag

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Tue Mar 2 17:35:26 EST 2004


User:      kwalsh
Date:      2004-03-02 22:35:26 GMT
Modified:  code/UserTag convert_date.tag
Log:
	* Replaced the "days" parameter with "adjust" and added a "days"
	  alias to allow it to depreciate gracefully.

	* The new "adjust" parameter allows date adjustments to be
	  specified as "2 hours" or "-2 days" etc.  If no qualifier
	  (seconds/hours/days/minutes/weeks) is specified then "days"
	  is assumed.

Revision  Changes    Path
1.3       +19 -8     interchange/code/UserTag/convert_date.tag


rev 1.3, prev_rev 1.2
Index: convert_date.tag
===================================================================
RCS file: /var/cvs/interchange/code/UserTag/convert_date.tag,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- convert_date.tag	2 Feb 2004 16:49:51 -0000	1.2
+++ convert_date.tag	2 Mar 2004 22:35:26 -0000	1.3
@@ -1,13 +1,15 @@
-UserTag convert-date Order days
+UserTag convert-date Order adjust
 UserTag convert-date PosNumber 1
 UserTag convert-date addAttr
 UserTag convert-date AttrAlias fmt format
+UserTag convert-date AttrAlias days adjust
 UserTag convert-date HasEndTag
 UserTag convert-date Interpolate
 UserTag convert-date Routine <<EOR
 sub {
-    my ($days, $opt, $text) = @_;
+    my ($adjust, $opt, $text) = @_;
     my @t;
+    my $now;
 
 	if(! ref $opt) {
 		my $raw = $opt ? 1 : 0;
@@ -32,11 +34,20 @@
 					$t[5] -= 1900;
 	}
 	else {
-					my $now = time();
-					if ($days) {
-									$now += $days * 86400;
-					}
-					@t = localtime($now);
+					$now = time();
+					@t = localtime($now) unless $adjust;
+	}
+
+	if ($adjust) {
+		$now ||= mktime(@t);
+		$adjust .= ' days' if $adjust =~ /^[-\s\d]+$/;
+
+		if ($adjust =~ s/^\s*-\s*//) {
+			@t = localtime($now - Vend::Config::time_to_seconds($adjust));
+		}
+		else {
+			@t = localtime($now + Vend::Config::time_to_seconds($adjust));
+		}
 	}
 
 	if (defined $opt->{raw} and Vend::Util::is_yes($opt->{raw})) {
@@ -44,7 +55,7 @@
 	}
 
 	if (! $fmt) {
-		if ($t[2]) {
+		if ($t[1] || $t[2]) {
 			$fmt = '%d-%b-%Y %I:%M%p';
 		} else {
 			$fmt = '%d-%b-%Y';








More information about the interchange-cvs mailing list