svn commit: r792113 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r792113 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java

apatel-2
Author: apatel
Date: Wed Jul  8 12:33:16 2009
New Revision: 792113

URL: http://svn.apache.org/viewvc?rev=792113&view=rev
Log:
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