Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 288164

Summary: Month selector in date dropdown has two March's.
Product: z_Archived Reporter: tnmdeuce <tnmdeuce>
Component: NebulaAssignee: John Janus <j.janus>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: j.janus, peter, wim.jongman
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
See Also: https://git.eclipse.org/c/nebula/org.eclipse.nebula.git/commit/?id=56b3130ee50998ecd7902e0b1c8a18b06c2a081f
Whiteboard:
Attachments:
Description Flags
Proposed patch none

Description tnmdeuce@yahoo.com CLA 2009-08-31 13:40:49 EDT
User-Agent:       Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB5; .NET CLR 1.1.4322; .NET CLR 2.0.50727; yie8)
Build Identifier: M20090211-1700

If the selected date has the day 29, 30, or 31, the month selector in the drop down displays two Marchs instead of Feb. Mar.

Reproducible: Always

Steps to Reproduce:
1.Create a date control with DROP_DOWN option.
2.Set the selected date to Aug. 31 of any year.
3.Push the month button in the header.
4.Observe the two Marchs in the selector.



This problem occurs becase the DatePicker class is using the selected date to determine the month.  This is done by setting the month field in the calender instance for each button to the months ordinal value (0-11).  If the selected Calendar.DATE is > 28, Feb is incorrectly calculated as Mar.

This methodology also has other implications.  If the selected date is the 31st of, say, August, and June is selected from the month selector, July 1st becomes the selected date, since June has only 30 days.  It would seem the selected date should be June 30th.  If Feb is selected, the date should be Feb 28th (or 29th).

I've worked around this issue by setting the date field to 1 in the temporary calendar instances used for determining the month and selecting the maximum allowed date value for a chosen month when the selected date(dat) exceeds that value.

These are the changes I've made...

in DatePicker.createHeader switch case MONTH:

for(int i = 0; i < 12; i++) {
        Calendar tmpcal = cdt.getCalendarInstance();
	tmpcal.set(Calendar.DATE, 1);   // <===  Added this
	tmpcal.set(Calendar.MONTH, i);
	monthItems[i] = new MenuItem(monthMenu, SWT.NONE);
	monthItems[i].setData("Month", new Integer(tmpcal.get(Calendar.MONTH)));


in DatePicker.createMonths(Body b)...

Calendar tmpcal = cdt.getCalendarInstance();

// Added from here...
Calendar selected = cdt.getCalendarInstance();
selected.set(Calendar.DATE, 1);
selected.set(Calendar.MONTH, (Integer) button.getData("Month")); //$NON-NLS-1$
if (selected.getActualMaximum(Calendar.DATE) < tmpcal.get(Calendar.DATE)) {
	tmpcal.set(Calendar.DATE, selected.getActualMaximum(Calendar.DATE));
}
// ... to here

tmpcal.set(Calendar.MONTH, (Integer) button.getData("Month")); //$NON-NLS-1$
cdt.setSelection(tmpcal.getTime());

in DatePicker.updateHeader...

Calendar tmpcal = cdt.getCalendarInstance();
for(int i = 0; i < 12; i++) {
	tmpcal.set(Calendar.DATE, 1);    // <==  added this line
	tmpcal.set(Calendar.MONTH, i);

in

Calendar tmpcal = cdt.getCalendarInstance();
for(int i = 0; i < 12; i++) {
    tmpcal.set(Calendar.DATE, 1);    // <== added this line
    tmpcal.set(Calendar.MONTH, i);
Comment 1 John Janus CLA 2016-09-05 10:27:09 EDT
Created attachment 263966 [details]
Proposed patch
Comment 3 Wim Jongman CLA 2016-09-05 11:39:00 EDT
(In reply to Eclipse Genie from comment #2)
> Gerrit change https://git.eclipse.org/r/80405 was merged to [master].
> Commit:
> http://git.eclipse.org/c/nebula/org.eclipse.nebula.git/commit/
> ?id=56b3130ee50998ecd7902e0b1c8a18b06c2a081f

Thanks John! I have assigned to bug to you so that you have to honor of closing it. The snapshot builds should be available in a few minutes.

Please set to Fixed/Resolved and then, after verifying to Verified