datetime Editor field - prev/next date selection bugs

datetime Editor field - prev/next date selection bugs

rduncecbrduncecb Posts: 125Questions: 2Answers: 28

I've noticed a couple of bugs in the the built-in datetime field-type control of Editor.
They are both to do with current date selection being at the end of a month and the number of months in the date being more than is valid for the month of the new date selection.

The issues can be reproduced on http://live.datatables.net/ziziwuse/4/edit

Follow these steps to reproduce:
1. Click the Edit button
2. On the form, click the Date entry box, the datetime picker will open.
3. Use the Month prev icon to find Dec 2016, click on 31 Dec 2016, the datetime control will close.
4. Click on the input box again, click the Month Prev button once. Here you will see this first bug, you have to click it twice to get it to go to November.
5. Click the Month Prev button again to display November 2016. Now click November 30th. Here you will see the second bug, the date selected is 30 DECEMBER 2016, not 30 November 2016.

These issues will be encountered whenever the date selected is the last of the month and the next/prev month has less days in it.
The bugs are present in Editor 1.5.6 and Editor 1.6.1

The issue seen at Step 4 can be fixed by adding

that._correctMonth( that.s.display, that.s.display.getUTCMonth() - 1);

as line 7577 (Editor 1.6.1) so it reads

                    if ( parent.hasClass(classPrefix+'-iconLeft') ) {
                        // Previous month
                        that._correctMonth( that.s.display, that.s.display.getUTCMonth() - 1);
                        that._setTitle();
                        that._setCalander();

                        that.dom.input.focus();
                    }

The issue seen at Step 5 can be fixed by adding

                        that.s.d.setUTCDate(1);

at line 7613 (Editor 1.6.1) so it reads:

                        that.s.d.setUTCDate(1);
                        that.s.d.setUTCFullYear( button.data('year') );
                        that.s.d.setUTCMonth( button.data('month') );
                        that.s.d.setUTCDate( button.data('day') );

Roger.

Replies

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    There's also noticed another bug that I haven't looked into yet.
    With a date such as 31 Jan 2016 selected, click the Next month button, then click 28 Feb 2016, it will chose 28 March 2016 instead.

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    Fix for the Next button issue in my previous comment:
    Change the _correctMonth function in dataTables.editor.js to read:

        _correctMonth: function ( date, month ) {
            var days = this._daysInMonth( date.getUTCFullYear(), month );
            var correctDays = date.getUTCDate() > days;
    
            if ( correctDays ) {
                date.setUTCDate( days );
                date.setUTCMonth( month );
            }
            else {
                date.setUTCMonth( month );
            }
        },
    

    Apologies for the quick fire posts.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Thanks very much for letting me know about these issues! I'll have them fixed in Editor 1.6.2.

    Regards,
    Allan

This discussion has been closed.