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

Bug 517598

Summary: DateTime shows wrong weekday for months with 30 days
Product: [RT] RAP Reporter: Thomas Scheller <t.scheller>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: ivan, stefan.fink
Version: 3.2   
Target Milestone: 3.3 M1   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/#/c/99302/
Whiteboard:
Attachments:
Description Flags
Screenshot showing wrong weekday
none
Patch for solution
none
New maybe nicer patch none

Description Thomas Scheller CLA 2017-05-31 15:21:15 EDT
Created attachment 268684 [details]
Screenshot showing wrong weekday

The DateTime widget shows wrong weekdays if SWT.LONG is set.

In the current demo (no idea which RAP version and which Java version) I can not reproduce this issue.

But if I run the Controls Demo in my own environment with 8 and RAP 3.2.0M6 or RAP 3.1.2 I can reproduce the issue, at least today on 31st of May.

Steps to reproduce:
1. Run controls demo with JDK8 and RAP 3.2.0M6
2. Open the controls demo in any browser
3. In "Type" select "DATE"
4. in "Details" select "LONG"
5. Select "DROP_DOWN" check box
6. Select a date in a month with exactly 30 days (the year does not matter)
7. The wrong weekday is shown.
8. Open the drop_down and the correct weekday is shown in the dropdown, but not in the DateTime widget.
Comment 1 Thomas Scheller CLA 2017-05-31 16:39:32 EDT
Created attachment 268690 [details]
Patch for solution

Issue is in DateTimeDate.js

Year, Month and Date are set separately.

Let's say it is 31.05.2017 and you want to set 16.06.2017

you set first year -> 2017-05-31 and then the month there is no 2017-06-31 so the date will be -> 2017-07-01 if you then set the Day, the result is 2017-07-16 

and that is why you end up on Sunday instead of Friday.

Easy solution is to set the day to 1 and set year and month and target day afterwards.
See attached patch
Comment 2 Thomas Scheller CLA 2017-06-07 15:09:01 EDT
Steps to reproduce:

1. Set client computer date to 31.05.2017 or 31st of any possible month
2. Start any RAP application that uses the calender with SWT.LONG with current RAP version (testet with 3.0.2 and 3.2.0M6)
3. select any date in a month that has only 30 days
4. The displayed weekday is wrong
Comment 3 Ivan Furnadjiev CLA 2017-06-08 02:37:05 EDT
What is your week start day set on the OS? Sunday or Monday?
Comment 4 Ivan Furnadjiev CLA 2017-06-08 02:41:13 EDT
It works for me and my week start day is set to Monday.
Comment 5 Thomas Scheller CLA 2017-06-08 17:37:39 EDT
Do you mean the system locale settings? I am using german/germany so the week starts at monday also. If I run it on the server, the server is set to english and timezone UTC.

I did now try with different locale settings, also with week start on sunday.

The issue is the same.

If I set 31.05.2017 on the client computer (does not matter if I run the software locally or on the server) I have this issue no matter which locale I am using.

Also if I switch the locale with Locale.setDefault or RWT.setLocale the issue is the same.

The date on the server does not play any role. Only the date of the client computer counts.

You can find a test installation here:
https://scheller.es/rapdemo/#DateTime
You can download the running example as enroute self-containing jar here:
https://scheller.es/RAP-DEMO.jar
and start it with 
java -jar RAP-DEMO.jar
Comment 6 Ivan Furnadjiev CLA 2017-06-09 02:30:53 EDT
Which browser did you test? Chrome, Firefox, Egde, IE11? Does the issue persist in all browsers?
Comment 7 Stefan Fink CLA 2017-06-09 16:31:49 EDT
Did a Test on OS X 10.12.5

Chrome 58.0.3029.110 (64-bit) ... OK
Firefox 53.0.3 (64-Bit) ... OK
Safari 10.1.1 (12603.2.4) ... OK

First day in Week is set in the System to Monday
Comment 8 Stefan Fink CLA 2017-06-09 16:33:25 EDT
Used the test installation https://scheller.es/rapdemo/#DateTime
Comment 9 Stefan Fink CLA 2017-06-09 16:35:03 EDT
Also on Chrome 59.0.3071.86 (Offizieller Build) (64-Bit) ... OK
Comment 10 Thomas Scheller CLA 2017-06-09 17:24:03 EDT
Did you really set your system date to 31.07.2017, or 31.05.2017 or 31.08.2017?

1. set the system date to 31.07.2017
2. start your browser and point it to https://scheller.es/rapdemo/demo#DateTime
3. Select Long in "Details" group
4. Select 09.06.2017 (9th of June 2017) (06/09/2017) in the calendar
-> You will see "Sunday 09.06.2017" instead of Friday, so it is 2 days ahead

And that is exactly because the tmpDate results in 09th of July 2017 which is indead a sunday.

And the reason is that year, month and day are set separately which leads to the following:
var tmpDate = new Date();
   // tmpDate is now 31.07.2017
tmpDate.setFullYear( parseInt( this._yearTextField.getText(), 10 ) );
   // tmpDate is now 31.07.2017
tmpDate.setMonth( this._monthInt - 1 );
   // tmpDate is now 01.07.2017 (because 31.06.2017 does not exist)
tmpDate.setDate( parseInt( this._dayTextField.getText(), 10 ) );
   // tmpDate is now 09.07.2017 

For me it does not work with
FireFox 54.0b14 64 bit Mac OS X
FireFox 53.0.3 64 bit Mac OS X
FireFox 55.0a1 64 bit Max OS X

Firefox 53.0.03 64 bit GNU/Linux ARM64

Google Chrome (official) 58.0.3029.110 (64-bit) Mac OS X

Safari 10.1.1 Mac OS X

Eclipse Neon.3 Internal Web Browser 64 bit Max OS X
Comment 11 Thomas Scheller CLA 2017-06-09 17:33:56 EDT
Created attachment 268851 [details]
New maybe nicer patch

Nicer patch which handles the tmpDate like in method _getDaysInMonth
Comment 12 Thomas Scheller CLA 2017-06-09 17:57:35 EDT
I guess the leap year fix introduced this issue.
Could you please tell which version of RWT is installed on the official RAP Controls Demo?
http://rap.eclipsesource.com/demo/release/controls/
I guess it does not have the leap year fix?

By the way, all the demos linked here:
http://www.eclipse.org/rap/demos/
do not work anymore since yesterday and lead to a timeout error.
Comment 13 Thomas Scheller CLA 2017-06-09 18:01:56 EDT
All days in February are exactly the same weekday as in March.
So the 28th of February and 28th of March are both a Tuesday, thats why we do not see a problem with February, but only with all the months that do have 30 days, if today is the 31st.
Comment 14 Stefan Fink CLA 2017-06-10 17:38:05 EDT
Tested again with Chrome and Safari with the procedure described - the Error is there.
Comment 15 Ivan Furnadjiev CLA 2017-06-12 04:11:38 EDT
I think I now understand what is the problem.
Comment 16 Thomas Scheller CLA 2017-06-17 11:54:06 EDT
Tested with p2 repo provided in Hudson
https://hudson.eclipse.org/rap/job/rap-head-runtime-gerrit/2201/artifact/org.eclipse.rap/releng/org.eclipse.rap.build/repository/target/rap-3.2.0-N-20170614-0940.zip

Fix works for me.

Thank you very much.