ng-admin: editionView() returns date decremented by 1 day

Description

In my index.js:

project.editionView().fields([
         nga.field('devdate', 'date')
           .format('MM-dd-yyyy')
           .label('Development Date'),
    ]);

The day (dd) is decremented by 1 but the above works fine (displays the correct devdate response) in project.creationView().fields.

Steps to Reproduce

Plunkr: http://plnkr.co/edit/M70PbzPLBCGVZ9dollvj?p=preview

  1. Set the browser to CST or any timezone less than GMT
  2. Select ‘Projects’ in the left hand pane
  3. Select ‘Id’ of any of the projects in the Project List; notice the ‘Dev Date’
  4. Now in the Edit Project form, the ‘Development Date’ displays decremented by 1 day
  5. If user chooses to save, the ‘Dev Date’ will be stored in the db incorrectly.

I’ve tried it with and without the .format and .label with the same results. Again, creationView works just fine. And the datepicker requests with the devdate:"2016-12-08" so it is stored in the database accurately.

Expected behavior: Display 12-07-2016

Actual behavior: Displays 12-06-2016

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 31 (14 by maintainers)

Most upvoted comments

I’m experiencing a similar problem with my Datepicker field, the value field is inconsistent with what I selected. I selected January 1, 2015, the field value changed to June 21, 2015. I’m also getting “Error: 10 $digest() iterations reached.” in my console log. The later error could be my app specific.

I pinpointed the error down to these codes. My $digest error disappeared when I commented out the $watch statement.

        // maDateField.js LINE 30
        scope.$watch('value', function (newValue, oldValue) {
            if (newValue === oldValue) {
                return;
            }
            
            if (!newValue) {
                scope.rawValue = null;
                return;
            }

            scope.rawValue = scope.value instanceof Date ? scope.value : new Date(scope.value);
        });

The solution that I came up with is to unregister $watch() instead of return inside the IF conditions. Replace the above statement with these codes.

        var $watchValue = scope.$watch('value', function (newValue, oldValue) {
            if (newValue === oldValue) {
                $watchValue();
            }

            if (!newValue) {
                scope.rawValue = null;
                $watchValue();
            }

            scope.rawValue = scope.value instanceof Date ? scope.value : new Date(scope.value);
        });

@wannarka @Phocea @Kmaschta @fzaninotto Can you please confirm the fixed and merge it to master? It is a critical bug.