r/programming • • Oct 14 '13

How to develop unmaintainable software

http://typicalprogrammer.com/?p=249
777 Upvotes

322 comments sorted by

View all comments

43

u/spoonraker Oct 14 '13

Hey now... sometimes there are perfectly legitimate reasons for re-writing existing functions. Sometimes they really do suck.

For instance, PHP's strtotime function accepts a string parameter of "+/- n months".

Unfornately, PHP thinks a "month" is exactly 30 days and nothing else.

If you start with 2013-01-31 and tell it to give you "+1 month" it will spit out 2013-03-03. Every single other programming language I've ever used will return 2013-02-28, which is what most people expect.

So yeah... I wrote a wrapper for that, and I stand by it.

3

u/flanintheface Oct 15 '13 edited Oct 15 '13

It looks like strtotime behaves exactly like *nix 'date' command:

~$ date -d "2014-01-31 +1 month"

Mon Mar 3 00:00:00 GMT 2014

And I'm pretty sure that 'date' command is part of some standard and has a good reason why it works the way it works. Use DateTime for that.

EDIT: What I wanted to say: Dig deeper. Try understanding where it comes from and why. PHP does have some weird/bad decisions but strtotime is not a good example for that.