When a date that is delimited with slash characters is parsed, it parses correctly. However, if dash is the delimiter (as is the default for Postgres), the date is parsed and ends up one day off.
To fix this, I always replace the first two dashes with slashes. Like this:
So, we need a simple date parsing utility function in greyspots.js that's just a wrapper for new Date() and we need to use it in gs-datetime to prevent further errors. In the future, instead of writing the code above for every new date function or element, we'll just use the new function.
The built-in Javascript date parser has an issue that most of our code takes into account. However,
gs-datetime
doesn't have the fix.Here is an example of a date being parsed correctly:
Here is an example of a date being parsed incorrectly:
When a date that is delimited with slash characters is parsed, it parses correctly. However, if dash is the delimiter (as is the default for Postgres), the date is parsed and ends up one day off.
To fix this, I always replace the first two dashes with slashes. Like this:
So, we need a simple date parsing utility function in greyspots.js that's just a wrapper for
new Date()
and we need to use it ings-datetime
to prevent further errors. In the future, instead of writing the code above for every new date function or element, we'll just use the new function.