[PATCH] Datacage: Add function dc:to-date(number) which converts a epoch base number to a date object

Wald Commits scm-commit at wald.intevation.org
Fri Oct 18 18:40:54 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1382114450 -7200
# Node ID ef310e272fb5bbaf9a940b159041f1920054144c
# Parent  36a194156f15f88f77fdbf12a5b95fe1bc170282
Datacage: Add function dc:to-date(number) which converts a epoch base number to a date object.

diff -r 36a194156f15 -r ef310e272fb5 artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java
--- 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 :


More information about the Dive4elements-commits mailing list