New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update MomentJS dependency #9382
Update MomentJS dependency #9382
Conversation
Origin: #9376
The commit fixes the tests.
expect(getDataAtRow(2)).toEqual(['BMW', '320i Coupe', '07/24/2011', 30500]); | ||
expect(getDataAtRow(3)).toEqual(['Audi', 'A4 Avant', '11/19/2011', 33900]); | ||
expect(getDataAtRow(4)).toEqual(['Citroen', 'C4 Coupe', '12/01/2008', 8330]); | ||
expect(getDataAtRow(0)).toEqual(['Opel', 'Astra', '02/02/2004', 7000]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need some root-cause analysis of why is this changed.
Maybe the reviewer (@jansiegel) can explain this? I know that @budnix is busy with other issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that before updating the lib, the date values sorting does not work correctly. At least in that test case. For example, the results for sorting rows ascending:
Before (it's sorted without any noticeable pattern):
'01/14/2006'
'02/02/2004'
'07/24/2011'
'11/19/2011'
'12/01/2008'
After:
'02/02/2004'
'01/14/2006'
'12/01/2008'
'07/24/2011'
'11/19/2011'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry, but this is not the root cause. The root cause seems related to the fact that the test, despite its name, provided wrongly formatted data to Moment.js, and tested that Moment.js does not sort in that case. After the change, Moment.js sorts even when it is given wrongly formatted data.
Compare the format given in line 1009 and the data provided in lines 996-1002
handsontable/handsontable/src/plugins/columnSorting/__tests__/columnSorting.spec.js
Lines 993 to 1009 in 5ec0fa6
it('should sort date columns along with empty and null values', () => { | |
handsontable({ | |
data: [ | |
['Mercedes', 'A 160', '01/14/2006', 6999.9999], | |
['Citroen', 'C4 Coupe', '12/01/2008', 8330], | |
['Citroen', 'C4 Coupe null', null, 8330], | |
['Citroen', 'C4 Coupe empty', '', 8330], | |
['Audi', 'A4 Avant', '11/19/2011', 33900], | |
['Opel', 'Astra', '02/02/2004', 7000], | |
['BMW', '320i Coupe', '07/24/2011', 30500] | |
], | |
columns: [ | |
{}, | |
{}, | |
{ | |
type: 'date', | |
dateFormat: 'mm/dd/yy' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's sorted without any noticeable pattern
I think it was sorted kind of as a string, so in this case by the month number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use Moment.js in the strict mode? https://momentjs.com/guides/#/parsing/strict-mode/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should use Moment.js in the strict mode? https://momentjs.com/guides/#/parsing/strict-mode/
I would be for it. It's better to only sort the date-type values based on the dateFormat
. Without leaving the room for guesses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A partial root cause analysis by me:
- in the forgiving mode, if Moment cannot parse a date, it uses
Date
constructor - in Moment 2.24.0, the date
moment('01/14/2006', 'mm/dd/yy')
was not parsed at all. TheDate
constructor fallback returned the current datetime (https://jsfiddle.net/warpech/d9qako0g/4/) - in Moment 2.25.0 (actually in this commit moment/moment@0c7d8da, a squashed version of [feature] Add era support for en,ja (closes #4591) moment/moment#4599), the character
yy
became significant and that date was parsed without resolving to theDate
constructor. However, parsing is not good either. Moment parses this date to2006-01-01
. (https://jsfiddle.net/warpech/d9qako0g/4/) - with
strict
flag turned off, all tested Moment versions from 2.24.0 to 2.29.2 consistently say it is an incorrect date.
TL;DR Moment team unknowingly changed the interpretation of incorrect dates. If we used strict
, the problem would not appear. Because we didn't use strict, the problem slipped through.
I think we should enforce strict
with an explanation in the migration guide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was advised that there are parts of Handsontable that treat the forgiving mode as a feature and we should not remove it. Discussion: https://handsoncode.slack.com/archives/C4PV4S33Q/p1650384660407479?thread_ts=1649328227.856499&cid=C4PV4S33Q
We discussed on the today's daily (https://kb.handsontable.com/pages/viewpage.action?pageId=56461739) that @jansiegel will take over this PR. According to the notes from the daily, we need:
|
@@ -1051,7 +1051,7 @@ describe('ColumnSorting', () => { | |||
{}, | |||
{ | |||
type: 'date', | |||
dateFormat: 'mm/dd/yy' | |||
dateFormat: 'MM/DD/YYYY' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file also uses the old notation dateFormat: 'mm/dd/yy'
on lines 294, 1532 (and also in 2 places in multiColumnSorting.spec.js
).
Why were other lines not affected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those remaining tests seem to not be sorted by the column containing the dates, so the dateFormat
is pretty much redundant, I'll change it, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jansiegel – I'm adding my changes in #9409
Just checking: should we update anything in the correctFormat
API ref? https://handsontable.com/docs/api/options/#correctformat
I don't think so - our API didn't change, what has changed is some logic on Moment's side, so until we have a more detailed specification on what exactly we should allow being automatically corrected, I'd leave it as it is. |
Launch the local version of documentation by running: npm run docs:review 90dfc4f1d2b207457890fd44d2ff32ab27031c72 |
* Update MomentJS dependency Origin: #9376 * Updating momentJS fixes an issue with sorting date values The commit fixes the tests. * Fix dateFormat pattern * - Correct the date format on the remaining cases in multiColumnSorting.spec.js. * Bump moment dependency for the 'handsontable' workspace and the root directory. * Docs: Adding docs changes related to the Moment.js dependency update (#9409) Co-authored-by: Jan Siegel <jansiegel@users.noreply.github.com> Co-authored-by: Jan Siegel <js.ziggle@gmail.com> Co-authored-by: Kuba Jakub <jakub.wisniewski@handsontable.com>
Context
The PR upgrades the
moment
library to 2.29.2. The PR applies all changes from the origin PR added by the bot (#9376), adds necessary changelog entry, and updates thepackage-lock.json
file.Migration guide
If I remember correctly, some of the users that use the MomentJS library within their apps struggle with an issue where the library was double transpiled in the bundle file. One version for the developer's app and one for Handsontable dependency. The workaround for that was using the same version of the library as Handsontable.
The PR changes the version, so it can be advisable to mention this in the migration guide.
Types of changes
Related issue(s):
Affected project(s):
handsontable
Checklist: