Changeset 1426

Show
Ignore:
Timestamp:
18/12/09 17:25:12 (3 months ago)
Author:
bruno
Message:

Still one more fix for correct year-edge handling

Files:

Legend:

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

    r1423 r1426  
    2828    public static Calendar getCalendar(int week, int year) { 
    2929        Calendar calendar = getCalendar(); 
    30         calendar.set(Calendar.DAY_OF_YEAR, 1); 
    3130        calendar.set(Calendar.YEAR, year); 
    3231        calendar.set(Calendar.WEEK_OF_YEAR, week); 
     32 
     33        // For the first and last week of the year, we have to be careful 
     34        // that the year-value doesn't shift because the day of the week 
     35        // falls in the other year. 
     36        if (week == 1) { 
     37            calendar.set(Calendar.DAY_OF_YEAR, 1); 
     38        } else { 
     39            // we don't check explictly for the last week of the year, 
     40            // but this covers it 
     41            calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); 
     42        } 
    3343        return calendar; 
    3444    }