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
版权声明:本文标题:codenameone - com.codename1.ui.Calendar Component DST Issue Causing Incorrect Day Selection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744674790a2619044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论