Mercurial > dive4elements > river
changeset 8460:081a57c80540
Accept number as argument in dc:date-format().
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 30 Oct 2014 14:17:49 +0100 (2014-10-30) |
parents | c6db5f8cafbb |
children | 2b4191f78ea6 |
files | artifacts/doc/datacage_ref_de.rst artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java |
diffstat | 2 files changed, 26 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/doc/datacage_ref_de.rst Thu Oct 30 14:10:41 2014 +0100 +++ b/artifacts/doc/datacage_ref_de.rst Thu Oct 30 14:17:49 2014 +0100 @@ -707,7 +707,9 @@ ``dc:date-format(Format, Datum)`` liefert für ein Datum einen String, der nach den Formatierungsregeln aus Format formatiert wird. Für die Formatierungen -gelten die in SimpleFormat_ beschriebenen Regeln. +gelten die in SimpleFormat_ beschriebenen Regeln. ``Datum`` kann dabei ein +Datums-Objekt oder eine Zahl sein. Letztere wird als Millisekunden nach dem +1.1.1970 00:00:00 GMT interpretiert. .. _SimpleFormat: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java Thu Oct 30 14:10:41 2014 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/templating/FunctionResolver.java Thu Oct 30 14:17:49 2014 +0100 @@ -429,23 +429,33 @@ Object date = args.get(1); try { - // Oracle does not return a date object but an oracle.sql.TIMESTAMP - Method meth = date.getClass().getMethod("dateValue", new Class[] {}); - date = meth.invoke(date, new Object [] {}); - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } catch (NoSuchMethodException e) { - } - if (pattern instanceof String && date instanceof Date) { + // TODO: Take locale into account. + SimpleDateFormat format = new SimpleDateFormat((String)pattern); + + if (date instanceof Number) { + return format.format(new Date(((Number)date).longValue())); + } + try { - // TODO: Take locale into account. - return new SimpleDateFormat((String)pattern).format((Date)date); + /* Oracle does not return a date object but + an oracle.sql.TIMESTAMP */ + Method meth = date.getClass() + .getMethod("dateValue", new Class[] {}); + date = meth.invoke(date, new Object[] {}); + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } catch (InvocationTargetException e) { + } catch (NoSuchMethodException e) { } - catch (IllegalArgumentException iae) { - throw new XPathFunctionException(iae); + + if (date instanceof Date) { + return format.format((Date)date); } } + catch (IllegalArgumentException iae) { + log.error(iae.getMessage()); + } + return ""; }