[xwiki-devs] Velocity format date
I'm overlooking something small... How can I format dates with velocity? {{velocity}} #set($myDate = $doc.getContentUpdateDate()) Last updated at $date.format('medium',$myDate) Last updated at $date.format('yyyy-MM-dd',$myDate) {{/velocity}} Both $date.format are not working! -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272.html Sent from the XWiki- Dev mailing list archive at Nabble.com.
As I said...something small... Last updated at $datetool.format('medium',$myDate) Last updated at $datetool.format('yyyy-MM-dd',$myDate) Why do we have to use $datetool instead of $date? -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580273.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Next challenge... How can I compare dates with velocity? It seems like the ComparisonDateTool is not implemented in XWiki http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/gen... -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580274.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
On Tue, Jul 10, 2012 at 2:36 PM, Hamster <[email protected]> wrote:
Next challenge...
How can I compare dates with velocity?
It seems like the ComparisonDateTool is not implemented in XWiki http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/gen...
For me $datetool.class.name displays org.apache.velocity.tools.generic.ComparisonDateTool :) Hope this helps, Marius
-- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580274.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On 07/10/2012 07:36 AM, Hamster wrote:
Next challenge...
How can I compare dates with velocity?
It seems like the ComparisonDateTool is not implemented in XWiki http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/gen...
Again, on http://extensions.xwiki.org/xwiki/bin/view/Extension/Velocity+Module#HVeloci... it states that $datetool is a reference to ComparisonDateTool. What do you mean by "compare"? ComparisonDateTool only offers methods for computing the difference between two dates, but just "is after" or "is before" comparison is directly available in the Date class, so a simple: $date1.after($date2) should return true or false. You can also compare the absolute time values using: #if ($date1.getTime() >= $date2.getTime()) -- Sergiu Dumitriu http://purl.org/net/sergiu/
We have created a reference manual on how to use XWiki at our company. I want to create a Wiki Macro which reads the "ContentUpdateDate" and shows that as a "red flag" when the document has been updated in the last 2 days (or 5 days). So I need to know the difference between Now() and ContentUpdateDate :-) #set($myDate = $doc.getContentUpdateDate()) $doc.getDisplayTitle() has been updated at $datetool.format('yyyy-MM-dd',$myDate) by $doc.getAuthor() On the VelocityDocs at http://velocity.apache.org/tools/releases/1.4/javadoc/org/apache/velocity/to... there's a method called "whenIs" which is exactly what I want to use to show how long ago the reference manual has been updated... So I tried... $datetool.whenis('1979-05-02') $datetool.whenIs('1979-05-02') $datetool.Whenis('1979-05-02') $datetool.WhenIs('1979-05-02') $comparisondatetool.whenIs('1979-05-02') $comparisondateTool.whenIs('1979-05-02') $comparisonDatetool.whenIs('1979-05-02') $comparisonDateTool.whenIs('1979-05-02') $ComparisonDateTool.whenIs('1979-05-02') $Comparisondatetool.whenIs('1979-05-02') $comparisondatetool.whenis('1979-05-02') $comparisondateTool.whenis('1979-05-02') $comparisonDatetool.whenis('1979-05-02') $comparisonDateTool.whenis('1979-05-02') $ComparisonDateTool.whenis('1979-05-02') $Comparisondatetool.whenis('1979-05-02') Nothing works... I could really need a working example of "whenIs"! -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580287.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Okay...so "whenIs" does not work with Strings like the examples at the VelocityDocs... But this does work: $datetool.whenIs($myDate) I just keep pulling my hair out :-( -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580288.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
In the end, it's not that hard... #set($ManualDoc = $xwiki.getDocument("SpaceName.PageName")) #set($ManualDate = $ManualDoc.getContentUpdateDate()) ##dutch $ManualDoc.getDisplayTitle() is bijgewerkt op $datetool.format('yyyy-MM-dd',$ManualDate) door $ManualDoc.getAuthor() ($datetool.whenIs($ManualDate)) ##english $ManualDoc.getDisplayTitle() has been updated at $datetool.format('yyyy-MM-dd',$ManualDate) by $ManualDoc.getAuthor() ($datetool.whenIs($ManualDate)) -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580289.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Only thing missing is getting the 'PrettyName' of the 'getAuthor' instead of the XWiki Username :-) -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580290.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
On Wed, Jul 11, 2012 at 9:25 AM, Hamster <[email protected]> wrote:
Only thing missing is getting the 'PrettyName' of the 'getAuthor' instead of the XWiki Username :-)
See http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org... Hope this helps, Marius
-- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580290.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Thanks, I was just looking at that same page! :-) $xwiki.getUserName($ManualDoc.getAuthor()) renders as /xwiki/bin/view/XWiki/firstname FirstName LastName instead of an actual link Any clue what could be causing this? -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580292.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
I was missing the {{html}} and {{/html}} tags :-) -- View this message in context: http://xwiki.475771.n2.nabble.com/Velocity-format-date-tp7580272p7580293.htm... Sent from the XWiki- Dev mailing list archive at Nabble.com.
On 07/10/2012 07:13 AM, Hamster wrote:
As I said...something small...
Last updated at $datetool.format('medium',$myDate) Last updated at $datetool.format('yyyy-MM-dd',$myDate)
Why do we have to use $datetool instead of $date?
Why would you expect $date and not $datetool? $date is used in the example documentation of the Velocity DateTool tool, but that is just an example binding name. $datetool as a name (and the other tools as well) is documented at http://extensions.xwiki.org/xwiki/bin/Extension/Velocity+Module#HVelocityToo... All the tools are using a $*tool name in XWiki. -- Sergiu Dumitriu http://purl.org/net/sergiu/
participants (3)
-
Hamster -
Marius Dumitru Florea -
Sergiu Dumitriu