You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2007/02/16 02:28:27 UTC

svn commit: r508271 - in /velocity/tools/trunk: examples/showcase/WEB-INF/toolbox.xml examples/showcase/date.vm src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java

Author: nbubna
Date: Thu Feb 15 17:28:26 2007
New Revision: 508271

URL: http://svn.apache.org/viewvc?view=rev&rev=508271
Log:
add some tests and showcase demos for new ComparisonDateTool

Modified:
    velocity/tools/trunk/examples/showcase/WEB-INF/toolbox.xml
    velocity/tools/trunk/examples/showcase/date.vm
    velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java

Modified: velocity/tools/trunk/examples/showcase/WEB-INF/toolbox.xml
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/examples/showcase/WEB-INF/toolbox.xml?view=diff&rev=508271&r1=508270&r2=508271
==============================================================================
--- velocity/tools/trunk/examples/showcase/WEB-INF/toolbox.xml (original)
+++ velocity/tools/trunk/examples/showcase/WEB-INF/toolbox.xml Thu Feb 15 17:28:26 2007
@@ -88,7 +88,10 @@
   <tool>
     <key>date</key>
     <scope>application</scope>
-    <class>org.apache.velocity.tools.generic.DateTool</class>
+    <class>org.apache.velocity.tools.generic.ComparisonDateTool</class>
+    <parameter name="format" value="yyyy-MM-dd"/>
+    <parameter name="depth" value="2"/>
+    <parameter name="skip" value="month"/>
   </tool>
   <tool>
     <key>esc</key>

Modified: velocity/tools/trunk/examples/showcase/date.vm
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/examples/showcase/date.vm?view=diff&rev=508271&r1=508270&r2=508271
==============================================================================
--- velocity/tools/trunk/examples/showcase/date.vm (original)
+++ velocity/tools/trunk/examples/showcase/date.vm Thu Feb 15 17:28:26 2007
@@ -17,7 +17,8 @@
 #title( 'DateTool' )
 <p>
 #set( $demo = $text.demo )
-$demo.thisPage.insert("#doclink( 'DateTool' true )").  As the DateTool
+$demo.thisPage.insert("#doclink( 'DateTool' true )") and its subclass, the 
+#doclink( 'ComparisonDateTool' true ).  As the DateTool
 is quite full-featured and provides many similar functions with varying and
 strongly-typed options, not all functions are demonstrated below.  See the javadoc
 for a full listing of available functions.
@@ -88,11 +89,31 @@
 
 #demoCustom( 'date' )
 </table>
+<br>
+<p>
+Here are a few demos of the functions provided by the
+#doclink( 'ComparisonDateTool' true ) class that are not in the standard
+DateTool.
+</p>
+
+#demoTableStart()
+
+#set( $desc = "This returns a #doclink( 'ComparisonDateTool.Comparison' true ) between the result of ${esc.d}date.calendar and the specified date.  The default rendering of that Comparison will be the largest unit difference between the dates followed by a description of their relative position." )
+#demo1( 'date' 'whenIs' 6 $desc )
+
+#set( $desc = "This returns a #doclink( 'ComparisonDateTool.Comparison' true ) between the second specified date and the first specified date.  The default rendering of that Comparison will be the largest unit difference between the dates followed by a description of their relative position." )
+#demo2( 'date' 'whenIs' 6 $desc )
+
+#set( $desc = "This returns a #doclink( 'ComparisonDateTool.Comparison' true ) between the second specified date and the first specified date.  The default rendering of that Comparison will be the largest unit difference between the dates." )
+#demo2( 'date' 'difference' 6 $desc )
+
+#demoCustom( "date.whenIs('2005-07-04').depth(3)" )
+</table>
 
 <div align="center">
   <a name="fullDemo"><h3>$demo.mainExampleHeader</h3></a>
 <form method="post" action="$link.self.anchor('fullDemo')">
-<textarea name="demo" rows="12" cols="65">##
+<textarea name="demo" rows="16" cols="65">##
 #if( $params.demo )##
 $params.demo##
 #else##
@@ -103,7 +124,16 @@
  ${esc.d}date.full_date
  ${esc.d}date.yyyy
  ${esc.d}date.get('default','short')
- ${esc.d}date.get('yyyy-M-d H:m:s')##
+ ${esc.d}date.get('yyyy-M-d H:m:s')
+
+${esc.h}${esc.h} Examples of comparing dates:
+ ${esc.d}date.whenIs('2005-07-04')
+ ${esc.d}date.whenIs('2005-07-04').full
+ ${esc.d}date.whenIs('2005-02-15').days
+ ${esc.d}date.whenIs(${esc.d}date)
+ ${esc.d}date.whenIs('2005-07-04', '2005-07-04')
+ ${esc.d}date.difference('2005-07-04', '2005-07-04')
+ ${esc.d}date.difference('2005-07-04', '2007-02-15').abbr##
 #end##
 </textarea>
   <br>

Modified: velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java?view=diff&rev=508271&r1=508270&r2=508271
==============================================================================
--- velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java (original)
+++ velocity/tools/trunk/src/test/org/apache/velocity/tools/test/whitebox/GenericToolsTests.java Thu Feb 15 17:28:26 2007
@@ -21,6 +21,7 @@
 
 import java.util.Locale;
 import java.util.Map;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 
@@ -29,6 +30,7 @@
 
 import org.apache.velocity.tools.generic.Alternator;
 import org.apache.velocity.tools.generic.AlternatorTool;
+import org.apache.velocity.tools.generic.ComparisonDateTool;
 import org.apache.velocity.tools.generic.DateTool;
 import org.apache.velocity.tools.generic.EscapeTool;
 import org.apache.velocity.tools.generic.MathTool;
@@ -173,5 +175,19 @@
         ResourceTool.Key frenchHelloWorld =
             frenchTool.get("hello.whoever").insert(frenchTool.get("world"));
         assertStringEquals("Bonjour Monde!", frenchHelloWorld);
+    }
+
+    public @Test void testComparisonDateTool() { /* TODO still incomplete */
+        ComparisonDateTool dateTool = (ComparisonDateTool)toolbox.get("date");
+        assertNotNull(dateTool);
+        Calendar date1 = new GregorianCalendar(2007,0,2);
+        Calendar date2 = new GregorianCalendar(2007,1,15);
+        /* test comparing */
+        ComparisonDateTool.Comparison whenIs = dateTool.whenIs(date1, date2);
+        assertEquals(0l, whenIs.getYears());
+        assertEquals(1l, whenIs.getMonths());
+        assertEquals(44l, whenIs.getDays());
+        // the toolbox config says to skip months, so this should be in weeks
+        assertStringEquals("6 weeks later", whenIs);
     }
 }