Author: adrianc
Date: Sat Dec 13 21:45:32 2008 New Revision: 726374 URL: http://svn.apache.org/viewvc?rev=726374&view=rev Log: A couple more UEL functions. Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java?rev=726374&r1=726373&r2=726374&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java Sat Dec 13 21:45:32 2008 @@ -1003,7 +1003,7 @@ public static DateFormat toTimeFormat(String timeFormat, TimeZone tz, Locale locale) { DateFormat df = null; if (timeFormat == null) { - df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); + df = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); } else { df = new SimpleDateFormat(timeFormat); } Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java?rev=726374&r1=726373&r2=726374&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java Sat Dec 13 21:45:32 2008 @@ -19,6 +19,7 @@ package org.ofbiz.base.util.string; import java.lang.reflect.Method; +import java.text.DateFormat; import java.util.Collection; import java.util.Locale; import java.util.Map; @@ -53,6 +54,9 @@ * <tr><td><code>date:monthEnd(Timestamp, TimeZone, Locale)</code></td><td>Returns <code>Timestamp</code> set to end of month.</td></tr> * <tr><td><code>date:yearStart(Timestamp, TimeZone, Locale)</code></td><td>Returns <code>Timestamp</code> set to start of year.</td></tr> * <tr><td><code>date:yearEnd(Timestamp, TimeZone, Locale)</code></td><td>Returns <code>Timestamp</code> set to end of year.</td></tr> + * <tr><td><code>date:dateStr(Timestamp, TimeZone, Locale)</code></td><td>Returns <code>Timestamp</code> as a date <code>String</code> (yyyy-mm-dd).</td></tr> + * <tr><td><code>date:dateTimeStr(Timestamp, TimeZone, Locale)</code></td><td>Returns <code>Timestamp</code> as a date-time <code>String</code> (yyyy-mm-dd hh:mm).</td></tr> + * <tr><td><code>date:timeStr(Timestamp, TimeZone, Locale)</code></td><td>Returns <code>Timestamp</code> as a time <code>String</code> (hh:mm).</td></tr> * <tr><td colspan="2"><b><code>math:</code> maps to <code>java.lang.Math</code></b></td></tr> * <tr><td><code>math:absDouble(double)</code></td><td>Returns the absolute value of a <code>double</code> value.</td></tr> * <tr><td><code>math:absFloat(float)</code></td><td>Returns the absolute value of a <code>float</code> value.</td></tr> @@ -154,6 +158,9 @@ this.functionMap.put("date:monthEnd", UtilDateTime.class.getMethod("getMonthEnd", Timestamp.class, TimeZone.class, Locale.class)); this.functionMap.put("date:yearStart", UtilDateTime.class.getMethod("getYearStart", Timestamp.class, TimeZone.class, Locale.class)); this.functionMap.put("date:yearEnd", UtilDateTime.class.getMethod("getYearEnd", Timestamp.class, TimeZone.class, Locale.class)); + this.functionMap.put("date:dateStr", UelFunctions.class.getMethod("dateString", Timestamp.class, TimeZone.class, Locale.class)); + this.functionMap.put("date:dateTimeStr", UelFunctions.class.getMethod("dateTimeString", Timestamp.class, TimeZone.class, Locale.class)); + this.functionMap.put("date:timeStr", UelFunctions.class.getMethod("timeString", Timestamp.class, TimeZone.class, Locale.class)); this.functionMap.put("math:absDouble", Math.class.getMethod("abs", double.class)); this.functionMap.put("math:absFloat", Math.class.getMethod("abs", float.class)); this.functionMap.put("math:absInt", Math.class.getMethod("abs", int.class)); @@ -230,6 +237,24 @@ } } + public static String dateString(Timestamp stamp, TimeZone timeZone, Locale locale) { + DateFormat dateFormat = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, locale); + dateFormat.setTimeZone(timeZone); + return dateFormat.format(stamp); + } + + public static String dateTimeString(Timestamp stamp, TimeZone timeZone, Locale locale) { + DateFormat dateFormat = UtilDateTime.toDateTimeFormat("yyyy-MM-dd HH:mm", timeZone, locale); + dateFormat.setTimeZone(timeZone); + return dateFormat.format(stamp); + } + + public static String timeString(Timestamp stamp, TimeZone timeZone, Locale locale) { + DateFormat dateFormat = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, locale); + dateFormat.setTimeZone(timeZone); + return dateFormat.format(stamp); + } + @SuppressWarnings("unchecked") public static int getSize(Object obj) { try { |
Free forum by Nabble | Edit this page |