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.

Date Picker always changes to the previous day

See original GitHub issue

Bug report

Describe the bug

When selecting a date, the DatePicker always changes the previous day

To Reproduce

  • Setup a list with a timestamp
  orderDate: timestamp(),
  • create a new record
  • select a date
  • date will change to the previous day

Expected behaviour

I expect the date a selected to continue to be the date I selected

Screenshots

WY8H3nzUSC

System information

  • OS: macos
  • Browser: chrome & brave

Additional context

The date stored in the database also seems to be the new date “choosen” by the DatePicker…

IOW:

  • If I’m in MST and I select 7/15/2021 07:00
  • The UI updates to 7/14/2021 07:00
  • I save
  • The database displays 2021-07-14 13:00:00

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
mrkutlycommented, Feb 4, 2022

I’m running into a similar issue, but the dates saved in my DB are correct (as in, they are the ones I clicked).

Inspecting the picker with React devtools shows that the date picker is getting the date I clicked as its value prop, but just displaying the wrong date.

Screen Shot 2022-02-03 at 8 51 37 PM Screen Shot 2022-02-03 at 8 51 32 PM

It looks to be caused by this line: https://github.com/keystonejs/keystone/blob/58f525d9118471abb434bf912dd557d282c87250/design-system/packages/fields/src/DatePicker/index.tsx#L86

Formatter code:

const formatter = new Intl.DateTimeFormat(undefined, {
  dateStyle: 'short',
});

export const formatDate = (date: Date): string => formatter.format(date);

Update I checked this in my console and was able to recreate the issue: Screen Shot 2022-02-03 at 9 06 56 PM

Another fun update Looks like using - as the delimiter in the Date constructor causes JS to treat it as an ISO date or something, so the timezones get weird. But using / treats it like a calendar date.

Screen Shot 2022-02-03 at 9 14 05 PM
2reactions
codingwithchriscommented, Mar 23, 2022

@bladey I posted another bug report for this in Slack, but the issue still exists and has not been addressed 😢 https://keystonejs.slack.com/archives/C01STDMEW3S/p1648051507931239

Our experience is the exact same as others.

Upon closer inspection of the DatePicker component in Keystone, the value passed to the component is correct.

Screen Shot 2022-03-23 at 11 57 19 AM

However the date information given to aria-label and children is incorrect. In our case it is always off by 1 day and 5 hours

Screen Shot 2022-03-23 at 11 57 32 AM

Database Value

Screen Shot 2022-03-23 at 12 06 50 PM

UI Display

Screen Shot 2022-03-23 at 12 06 07 PM

This is a critical bug IMO 😕 It’s causing massive confusion for our clients in the medical field who are relying on the application we built to deliver accurate information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

datepicker date off by one day - Stack Overflow
The reason you're off by day is because UTC time is for a timezone that is ahead of yours. (Since you didn't also...
Read more >
DatePicker - date selected is previous day if changing month ...
open a datepicker (opens up in november); move to next or previous month (ex. move to december); select a date (ex. december, 12)....
Read more >
Date Picker showing one day earlier, but there is no history of ...
You can see in the history that they were set correctly, but when we look at them the dates are off (but there...
Read more >
changing selected date should ALWAYS update text input
With the current datepicker, selecting a different year/month using the dropdowns does NOT cause the text in the input field to update.
Read more >
Date picker shows the previous day in Report New UI if the ...
1. Make sure to select the system timezone as UTC+10. 1. Create a new report for any table, for example the Incident table....
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