Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

selectDate #589

Closed
cloudymeatball opened this issue Feb 27, 2024 · 4 comments
Closed

selectDate #589

cloudymeatball opened this issue Feb 27, 2024 · 4 comments
Labels

Comments

@cloudymeatball
Copy link

Problem

selectDate() behaves differently depending on whether the input is properly formatted or not. This leads to a properly formatted input date goes to previous day when system timezone is west of UTC +0.

Background

I want the user to be able to enter a day on keyboard, and the datepicker should highlight that day. This works with a malformed date, such as 2024-2-26. But if the value is instead 2024-02-26, it converts 2024-02-26T00:00:00.000Z to my local timezone in the Americas, then show '2024-02-25'. This occurs with every focusin and focusout of the fie, either by mouse or by tabbing. I am only working with date, and it seems to be the same regardless what I put for updateTime, or whether I wrap the '2024-02-26in anew Date()`.

Reproduction

I couldn't quite get css to work in stackblitz, but you can 1) change system timezone to any Americas timezone and 2) go to https://stackblitz.com/edit/sveltejs-kit-template-default-uzophc?file=src%2Froutes%2F%2Bpage.svelte. 3) observe the differences between typing in 2024-02-26 and 2024-2-26.

@cloudymeatball
Copy link
Author

A workaround is

let localDate = new Date(date)
localDate.setDate(localDate.getUTCDate())
datepicker.selectDate(localDate)

This basically adds 24 hours when local date is one less than UTC date.

@t1m0n
Copy link
Owner

t1m0n commented Feb 29, 2024

Hi! Yeah, it seems like a problem =(. Thank you for a bug report, I'll see what I can do about it.

@t1m0n
Copy link
Owner

t1m0n commented Feb 29, 2024

A workaround is

let localDate = new Date(date)
localDate.setDate(localDate.getUTCDate())
datepicker.selectDate(localDate)

This basically adds 24 hours when local date is one less than UTC date.

It is not good idea, because you will get wrong dates in edge cases, when, for example, your date is '2024-03-01' you will get '2024-02-01` instead of what you'd expect.

@cloudymeatball
Copy link
Author

@t1m0n yeah I ended up using the workaround in #592, which fixes all sorts of month drop by 1 error, but your approach of modifying the string is most likely cleaner.

t1m0n added a commit that referenced this issue Mar 5, 2024
* #87 - added option to have same weeks count in every month

* #87 - added description for `fixedHeight` option

* #568 - fixed time change in same range dates, fixes #568

* #556 - added `disableDate` method

* #556 - added tests for `disableDate` method, added docs for new methods

* bumped up node version in docs package.json

* #589 - added conversion from date-only string to local date

* fixed wrong css class handling

* added `silent` params in `update` method, wrote CHANGELOG

* change CHANGELOG.md

* fixed locale generation

* fixed eu locale default export

* bump version 3.5.0
@t1m0n t1m0n closed this as completed Mar 5, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants