Calendar-Template-Building Script, Version 3

I published an updated to my Photoshop calendar-template-building script today. The script, which runs on Photoshop CS2 or CS3, creates the components of a calendar as a many-layered PhotoShop document that you can then change and tweak (adding photos, etc.) as you like.

The upgrade is from Version 3 Beta 1 (a major upgrade released a month ago) to Version 3, and incorporates these enhancements:

  • The “February becomes March” bug has been fixed.
  • You can now have weeks start on any day of the month, not just Sunday or Monday as before. Apparently, a calendar starting on Saturday is useful in Arab and Islamic countries.
  • I added sizes A3 and A5 to the list of paper sizes.

(The picture in the calendar above is from when Anthony turned five last week.)

You can download the new version from the script's page.

Geeky Programmer Stuff Follows

The “February becomes March” bug was reported almost right away, but I could not replicate the problem, and now I know why: it only happened when you ran the script at the end of the month. That also explains why I started getting reports on it again yesterday and today.

The problem was with how I was using Javascript's Date object. In Version 3b1, I had this code to create a Date object representing the first day of the target month/year:

var d = new Date(); // for some reason, new Date(year, month-1, 1) always ends up with January
d.setMonth(month - 1);

Silly me, I didn't pay attention to the repercussions of the fact that new Date() creates a date object representing the current date and time. If the current date is the 31st like today, for example, then on the setMonth line when I change the Date object's month to a requested month with less than 31 days, I'm asking for the impossible (February 31st? I don't think so).

At this point, all bets are off because of my mistake, but it turns out that it resolves the conflict by changing the month to one that fits. Hence, February becomes March.

The easy fix is to put the setDate line first, then setMonth and setYear, but while I was there I decided to figure out the issue mentioned in the comment. It turns out that year was sometimes a string (e.g. “2008”) rather than a number, so judicious use of parseInt where required took care of that.

In the new Version 3, that section of code is now simply:

var d = new Date(year, month-1, 1, 0, 0, 0, 0)

Leave a comment...

All comments are invisible to others until Jeffrey approves them.

Please mention what part of the world you're writing from, if you don't mind. It's always interesting to see where people are visiting from.

You can use basic HTML; be sure to close tags properly.

Subscribe without commenting