Skip to content

Comment on Fix date-handling bug when today’s date is later than the target month

Comments

Unlike many issues with dates, this one is purely a result of a wrong API design. It does not make sense to "set a component" of a date all by itself (unlike hours/minutes/seconds in a day), so an API that allows you to so is plain broken.

Correct API would be to set the components D,M,Y all at once and have them validated on the spot before returning a valid Date value.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.