Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Change datetime in program does strange things for February and March
Change datetime in program does strange things for February and March [message #1773832] Thu, 05 October 2017 09:04 Go to next message
Wim Anckaert is currently offline Wim AnckaertFriend
Messages: 32
Registered: December 2012
Member
Hi,

Use case:
We have a general date widget datetime : SWT.CALENDAR for all our dates in a popup.
In one case we want to set the birthdate of a person running RAP on a mobile device.
You need a lot of clicks to get to, for example 1971.

So we created two comboboxes above the datetime to change year and month. So the user has multiple options for change the year and month.

That works ok !

We found what i think is a bug.
If the date is set to 2017/03/31 (YYYY/MM/DD) and via the combobox we change it to februari, we want it to be the first of February, but in the gui we see the first of March.
If we ask the datetime wich date is selected, it says first of February. So the widget is correct but it shows the wrong month.

see below a basic snippet to reproduce the problem.
We use RAP 3.1.1, I don't know if it also occures in RAP 3.2

final DateTime dateTime = new DateTime(parent, SWT.CALENDAR);
            dateTime.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

            Button button = new Button(parent, SWT.PUSH);
            button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
            button.setText("Change date");
            button.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    dateTime.setDay(1);// first day of month
                    dateTime.setMonth(1);// to february

                    // strange thing : we get the correct date that is just set, but gui is not ok.
                    System.out.println("new date:" + dateTime.getYear() + " " + dateTime.getMonth() + " " + dateTime.getDay());
                }
            });

            dateTime.setYear(2017);
            dateTime.setMonth(2);// march
            dateTime.setDay(31);// last day of month

            dateTime.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    System.out.println("selected:" + dateTime.getYear() + " " + dateTime.getMonth() + " " + dateTime.getDay());

                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    System.out.println("def selected:" + dateTime.getYear() + " " + dateTime.getMonth() + " " + dateTime.getDay());
                }
            });


Kind regards,
Wim
Re: Change datetime in program does strange things for February and March [message #1773875 is a reply to message #1773832] Fri, 06 October 2017 00:02 Go to previous messageGo to next message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 221
Registered: February 2011
Senior Member
Looks like an issue with the ordering of the commands in the JSON protocol.

It doesn't matter which value you set first or how (via setMonth, setDay, setDate) the month property goes first, followed by the day
["set","w1034",{"month":1,"day":1}]

Calling setMonth on a JS date object causes the date value to roll over until the date is valid
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth
Before setMonth is called the date is 2017-03-31
Calling setMonth to Feb changes it to 2017-02-31, which when rolled forward makes 2017-03-03

setDay is then called, making it 2017-03-01

Perhaps the JSON API needs changing to either enforce the correct ordering or to call a single setDate method instead of individual day/month/year methods.

Either way it's a bug and should be logged as such.
Re: Change datetime in program does strange things for February and March [message #1773920 is a reply to message #1773875] Fri, 06 October 2017 14:08 Go to previous messageGo to next message
Wim Anckaert is currently offline Wim AnckaertFriend
Messages: 32
Registered: December 2012
Member
ok, i created a bug : https://bugs.eclipse.org/bugs/show_bug.cgi?id=525682
Re: Change datetime in program does strange things for February and March [message #1774091 is a reply to message #1773920] Tue, 10 October 2017 13:05 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
we fixed some Date/Time issues in RAP 3.3. Please check the issue with latest RAP release.
Regards,
Ivan
Previous Topic:Integrating Twitter Bootstrap with Eclipse RAP
Next Topic:Cannot use RAP Oxygen SR1 with Equinox SR1a
Goto Forum:
  


Current Time: Thu Mar 28 10:06:48 GMT 2024

Powered by FUDForum. Page generated in 0.02032 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top