Skip to content
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

editionView() returns date decremented by 1 day #1271

Closed
wannarka opened this issue Dec 8, 2016 · 31 comments
Closed

editionView() returns date decremented by 1 day #1271

wannarka opened this issue Dec 8, 2016 · 31 comments
Assignees

Comments

@wannarka
Copy link

wannarka commented Dec 8, 2016

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

@Kmaschta
Copy link
Contributor

Kmaschta commented Dec 9, 2016

It's perhaps a timezone issue. Have you tried with different timezones, or with UTC?

@wannarka
Copy link
Author

wannarka commented Dec 9, 2016 via email

@Kmaschta
Copy link
Contributor

Kmaschta commented Dec 9, 2016

Can you provide a Plunkr that reproduce the issue, following the issue template?

@wannarka
Copy link
Author

wannarka commented Dec 15, 2016 via email

@Kmaschta
Copy link
Contributor

Your Plunkr aims the url http://dashboard.globalvetlink.com which is down.
You need to make it works in a standalone way.

@wannarka
Copy link
Author

wannarka commented Dec 15, 2016 via email

@wannarka
Copy link
Author

wannarka commented Dec 15, 2016 via email

@Phocea
Copy link
Contributor

Phocea commented Dec 15, 2016

I also get a 404 error. This is due to a cross origin problem

XMLHttpRequest cannot load http://dashboard.globalvetlink.com/projects?_end=30&_order=DESC&_sort=id&_start=0. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://run.plnkr.co' is therefore not allowed access.

@wannarka
Copy link
Author

wannarka commented Dec 15, 2016 via email

@Phocea
Copy link
Contributor

Phocea commented Dec 15, 2016

Maybe its just me being tired, but I dont see the issue.

  • Ran the plunkr
  • Selected Projects / clicked on 66
  • Paylod received is: {"id":"66","projname":"Feline","owner":"Jan Johnson","description":"Today's New York Times features the story Holly the Cat, a Florida feline who traveled nearly 200 miles to get home. Ms. Johnson's cat is now famous.","devdate":"2016-12-07","stage":"Development and Beta","parked":true}
  • Development Date is displayed: 12-07-2016

So the displayed date is the same as the payload devdate (?).
If you see it as the 8th, this might well be a GMT issue .. payload is expected to be received as GMT date but local timezone is used on your browser display

@wannarka
Copy link
Author

wannarka commented Dec 15, 2016 via email

@Phocea
Copy link
Contributor

Phocea commented Dec 15, 2016

Cannot see your screenshot.

On your current plunker, every date displayed, on the listview or on the individual edit views, are exactly the date received inside the response payload:

[{"id":"66","projname":"Feline","owner":"Jan Johnson","description":"Today's New York Times features the story Holly the Cat, a Florida feline who traveled nearly 200 miles to get home. Ms. Johnson's cat is now famous.","devdate":"2016-12-07","stage":"Development and Beta","parked":true},{"id":"61","projname":"Canine","owner":"Mark Anderson","description":"The Spinone Italiano is an Italian dog breed. It was originally bred as a versatile gun dog. To this day, the breed still masters that purpose. The Spinone is a loyal, friendly and alert dog with a close lying, wiry coat.","devdate":"2016-12-08","stage":"Full Commercialization","parked":false},{"id":"18","projname":"Poultry","owner":"Mark Anderson","description":"\"Poultry\" means chickens, turkeys, domestic waterfowl, ratites, and domestic game birds, except doves and pigeons.","devdate":"2016-12-06","stage":"Development and Beta","parked":false},{"id":"4","projname":"Equine","owner":"Mark Anderson","description":"Certificate of Veterinary Inspection (CVI). All equine imported into the state of Iowa shall be accompanied by a CVI.","devdate":"2016-09-04","stage":"Feasibility & Planning","parked":true},{"id":"3","projname":"Cattle","owner":"Jan Johnson","description":"Recognized slaughter establishment means a slaughtering establishment operating under the\r\nprovisions of either the Federal Meat Inspection Act (21 U.S.C. 601 et seq.) or an equivalent state meat\r\ninspection program.","devdate":"2016-10-28","stage":"Concept Development","parked":true},{"id":"1","projname":"Swine","owner":"Jan Johnson","description":"Transitional swine means swine that have been, or have had the potential to be, exposed to feral swine.","devdate":"2016-10-30","stage":"Idea Generation","parked":false}]

