svn commit: r466364 - in /incubator/ofbiz/trunk: applications/workeffort/webapp/workeffort/calendar/month.ftl framework/base/src/base/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: r466364 - in /incubator/ofbiz/trunk: applications/workeffort/webapp/workeffort/calendar/month.ftl framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java

jleroux@apache.org
Author: jleroux
Date: Sat Oct 21 01:34:23 2006
New Revision: 466364

URL: http://svn.apache.org/viewvc?view=rev&rev=466364
Log:
At beginning a patch from Bilgin Ibryam slightly modified by Jacopo.
But actually that was not solving the problem exposed in "Wrong week numbers in the fixed asset calendar" (https://issues.apache.org/jira/browse/OFBIZ-392)
To fix it I added some locale settings in month.ftl .
I'm not quite sure why these should be "en". But I'm sure it works with it and don't without.
I assume it's because we calculate date values before in this locale (set from command line).
It seems that it's the same type of problem that the one who arises and forced us to put -Duser.language=en in command line some times ago.


Modified:
    incubator/ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl
    incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java

Modified: incubator/ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl?view=diff&rev=466364&r1=466363&r2=466364
==============================================================================
--- incubator/ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl (original)
+++ incubator/ofbiz/trunk/applications/workeffort/webapp/workeffort/calendar/month.ftl Sat Oct 21 01:34:23 2006
@@ -14,6 +14,12 @@
 License for the specific language governing permissions and limitations
 under the License.
 -->
+<#-- I'm not quite sure why these should be "en". But I'm sure it works with it and don't without.
+I assume it's because we calculate date before in this locale (set from command line) - JLR 21/10/2006
+Please see https://issues.apache.org/jira/browse/OFBIZ-392-->
+<#setting locale="en">
+<#assign locale="en">
+
 <table border='0' width='100%' cellspacing='0' cellpadding='0' class='boxoutside'>
   <tr>
     <td width='100%'>

Modified: incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java?view=diff&rev=466364&r1=466363&r2=466364
==============================================================================
--- incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java (original)
+++ incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java Sat Oct 21 01:34:23 2006
@@ -706,21 +706,23 @@
      * @return A int containing the week number
      */
     public static int weekNumber(Timestamp input) {
-        Timestamp yearStart = UtilDateTime.getYearStart(input);
-        Timestamp weekStart = UtilDateTime.getWeekStart(yearStart);
-
-        int days = 0;
-        for (days = 0; UtilDateTime.getDayStart(weekStart, days).compareTo(yearStart) == 0; days++) ;
-
-        // the splitted week belongs to the year where there are the most days (ISO)
-        Timestamp week1Start = weekStart;
-        if (days < 4)
-            week1Start = UtilDateTime.getWeekStart(weekStart, 7);
-
-        int weeks = 0;
-        for (weeks = 0; UtilDateTime.getDayStart(week1Start, weeks * 7).compareTo(input) < 0; weeks++) ;
-
-        return ++weeks; // start at 1
+        Calendar calendar = Calendar.getInstance();
+        return weekNumber(input, calendar.getFirstDayOfWeek());
+    }
+    
+    public static int weekNumber(Timestamp input, int startOfWeek) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setFirstDayOfWeek(startOfWeek);
+        
+        if(startOfWeek == Calendar.MONDAY) {
+           calendar.setMinimalDaysInFirstWeek(4);
+        } else if(startOfWeek == Calendar.SUNDAY) {
+           calendar.setMinimalDaysInFirstWeek(3);
+        }
+        
+        calendar.setTime(new java.util.Date(input.getTime()));
+        return calendar.get(Calendar.WEEK_OF_YEAR);
     }
 }
+