2 ms·
IMO there’s no valid reason for date parsers to accept YYYY by default. There’s no sensible use case where you’d want to mix week-based dates with month-based o
by pavlov 8y ago
IMO there’s no valid reason for date parsers to accept YYYY by default. There’s no sensible use case where you’d want to mix week-based dates with month-based ones, and the latter type is way more common.
So why not have a separate “WeekOfYearDateFormatter” subclass for the rare use case? The default class could then explicitly fail when you’re accidentally using YYYY in a format string, saving you from a weird end-of-year bug that might spoil your holiday.
- ivan_gammel 8y agoIt would reduce value of a pattern-based API as an idea, that you can specify any format with combination of special characters. But you are right: this case is so special that it would make sense to protect majority of developers from misuse. If builder pattern is used for date formatters, then it could throw an exception unless certain flag is also set: var formatter = format(“ww-e-YYYY”) .withWoYCalculations() .build();
- naniwaduni 8y agoOne of the big benefits of using these APIs is often that you implicitly accept a greater range of user formats than you anticipated.