capture d ecran 2016-12-15 20 58 48

@wannarka
Copy link
Author

wannarka commented Dec 15, 2016 via email

@Phocea
Copy link
Contributor

Phocea commented Dec 16, 2016

Ok for the screenshot, but what is the payload you actually receive in the browser. Check in the developper console in Chrome (CTRL+SHIFT+I).
If it is "2016-12-07", then as you can see in my screenshot , it is definitaly a regional setting problem. This is probably gthe case because when you save you are saying that it is the correct date..so probably the JSON paylod of the POST or PUT is also correct, even though displayed wrong

You may try to adapt the display date (#1091) or play with the [datepicker config] (https://angular-ui.github.io/bootstrap/)

@wannarka
Copy link
Author

wannarka commented Dec 16, 2016 via email

@wannarka
Copy link
Author

I tried adapting the display date (#1091) but it appears that the transform(dateFormatting) happens after the datepicker displays the wrong date. It leaves me with only the datepicker config.

@wannarka
Copy link
Author

Changing the datepicker config will not address the issue either. I traced the code down and the #devDate value is "2016-12-06" before the input-group datepicker class is called. As we have already established, the devDate is correct ("2016-12-07") coming from the API in the browser and also correct in the creationView. My best guess is it is getting changed by ng-admin-field-devDate.

@thachp
Copy link

thachp commented 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.

@estorco
Copy link

estorco commented Feb 6, 2017

I experienced the same issue with the Datepicker field and thachp's solution worked for me!

@thachp Kudos!

@Phocea
Copy link
Contributor

Phocea commented Feb 6, 2017

@thachp its a bit difficult to verify this in our timezone. In any case, could you please create a PR with your changes so the whole team can have a look ?

@wannarka
Copy link
Author

wannarka commented Feb 6, 2017 via email

@matheo
Copy link
Contributor

matheo commented Mar 4, 2017

This workaround may help here:
#1305 (comment)

@Kmaschta
Copy link
Contributor

Kmaschta commented Mar 8, 2017

Okay, I just fixed an issue with the DateField.
I'm not sure that it will fix this issue about timezone, we do not manage it properly.

Let's try it again when the #1318 will be published.

@Kmaschta
Copy link
Contributor

Kmaschta commented Mar 8, 2017

It seems fixed with the 1.0.1 as you can see on this Plunkr.

I close this issue, feel free to open it again if needed and share your feedback.
Thank you all!

@Kmaschta Kmaschta closed this as completed Mar 8, 2017
@wannarka
Copy link
Author

wannarka commented Mar 9, 2017 via email

@Kmaschta
Copy link
Contributor

Kmaschta commented Mar 9, 2017

I am not able to reproduce, even with a timezone in the USA.
If I click on the 3rd March, the input will be filled with 2017-03-03.
I don't find a field named Next Review Date either.

Can you give me more detailed infos about the bug?

@wannarka
Copy link
Author

wannarka commented Mar 9, 2017 via email

@Kmaschta
Copy link
Contributor

Kmaschta commented Mar 9, 2017

Okay, better!

I was able to reproduce the bug until I type Ctrl + F5.
I suspect a cache issue, because I'm unable again to reproduce the error.

Can you confirm?

@wannarka
Copy link
Author

wannarka commented Mar 9, 2017 via email

@matheo
Copy link
Contributor

matheo commented Mar 9, 2017

Indeed, I'm GMT-5 and I see a different Date on showView and editView.

IMHO the field needs to adjust the timezone to avoid modifications on the original value by the javascript's Date object.

@thanhbuiea
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants