Author: apatel
Date: Wed Jul 8 12:33:16 2009
New Revision: 792113
URL:
http://svn.apache.org/viewvc?rev=792113&view=revLog:
Added method to return List of month number and month name entries for the year. Will be useful for building dropdown lists.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.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=792113&r1=792112&r2=792113&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 Wed Jul 8 12:33:16 2009
@@ -33,6 +33,8 @@
import java.util.Map;
import java.util.TimeZone;
+import javolution.util.FastMap;
+
/**
* Utility class for handling java.util.Date, the java.sql data/time classes and related
*/
@@ -955,6 +957,27 @@
}
/**
+ * Returns a List of Maps of month number and name entries - suitable for select inputs.
+ *
+ * @param locale
+ * @return List of month number, name
+ */
+ public static List<Map<String,Object>> getMonths(Locale locale) {
+ Calendar tempCal = Calendar.getInstance(locale);
+ tempCal.set(Calendar.MONTH, Calendar.JANUARY);
+ SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", locale);
+ List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
+ for (int i = Calendar.JANUARY; i <= tempCal.getActualMaximum(Calendar.MONTH); i++) {
+ Map<String,Object> monthEntry = new FastMap<String,Object>();
+ monthEntry.put("monthNumber",tempCal.get(Calendar.MONTH));
+ monthEntry.put("monthName",dateFormat.format(tempCal.getTime()));
+ resultList.add(monthEntry);
+ tempCal.roll(Calendar.MONTH, 1);
+ }
+ return resultList;
+ }
+
+ /**
* Returns an initialized DateFormat object.
*
* @param dateFormat