Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java @ 7384:ef310e272fb5
Datacage: Add function dc:to-date(number) which converts a epoch base number to a date object.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 18 Oct 2013 18:40:50 +0200 |
parents | 36a194156f15 |
children | 99312d2b4a20 |
comparison
equal
deleted
inserted
replaced
7383:36a194156f15 | 7384:ef310e272fb5 |
---|---|
197 @Override | 197 @Override |
198 public Object evaluate(List args) throws XPathFunctionException { | 198 public Object evaluate(List args) throws XPathFunctionException { |
199 return minNumber(args.get(0)); | 199 return minNumber(args.get(0)); |
200 } | 200 } |
201 }); | 201 }); |
202 | |
203 addFunction("to-date", 1, new XPathFunction() { | |
204 @Override | |
205 public Object evaluate(List args) throws XPathFunctionException { | |
206 return toDate(args.get(0)); | |
207 } | |
208 }); | |
209 | |
210 | |
202 } | 211 } |
203 | 212 |
204 /** | 213 /** |
205 * Create a new function. | 214 * Create a new function. |
206 * @param name Name of the function. | 215 * @param name Name of the function. |
529 | 538 |
530 return list instanceof Number | 539 return list instanceof Number |
531 ? (Number)list | 540 ? (Number)list |
532 : Double.valueOf(-Double.MAX_VALUE); | 541 : Double.valueOf(-Double.MAX_VALUE); |
533 } | 542 } |
543 | |
544 public Date toDate(Object obj) { | |
545 | |
546 return obj instanceof String | |
547 ? new Date(Long.valueOf((String)obj)) | |
548 : obj instanceof Number | |
549 ? new Date(((Number)obj).longValue()) | |
550 : null; | |
551 } | |
534 } | 552 } |
535 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 553 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |