admin管理员组

文章数量:1391951

Dear Codename One Team,

I have encountered an issue in the Codename One com.codename1.ui.Calendar component that affects day selection when Daylight Savings Time (DST) changes within the month.

Issue Description:

The setCurrentDay method's current implementation increments days using startDate += 86400000L; (adding a fixed 24-hour period). When the DST transition occurs, the system adjusts the time forward (e.g., from 1 AM to 3 AM), causing the selected days to shift from 1 AM to 2 AM. As a result, this causes incorrect date selection behavior when comparing:

  • startDate (which now has an unexpected hour shift) with SELECTED_DAY
  • selectedDays.contains(new Date(dates[j])), since dates[j] may have been shifted by an hour.

Proposed Fix:

Instead of adding 86400000L manually, use Calendar.add(), which correctly handles DST transitions:

 for (; j < components.length && (j - i + 1) <= lastDay; j++) {
                setDayEnabled(components[j], true);
                dates[j] = startDate;
                if (dates[j] == SELECTED_DAY) {
                    setDayUIID(components[j], "CalendarSelectedDay");
                    selected = components[j];
                } else {
                    setDayUIID(components[j], "CalendarDay");
                }

                for (Map.Entry<String, Collection<Date>> entry : highlightGroup.entrySet()) {
                    if (entry.getValue().contains(new Date(dates[j]))) {
                        setDayUIID(components[j], entry.getKey());
                    }
                }

                if (multipleSelectionEnabled) {
                    if (selectedDays.contains(new Date(dates[j]))) {
                        setDayUIID(components[j], selectedDaysUIID);
                    }
                }
                updateButtonDayDate(components[j], yearNew, month, j - i + 1);
                //startDate += DAY; // Current Implementation 

                // Fixed Code
                cal.setTime(new Date(startDate));
                cal.add(java.util.Calendar.DAY_OF_MONTH, 1);
                startDate = cal.getTime().getTime();
                // End Code Fided
            }

This ensures that date calculations respect DST changes without shifting the hour.

I hope this helps improve Codename One’s Calendar component. Please let me know if you need further details.

Best regards, Oscar Naranjo

本文标签: codenameonecomcodename1uiCalendar Component DST Issue Causing Incorrect Day SelectionStack Overflow