planetscale / database-js

A Fetch API-compatible PlanetScale database driver
https://planetscale.com/docs/tutorials/planetscale-serverless-driver
Apache License 2.0
1.17k stars 35 forks source link

perf: faster sanitize date #131

Closed andrewvasilchuk closed 11 months ago

andrewvasilchuk commented 1 year ago

Use String#slice instead of String#replace since it is ~20% faster in this particular case according to this performance test.

iheanyi commented 1 year ago

Going to close this one out. We only want to use replace in the sense that if the Z exists at the end, remove it. With this change, we're losing precision if the string doesn't contain the timezone.

andrewvasilchuk commented 1 year ago

@iheanyi thanks for the feedback. Following MDN Date.prototype.toISOString() and ECMAScript Language Specification, a date string, returned from the Date#toISOString method always contain a "Z" char at the end.

iheanyi commented 1 year ago

Good point, that's a good call then. I'll reopen this then

ayrton commented 11 months ago

Thank you