Menu

#1 Calendar Data is Incorrect

open
nobody
None
5
2004-02-12
2004-02-12
No

The calendar that is displayed has incorrect
information. As an example, it shows February 11, 2004
occurring on a Tuesday. February 11, 2004 should be
Wednesday. The attached file shows a screen capture.

Discussion

  • John Kauczka

    John Kauczka - 2004-02-12

    Screen Capture of DatePicker

     
  • Adam Hathcock

    Adam Hathcock - 2004-03-03

    Logged In: YES
    user_id=554278

    I think you're having the same problem I am having, but I
    got a fix for it. The computeoffset method needs to start
    on SUNDAY for the first day of the week rather than MONDAY.
    I guess that is a difference in euro-style weeks and
    american-style weeks

    here is my fix although probably need something more
    intelligent to account for the locale difference

    private int computeOffset(int day) {
    switch (day) {
    case Calendar.SUNDAY :
    return 1;
    case Calendar.MONDAY :
    return 2;
    case Calendar.TUESDAY :
    return 3;
    case Calendar.WEDNESDAY :
    return 4;
    case Calendar.THURSDAY :
    return 5;
    case Calendar.FRIDAY :
    return 6;
    case Calendar.SATURDAY :
    return 7;
    }
    return -1;
    }

     
  • Nobody/Anonymous

    Logged In: NO

    If you want the datepicker to work on different locales, you might want
    to try this fix.

    private int computeOffset(int day) {
    int offset = temp.getFirstDayOfWeek();
    day = day - offset + 1;
    if (day < 1) day = day + 7;
    return day;
    }

    I haven't tested it on different locales but if temp (a Calendar) is being
    set to the specific locale, this snippet should work. This bug has been
    open for quite a long time. Maybe this will help the developers fix the
    bug and create a new release so that new users won't have to patch the
    code themselves (although patching is always fun :-) )

    For contact information: nathan(AT)borderlandconsulting(DOT)com

     
  • Daniel Dietrich

    Daniel Dietrich - 2005-06-30

    Logged In: YES
    user_id=1276492

    I use the following solution (DatePicker.java):

    private void onPaint(PaintEvent event) {
    ...
    final int days[] = {

    Calendar.MONDAY,

    Calendar.TUESDAY,

    Calendar.WEDNESDAY,

    Calendar.THURSDAY,

    Calendar.WEDNESDAY,

    Calendar.FRIDAY,

    Calendar.SATURDAY,

    Calendar.SUNDAY

    };

    for (int i = 0; i < 7; i++) {

    if (i == 6) {

    gc.setForeground(display.getSystemColor(SWT.COLOR_RED));

    }

    drawTextImage(gc, getDayName(days[i]), x, 0,
    colSize, rowSize);

    x += colSize;

    }
    ...
    }
    ---

    The first solution

    private int computeOffset(int day) {
    int offset = temp.getFirstDayOfWeek();
    ...

    is not deterministic because the int value of the function
    getFirstDayOfWeek() is not specified by the jvm! that means,
    that other jvm's may have other int values.

    ---

    The second solution (beginning with Sunday in the
    switch-statement) doesn't work for me (german locale),
    because saturday is drawn red (instead of sunday).

    ---

    - Daniel

     
  • Daniel Dietrich

    Daniel Dietrich - 2005-06-30

    Logged In: YES
    user_id=1276492

    Sorry, the days[] array of my previous message contains one
    Calendar.WEDNESDAY too much...

     

Log in to post a comment.