You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Internally, itty-time was using the build-in Date functions for manipulating time from a fixed date. This meant using things like setHours and setMonth and such. getSeconds was actually a derivative function of datePlus, which needed those bits. Regardless, some of these functions return inconsistent results, which is especially irritating when you're asking for a very easily calculation like seconds, days, etc.
The Solution
I've reworked itty-time to make getSeconds the first-class citizen, and default to using basic time math for all "obvious" units (seconds, minutes, hours, days, weeks), and only use the built-ins for months and years (where you don't want to add a fixed number of seconds, you typically want to move the month/year). The new solution should be faster in most cases (simple multiplication is faster than getters/setters), and only added 11 bytes total, as much of the specific unit translation to use all the setters could be removed. Furthermore, with getSeconds now not dependent on the other functions, the import for that alone should actually be smaller!
Notes
I've verified it in your demo code (that was super helpful btw!), and confirmed the value remains 86400 now :)
I noticed some weird behavior when trying out getSeconds in an Advent of Vue challenge (that I did in Svelte) and had to replace it sadly.
Sometimes getSeconds('1 day') and the others return weird values.
Here is a minimal repro that showcases it with a flickering number and in the console when using chrome 107.0.5304.121: https://svelte.dev/repl/31907b32e50042d8b8f068148de739a3?version=3.53.1
EDIT: same on firefox 107.0 (lol they share version numbers atm?) and safari 16.1
The text was updated successfully, but these errors were encountered: