6eDesign / svelte-calendar

A lightweight datepicker with neat animations and a unique UX.
https://6edesign.github.io/svelte-calendar/
MIT License
542 stars 89 forks source link

TypeError: weeks[0] is undefined when using Change Timezone extension #50

Closed pzmarzly closed 5 years ago

pzmarzly commented 5 years ago

With this extension enabled, I keep getting this error, both in Firefox, and Chrome, no matter which timezone I choose:

DeepinScreenshot_select-area_20191019185351

Current real date on my PC is 2019-10-19 19:41, Saturday.

Smallest reproducible example code:

<script>
    import Datepicker from 'svelte-calendar'
    let selected
    const format = "#{l}, #{j} #{F} #{Y}"
</script>
<Datepicker {format} bind:selected />

I don't think any of my users will have this extension installed, but this behaviour shouldn't happen nonetheless.

6eDesign commented 5 years ago

@pzmarzly I am unable to reproduce this in the svelte.dev repl even when I set my system date to the one you provided and enable this extension. I may need more details. I don't see anything in particular in this function which would break given a change to the timezone but maybe I'm missing something.

pzmarzly commented 5 years ago

I made a repo with a tiny website that shows this behaviour. I also uploaded the website there. Please let me know whether you are able to reproduce the error with it. If not, I'll try to debug the calendar myself.

6eDesign commented 5 years ago

@pzmarzly I am not seeing this error in chrome (Windows), with the extension (https://chrome.google.com/webstore/detail/change-timezone-time-shif/nbofeaabhknfdcpoddmfckpokmncimpj?hl=en) installed and active. Do you have more specific steps needed to reproduce the issue you're seeing?

pzmarzly commented 5 years ago

I dug for a bit, and found out that there is a problem with Date.getMonth() when using that extension (it e.g. still reports September on 2019-10-01 00:00, unlike the JS API). This is definitely extension's bug, not svelte-calendar's. It looks like it could be worked around by changing these lines:

-  let date = new Date(year, month, 1);
+  let date = new Date(year, month, 1, 15);
-  let date = new Date(start.getFullYear(), start.getMonth(), 1);
+  let date = new Date(start.getFullYear(), start.getMonth(), 1, 15);

, but I don't suggest we do that - I'm leaving this just for future reference.

Looking at that extension's review page, I can see svelte-calendar is not the only calendar affected:

after a few days of use: breaks a number of sites, including flight booking at westjet.com (calendars do not work at all) and managing my Mikrotik router (all dates are incorrect by a day.)

I'll try contacting the extension's author. Anyway, the issue can be closed.

Do you have more specific steps needed to reproduce the issue you're seeing?

Sadly, not really. The bug also happens on my Ubuntu VM with clear Firefox (aside of that extension), English (US) locale. I tried setting different timezones, it made no difference.