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

internal function createDate(date) incompatible with rest of library #592

Closed
cloudymeatball opened this issue Feb 28, 2024 · 2 comments
Closed

Comments

@cloudymeatball
Copy link

// src/utils.js
export function createDate(date) {
    ...
    if (!(date instanceof Date)) {
        resultDate = new Date(date);
    }
    ...
}

Basically, Date(year, month ... ) is interpreted in local time but Date(string) uses the timezone in the string and date strings without time resolves to UTC

This means if the programmer provides a date string without time, such as '2024-02-29', this function will use the UTC midnight, which will lead to problems in various internal date comparisons against other local timestamps, as well populating the datepicker grid itself, especially in min/max mode which uses

_createMinMaxDates() {
      let {minDate, maxDate} = this.opts;

      this.minDate = minDate ? createDate(minDate) : false;
      this.maxDate = maxDate ? createDate(maxDate) : false;
  }

This may be one of the underlying issues in #589, #544, #504, #462, and possibly others. In particular #589 illustrates a divergence between ill- and well-formatted date/time strings as they use different Date() constructors mentioned above.

The best solution probably is to extract year, month ... from date so all internal calls uses new Date(year, month ...) syntax. This enables _createMinMaxDates above to use 00:00:00 for min, and 23:59:59 for max. The other solution is to get the programmer to supply a well-formatted timestamp in the user's timezone. But as a lazy programmer who just want to use a third-party datepicker, I like the first one better.

@cloudymeatball
Copy link
Author

cloudymeatball commented Feb 28, 2024

In the meantime let date = new Date('2024-02-29'); date.setTime(date.getTime() + date.getTimezoneOffset() * 60 * 1000) will set a Date to midnight local time.

@t1m0n
Copy link
Owner

t1m0n commented Mar 5, 2024

fixed in 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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants