dschnelldavis / angular2-json-schema-form

Angular 2 JSON Schema Form builder
MIT License
285 stars 177 forks source link

Fix issue where the date displayed by mat-datepicker was one day off from what was specified in the JSON #308

Open albertjke opened 6 years ago

albertjke commented 6 years ago

Fix issue where the date displayed by mat-datepicker was one day off from what was specified in the JSON

PR Type

What changes does this PR include (check all that apply)? [x] Bugfix [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Build process changes [ ] Documentation changes [ ] Other... please describe:

Related issue / current behavior

The date displayed by mat-datepicker is one day off from the data in the JSON.

For example:

  1. Navigate to Angular JSON Schema Form — Demonstration Playground
  2. Set the birthday property in the Input JSON Schema Form Layout section to "1999-07-21"
  3. Observe that in the Generated Form section, the birthday displayed is "07/20/1999"

Notice that this is not an issue for the other design frameworks, which correctly display "07/21/1999".

New behavior

Date displayed in the generated mat-datepicker matches the data in the JSON.

Does this PR introduce a breaking change?

[ ] Yes [x] No

Any other relevant information

At first, thought it was an issue with timezones and mat-datepicker (e.g. here). However, it appears that the functions in date.functions.ts were all working correctly to avoid timezone issues.

Found that when the second matInput in the material-datepicker-widget component was used (the one with *ngIf="!boundControl"), this issue did not come up.

Concluded that the reason this issue still exists is because although the dateValue property is computed correctly, it's not being used in the first matInput (the one with *ngIf="boundControl").