Formatting a date

1,182 views
Skip to first unread message

Ben Short

unread,
Feb 23, 2012, 3:34:00 PM2/23/12
to Closure Templates Discuss
Hi,

I'm trying to format a unix epoc into a human readable date as shown
here https://community.jivesoftware.com/docs/DOC-42113#Formatting_Dates
but I get an error when I try to compile it.

My soy file:

{namespace nalps.map.mockup}
/**
* @param speedLimit
* @param name
* @param carCount
* @param peakSpeed
* @param averageSpeed
* @param temperature
* @param windSpeed
* @param windDirection
* @param lastUpdated
*/
{template .speedSign}
<table class="speed-sign-table">
<tr>
<td class="speed-sign-icon-cell">
<img class="speed-sign-icon" src="images/
{$speedLimit}.png" />
</td>
<td>{$name}</td>
</tr>
<tr>
<td colspan="2">Count: {$carCount}cpm</td>
</tr>
<tr>
<td colspan="2">Peak: {$peakSpeed}mph</td>
</tr>
<tr>
<td colspan="2">Average: {$averageSpeed}mph</td>
</tr>
{if $temperature}
<tr>
<td colspan="2">Temperature: {$temperature}&deg;C</td>
</tr>
{/if}
{if $windSpeed}
<tr>
<td colspan="2">Wind speed: {$windSpeed}mph</td>
</tr>
{/if}
{if $windDirection}
<tr>
<td colspan="2">Wind direction: {$windDirection}mph</td>
</tr>
{/if}
<tr>
<td colspan="2">Last updated:
{formatDate($lastUpdated,'long','date')}</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="right"><a href="">Refresh</a></td>
</tr>
</table>
{/template}

Compile output:


Exception in thread "main"
com.google.template.soy.base.SoySyntaxException: In file templates.soy:
46: Unrecognized function 'formatDate' (function call
"formatDate($lastUpdated, 'long', 'date')").
at com.google.template.soy.parsepasses.CheckFunctionCallsVisitor
$CheckFunctionCallsExprVisitor.visitFunctionNode(CheckFunctionCallsVisitor.java:
173)
at
com.google.template.soy.exprtree.AbstractExprNodeVisitor.visit(AbstractExprNodeVisitor.java:
114)
at
com.google.template.soy.exprtree.AbstractExprNodeVisitor.visit(AbstractExprNodeVisitor.java:
69)
at
com.google.template.soy.basetree.AbstractNodeVisitor.visitChildren(AbstractNodeVisitor.java:
58)
at
com.google.template.soy.exprtree.AbstractExprNodeVisitor.visitChildren(AbstractExprNodeVisitor.java:
127)
at com.google.template.soy.parsepasses.CheckFunctionCallsVisitor
$CheckFunctionCallsExprVisitor.visitExprNode(CheckFunctionCallsVisitor.java:
125)
at
com.google.template.soy.exprtree.AbstractExprNodeVisitor.visitExprRootNode(AbstractExprNodeVisitor.java:
150)
at
com.google.template.soy.exprtree.AbstractExprNodeVisitor.visit(AbstractExprNodeVisitor.java:
76)
at
com.google.template.soy.exprtree.AbstractExprNodeVisitor.visit(AbstractExprNodeVisitor.java:
69)
at
com.google.template.soy.basetree.AbstractNodeVisitor.exec(AbstractNodeVisitor.java:
39)
at
com.google.template.soy.parsepasses.CheckFunctionCallsVisitor.visitSoyNode(CheckFunctionCallsVisitor.java:
89)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitPrintNode(AbstractSoyNodeVisitor.java:
216)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
83)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
54)
at
com.google.template.soy.basetree.AbstractNodeVisitor.visitChildren(AbstractNodeVisitor.java:
58)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitChildren(AbstractSoyNodeVisitor.java:
121)
at
com.google.template.soy.parsepasses.CheckFunctionCallsVisitor.visitSoyNode(CheckFunctionCallsVisitor.java:
102)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitTemplateNode(AbstractSoyNodeVisitor.java:
160)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitTemplateBasicNode(AbstractSoyNodeVisitor.java:
152)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
64)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
54)
at
com.google.template.soy.basetree.AbstractNodeVisitor.visitChildren(AbstractNodeVisitor.java:
58)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitChildren(AbstractSoyNodeVisitor.java:
121)
at
com.google.template.soy.parsepasses.CheckFunctionCallsVisitor.visitSoyNode(CheckFunctionCallsVisitor.java:
102)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitSoyFileNode(AbstractSoyNodeVisitor.java:
148)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
62)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
54)
at
com.google.template.soy.basetree.AbstractNodeVisitor.visitChildren(AbstractNodeVisitor.java:
58)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitChildren(AbstractSoyNodeVisitor.java:
121)
at
com.google.template.soy.parsepasses.CheckFunctionCallsVisitor.visitSoyNode(CheckFunctionCallsVisitor.java:
102)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visitSoyFileSetNode(AbstractSoyNodeVisitor.java:
144)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
61)
at
com.google.template.soy.soytree.AbstractSoyNodeVisitor.visit(AbstractSoyNodeVisitor.java:
54)
at
com.google.template.soy.basetree.AbstractNodeVisitor.exec(AbstractNodeVisitor.java:
39)
at
com.google.template.soy.SoyFileSet.runMiddleendPasses(SoyFileSet.java:
792)
at
com.google.template.soy.SoyFileSet.compileToJsSrcFiles(SoyFileSet.java:
733)
at
com.google.template.soy.SoyToJsSrcCompiler.execMain(SoyToJsSrcCompiler.java:
255)
at
com.google.template.soy.SoyToJsSrcCompiler.main(SoyToJsSrcCompiler.java:
205)


Am I missing an external lib or something?

Regards

Ben

Juan Mendes

unread,
Feb 23, 2012, 4:06:03 PM2/23/12
to closure-temp...@googlegroups.com
It looks like Jive adds some custom functions, I've never seen formatDat. Are you sure you're including the Jive plugins?

--Juan
--
Juan Mendes

Ben Short

unread,
Feb 23, 2012, 4:15:34 PM2/23/12
to closure-temp...@googlegroups.com
Hi Juan,

I assumed that it was just better documentation for closure-templates
so I don't have the jive plugins.

Can I write a plugin? Do I just need to defined a function called
formatDate and it will be called?

Ben

Juan Mendes

unread,
Feb 23, 2012, 4:27:52 PM2/23/12
to closure-temp...@googlegroups.com
Here's the page on how to write plugins


I haven't done it

Good luck,

--Juan
--
Juan Mendes

Ben Short

unread,
Feb 23, 2012, 4:28:23 PM2/23/12
to closure-temp...@googlegroups.com
Thanks

Ed Venaglia

unread,
Feb 28, 2012, 11:49:07 PM2/28/12
to closure-temp...@googlegroups.com
The formatDate() function is one of many custom functions provided by Jive. It looks like you are trying to compile using the stand alone soy compiler. Jive compiles soy files internally and does not use the stand alone compiler.   ...just wanted to clear that up.

I've written a few custom functions, all fairly simple. The steepest part of the learning curve is around generating JavaScript in Java. I would recommend using a third-party date formatting library on the browser to handle the actual date formatting, then delegate to that in computeForJsSrc(). That'll keep the Java code much simpler. That's what we do.

Good luck.

-Ed-
Senior Software Engineer
Jive Software
Reply all
Reply to author
Forward
0 new messages