Changeset 1432

Show
Ignore:
Timestamp:
19/01/10 09:11:52 (2 months ago)
Author:
bruno
Message:

Fix problems in the reporting:
- for the first days of 2010, the composed week index was '201053', causing the reports to be empty since this start week was always larger than any end week in 2010.
- in the RawDataResource?, no zero was prepended for weeks < 10 (though this was done in InvoiceResource?)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tupper/trunk/tupper-site/src/main/java/org/kauriproject/tupper/resource/CalendarUtil.java

    r1428 r1432  
    1313    private static final Pattern WEEK_RANGE = Pattern.compile("^" + WEEK_PATTERN_STRING + "-" + WEEK_PATTERN_STRING + "$"); 
    1414 
     15    public static Locale CALENDAR_LOCALE = new Locale("nl", "BE"); 
     16 
    1517    public static Calendar getCalendar() { 
    1618        // The firstDayOfWeek and minimalDaysInFirstWeek fields 
    1719        // are dependent on the Locale, we use the Belgian settings 
    18         return new GregorianCalendar(new Locale("nl", "BE")); 
     20        return new GregorianCalendar(CALENDAR_LOCALE); 
    1921    } 
    2022 
     
    8991        return new int[] {startWeek, startYear, endWeek, endYear}; 
    9092    } 
     93 
     94    public static int[] getWeekAndYear(Calendar calendar) { 
     95        int year = calendar.get(YEAR); 
     96        int week = calendar.get(WEEK_OF_YEAR); 
     97 
     98        // At the beginning of the year, the day might fall in the last week of 
     99        // last year, while the year value would point to the new year. 
     100        // We adjust by letting the year value match the week. 
     101        // (see getCalendar(week, year) for similar problem) 
     102        if (calendar.get(MONTH) == JANUARY && week > 50) { 
     103            year--; 
     104        } 
     105 
     106        return new int[] {week, year}; 
     107    } 
     108 
     109    public static long getWeekIndex(int week, int year) { 
     110        return Long.parseLong(String.valueOf(year) + (week < 10 ? "0" + week : week)); 
     111    } 
     112 
    91113} 
  • tupper/trunk/tupper-site/src/main/java/org/kauriproject/tupper/resource/InvoiceResource.java

    r1419 r1432  
    6363            DateTime to = iso8601.parseDateTime((String) getRequest().getAttributes().get("to")); 
    6464 
    65             Calendar cal = CalendarUtil.getCalendar(); 
    66             cal.setTime(from.toDate()); 
    67             templateData.put("beginWeek", cal.get(Calendar.WEEK_OF_YEAR)); 
    68             long beginIndex = Long.parseLong("" + cal.get(Calendar.YEAR) + "" + (cal.get(Calendar.WEEK_OF_YEAR) < 10 ? "0" + cal.get(Calendar.WEEK_OF_YEAR) : cal.get(Calendar.WEEK_OF_YEAR))); 
    69             cal.setTime(to.toDate()); 
    70             templateData.put("endWeek", cal.get(Calendar.WEEK_OF_YEAR)); 
    71             long endIndex = Long.parseLong("" + cal.get(Calendar.YEAR) + "" + (cal.get(Calendar.WEEK_OF_YEAR) < 10 ? "0" + cal.get(Calendar.WEEK_OF_YEAR) : cal.get(Calendar.WEEK_OF_YEAR))); 
     65            int[] fromWY = CalendarUtil.getWeekAndYear(from.toCalendar(CalendarUtil.CALENDAR_LOCALE)); 
     66            int[] toWY = CalendarUtil.getWeekAndYear(to.toCalendar(CalendarUtil.CALENDAR_LOCALE)); 
     67 
     68            long beginIndex = CalendarUtil.getWeekIndex(fromWY[0], fromWY[1]); 
     69            long endIndex = CalendarUtil.getWeekIndex(toWY[0], toWY[1]); 
    7270 
    7371            Form form = getRequest().getResourceRef().getQueryAsForm(); 
  • tupper/trunk/tupper-site/src/main/java/org/kauriproject/tupper/resource/RawDataResource.java

    r1419 r1432  
    55package org.kauriproject.tupper.resource; 
    66 
    7 import java.util.ArrayList; 
    87import java.util.Calendar; 
    9 import java.util.GregorianCalendar; 
    108import java.util.List; 
    119import org.kauriproject.tupper.api.Tupper; 
     
    5856            DateTime to = iso8601.parseDateTime((String) getRequest().getAttributes().get("to")); 
    5957 
    60             Calendar calendar = CalendarUtil.getCalendar(); 
    61             calendar.setTime(from.toDate()); 
    62             long beginweek = Long.parseLong("" + calendar.get(GregorianCalendar.YEAR) + calendar.get(GregorianCalendar.WEEK_OF_YEAR)); 
    63             calendar.setTime(to.toDate()); 
    64             long endweek = Long.parseLong("" + calendar.get(GregorianCalendar.YEAR) + calendar.get(GregorianCalendar.WEEK_OF_YEAR)); 
     58            int[] fromWY = CalendarUtil.getWeekAndYear(from.toCalendar(CalendarUtil.CALENDAR_LOCALE)); 
     59            int[] toWY = CalendarUtil.getWeekAndYear(to.toCalendar(CalendarUtil.CALENDAR_LOCALE)); 
     60 
     61            long beginweek = CalendarUtil.getWeekIndex(fromWY[0], fromWY[1]); 
     62            long endweek = CalendarUtil.getWeekIndex(toWY[0], toWY[1]); 
    6563 
    6664            Form form = getRequest().getResourceRef().getQueryAsForm(); 
     
    6866            String projectId = form.getValues("proj"); 
    6967            String custInitials = form.getValues("cust"); 
    70             List<Performance> performances = new ArrayList<Performance>()
     68            List<Performance> performances
    7169 
    7270            try {