changeset 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 e2eb1a110b44
files artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Fri Oct 18 18:36:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java	Fri Oct 18 18:40:50 2013 +0200
@@ -199,6 +199,15 @@
                 return minNumber(args.get(0));
             }
         });
+
+        addFunction("to-date", 1, new XPathFunction() {
+            @Override
+            public Object evaluate(List args) throws XPathFunctionException {
+                return toDate(args.get(0));
+            }
+        });
+
+
     }
 
     /**
@@ -531,5 +540,14 @@
             ? (Number)list
             : Double.valueOf(-Double.MAX_VALUE);
     }
+
+    public Date toDate(Object obj) {
+
+        return obj instanceof String
+            ? new Date(Long.valueOf((String)obj))
+            : obj instanceof Number
+                ? new Date(((Number)obj).longValue())
+                : null;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org