react-dropdown-date icon indicating copy to clipboard operation
react-dropdown-date copied to clipboard

Input displaying one day off

Open JMcAmmond opened this issue 6 years ago • 4 comments

When selecting a date, the value is being returned correctly but it displays as one day off. This is probably because when the date objects are built they accept a string that doesn't account for time zones.

JMcAmmond avatar Jul 17 '19 16:07 JMcAmmond

I'm still seeing this issue. I initialize with selectedDate='2000-01-20', and the dropdowns show January 19 2000.

biomiker avatar Jul 31 '20 22:07 biomiker

@JMcAmmond is right, it relates to Time Zones. Specifically, the Date(selectedDate) constructor which Mozilla recommends not using: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

This issue is probably browser and data dependent but will reproduce on Chrome when using the recommended yyyy-mm-dd format. A workaround is to use slashes instead of dashes as the delimiter; this causes Date.parse to interpret the date in local time. Adding .replace(/-/g, '/') to my date string worked well.

biomiker avatar Jul 31 '20 23:07 biomiker

@biomiker Is this still a problem ? Do you have a workaround ?

ssxv avatar Sep 30 '20 17:09 ssxv

The workaround I mentioned on Jul 31 is still necessary. I use yyyy/mm/dd instead of yyyy-mm-dd.

biomiker avatar Sep 30 '20 17:09 biomiker