3 ms·
Unfortunately, dates can be deceptively messy. Formatting as 2021-01-02 instead of 2021/01/02 may not seem like a big deal, until you try to parse them back. Th
by lhorie 5y ago
Unfortunately, dates can be deceptively messy. Formatting as 2021-01-02 instead of 2021/01/02 may not seem like a big deal, until you try to parse them back. Then this happens:
const a = new Date("2021/01/02"); // Sat Jan 02 2021 00:00:00 GMT-0800 (Pacific Standard Time)
const b = new Date("2021-01-02"); // Fri Jan 01 2021 16:00:00 GMT-0800 (Pacific Standard Time)
Date library authors have been bit hard because date parsing is hard, and they thought it would be easier to let the Date constructor do the job... only to find out via bug reports about the nasty obscurities of the date parsing rabbit hole.
- hathawsh 5y agoThat second example is particularly ugly. It assumes the input is UTC, then it quietly converts that Date to your local time zone. Proper date input usually requires a widget.
- capableweb 5y agoThe context of the conversation is showing dates, not parsing dates. Obviously I'm not advocating in changing your data model to something that would be harder to parse, I'm advocating providing APIs for easier show the date in a format that you want it to show as.
- lhorie 5y agoYes, as a software person, I understand that. I brought this up because we were veering into "client asked" territory, and that where we see clashes between seemingly innocent real world asks and technology rabbit holes.