Leeeeeeeroy Jenkins!
Loosely Typed in Ohio

Software In PHP, Bugs Aren’t Bugs

Today is 29 January 2009. Ask someone today what next month is.

Their answer is “February”.

Ask PHP: print date('m/d/Y', strtotime('next month')); (In english: PHP, please give me a date that looks like MM/DD/YYYY for next month.)

03/01/2009 (1 March 2009)

As it turns out, like all things with computers, you’re asking it wrong. You should write print date('m/d/Y', strtotime(date('Y-m') . '-01 next month')) which is a convoluted way of saying “Give me a date, MM/DD/YYYY, for next month calculated from the first of this month.”

Okay, but this is a bug, right? I mean, php has a strtotime() function for the purpose of letting people write english statements and parsing them into real time values, and it’s acting incorrectly.

Wrong-o.

According to the PHP devs on numerous occasions this is purely correct behavior, and they even cite the GNU date format documentation as proof:

  • PHP says “add one to the month on the date you gave us”
  • You get 31 Feb 2009
  • PHP says “that doesn’t exist!” and rolls it up to the next available real date, 1 March 2009

Except this is bullshit.

By their own admission (in the second linked bug above), the PHP developers get a bunch of bug reports because this doesn’t work as expected. Waving your hands and pointing at the GNU guys doesn’t make it okay, that’s passing the buck. Pointing back at the PHP manual in your standard form reply to these doesn’t help either: the manual page for strtotime() mentions nothing of how it might not work the way you expect it to.

Lesson to be taken away: if your users think it’s a bug, take a good look at it. It might be a bug.

Culture Snow day at Innova

Amidst a blizzard in Columbus, I had a really nice quiet day at the office.

I was amused by the some of my favorite personalities on the team; all in the form of “I’m not coming in today” messages. Roughly in chronological order:

  • Are you in the office…

– Dan by phone

  • Meanwhile, in the frozen North, in the Fortress of Solitude, a structure which appears to be more born of the ice than like it was constructed by human hands, Mr. Kent, mild-mannered alter ego, logs in to his computer and begins his day.

  • Anyway — I hope everyone stays safe and has a great day.

– Kent by email

  • Nuts to this cold, I’m working from the warm confines of home today. 614-555-5555 if needed.

– Jon by email

  • Unbeknownst to Kent, the evil Doctor Eddie was also working from his volcano home. Soon the world would tremble.

– Eddie by email

  • On IM or call us:

  • Chris 614.555.5555

  • Chip 614.783.5555

– Chris by email

  • Is anyone in the office? I don’t think I will be able to get lunch to you today. Please let me know if you are there.

– Mary by email

  • Keith feels bad for his boss, the only one to make it into the office today.

– Keith by Facebook

  • ************ (sensitive)

– Brian to a client via email from a ski trip

  • Chad is excited, 50 degrees and sunny, going to be a good run tonight! Sorry my Ohio friends, enjoy the snow.

– Chad from Oregon

  • NULL

– Bruce by silence

Open Source Innova gets with git

We’ve started using git for more of our projects, which I enjoy a lot. I do a lot of things offline, so keeping changes locally, keeping local branches, etc. is a great thing for what I do and what I like to do.

Oh, and if you’re using different versions of git (say, versions 1.5 and 1.6), the utility doesn’t puke instantly when you try to do anything with it as some others do.

Anyway, I would be remiss in my duties if I didn’t pass on this link — it hasn’t saved my bacon yet, but I’m sure it will. GitReady has the idea of using a daily tip, now categorizing the tips by beginning, intermediate, and advanced usage.

Open Source I <3 iTextSharp

I’ve just started using iTextSharp, a .NET port of the Java iText library. It’s surprisingly good.

The library can create files or streams of PDF. I’m caching my output, so this example uses files:

        // create a document
        Document document = new Document();

        // associate it with a file
        String filepath = Request.MapPath("/Pdfs/test.pdf");
        FileStream file = new FileStream(filepath, FileMode.Create);
        PdfWriter.GetInstance(document, file);

        // write the pdf
        document.Open();
        document.Add(new Paragraph("OMG this thing works"));
        document.Close();

Close
E-mail It
Socialized through Gregarious 42