question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

editionView() returns date decremented by 1 day

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:31 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
thachpcommented, Feb 5, 2017

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.

0reactions
thanhbuieacommented, Nov 28, 2017

hi @Phocea , I’m experiencing with DateField infinite watches loop in EditionView (Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: ), my using version is 1.0.6. Any progress to get this problem resolved. We tried applying the fix that @thachp recommended above, and it works. Could you please let me know how to get the progress on and completed quickly?

Read more comments on GitHub >

github_iconTop Results From Across the Web

datepicker date off by one day - Stack Overflow
My project is having the same issue where depending on the syntax of my date input, the date returns as input or off...
Read more >
Datepicker returns minus 1 day - Power Platform Community
The date returned to the server from a DatePicker control is consistently one day less than the date entered. So enter, say, April...
Read more >
Options - Tempus Dominus - Bootstrap 4
Returns the component's model current date, a moment object or null if not set. ... moment by passing one of the following strings...
Read more >
JS Datetime bug — auto set back one day | by Fred Wong
I came across this bug about the JavaScript Datetime object. The application set the date to 2019–01–31to the database but when I tried...
Read more >
Date Picker Return Wrong Date - ServiceNow Community
I realized one thing when I'm working on Business Rule and Script Include ... I understand that GlideDateTime() would return me the UTC ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found