palantir / blueprint

A React-based UI toolkit for the web
https://blueprintjs.com/
Apache License 2.0
20.75k stars 2.18k forks source link

[DateTime] Improve docs around using DateInput/DateRangeInput in controlled mode #1826

Open cmslewis opened 7 years ago

cmslewis commented 7 years ago

See https://github.com/palantir/blueprint/issues/955#issuecomment-345784633. Pasted here:


So here's what I'm seeing:

selectedDate:     Sun Feb 15 2015 00:00:00 GMT-0800 (PST)
this.state.value: 2015-02-15
valueAsDate:      Sat Feb 14 2015 16:00:00 GMT-0800 (PST)

Looks like onChange is receiving the correct date; it's the new Date(...) value that's erroneous. From the Date docs on MDN (link):

Note: parsing of date strings with the Date constructor (and Date.parse, they are equivalent) is strongly discouraged due to browser differences and inconsistencies. Support for RFC 2822 format strings is by convention only. Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local.

Looks like this works fine:

new Date(2015, 02, 15) // returns proper date in PST: Sun Mar 15 2015 00:00:00 GMT-0700 (PDT)

Closing as the component isn't behaving incorrectly. However, we could use better docs here. Will open a follow-up issue.

alshain commented 6 years ago

Probably related: #1355

Will investigate further next week or so.