{"id":619,"date":"2007-10-31T21:55:33","date_gmt":"2007-10-31T12:55:33","guid":{"rendered":"https:\/\/regex.info\/blog\/2007-10-31\/619"},"modified":"2007-10-31T21:55:33","modified_gmt":"2007-10-31T12:55:33","slug":"calendar-template-building-script-version-3","status":"publish","type":"post","link":"https:\/\/regex.info\/blog\/2007-10-31\/619","title":{"rendered":"Calendar-Template-Building Script, Version 3"},"content":{"rendered":"\n\n\n\n<div class='ic'><a name='039358Cal' href=\"\/i\/JEF_039358Cal.jpg\"\n><img loading=\"lazy\" decoding=\"async\" src=\"\/i\/JEF_039358Cal_sm.jpg\" width=\"750\" height=\"539\"\nalt=\"\"\nid=\"i039358Cal\"\nstyle=\"border:none; padding:none\"\/><\/a><\/div>\n\n<p>I published an updated to my <a\nhref=\"\/blog\/photo-tech\/calendar\/\">Photoshop\ncalendar-template-building script<\/a> today. The script, which runs on\nPhotoshop CS2 or CS3, creates the components of <span class='nobr'>a calendar<\/span> as <span class='nobr'>a\nmany<\/span>-layered PhotoShop document that you can then change and tweak (adding\nphotos, etc.) as you like.<\/p>\n\n<p>The upgrade is from <b><span class='nobr'>Version 3<\/span> Beta 1<\/b> (<span class='nobr'>a major<\/span> upgrade <a\nhref=\"\/blog\/2007-09-26\/585\">released <span class='nobr'>a month<\/span> ago<\/a>) to\n<b><span class='nobr'>Version 3<\/span><\/b>, and incorporates these enhancements:<\/p>\n\n<ul style='margin-top:5px'>\n  <li>The &#8220;February becomes March&#8221; bug has been fixed.<\/li>\n  <li>You can now have weeks start on any day of the month, not just Sunday or Monday as before. Apparently, <span class='nobr'>a calendar<\/span> starting on Saturday\n       is useful in Arab and Islamic countries.<\/li>\n  <li><span class='nobr'>I added<\/span> sizes A3 and A5 to the list of paper sizes.<\/li>\n<\/ul>\n\n<p>(The picture in the calendar above is from when <a href=\"\/blog\/2007-10-23\/614\">Anthony turned five<\/a> last week.)<\/p>\n\n<p>You can download the new version from the <a\nhref=\"\/blog\/photo-tech\/calendar\/\">script's page<\/a>.<\/p>\n\n<p><b>Geeky Programmer Stuff Follows<\/b><\/p>\n\n<p>The &#8220;February becomes March&#8221; bug was reported almost right away, but <span class='nobr'>I\ncould<\/span> not replicate the problem, and now <span class='nobr'>I know<\/span> why: it only happened when\nyou ran the script at the end of the month. That also explains why <span class='nobr'>I\nstarted<\/span> getting reports on it again <a\nhref=\"\/blog\/photo-tech\/calendar\/#comment-10909\"\nclass='quiet'>yesterday<\/a> and <a\nhref=\"\/blog\/photo-tech\/calendar\/#comment-10920\"\nclass='quiet'>today<\/a>.<\/p>\n\n<p>The problem was with how I was using Javascript's <b>Date<\/b> object. <span class='nobr'>In Version<\/span> 3b1, <span class='nobr'>I had this<\/span> code to create <span class='nobr'>a Date<\/span> object representing the first\nday of the target month\/year:<\/p>\n\n<pre class='code'>\nvar d = new Date(); \/\/ <i>for some reason, new Date(year, month-1, 1) always ends up with January<\/i>\nd.setYear(year);\nd.setMonth(month - 1);\nd.setDate(1);\n<\/pre>\n\n<p>Silly me, I didn't pay attention to the repercussions of the fact that\n<tt><b>new Date()<\/b><\/tt> creates <span class='nobr'>a date<\/span> object representing the current\ndate and time. <span class='nobr'>If the current<\/span> date is the 31st like today, for example,\nthen on the <b>setMonth<\/b> line when <span class='nobr'>I change<\/span> the Date object's month to <span class='nobr'>a\nrequested<\/span> month with less than 31 days, <span class='nobr'>I'm asking<\/span> for the impossible\n(February 31st? <span class='nobr'>I don't<\/span> think so).<\/p>\n\n<p>At this point, all bets are off because of my mistake, but it turns out\nthat it resolves the conflict by changing the month to one that fits.\nHence, February becomes March.<\/p>\n\n<p>The easy fix is to put the <b>setDate<\/b> line first, then\n<b>setMonth<\/b> and <b>setYear<\/b>, but while <span class='nobr'>I was<\/span> there <span class='nobr'>I decided<\/span> to\nfigure out the issue mentioned in the comment. <span class='nobr'>It turns<\/span> out that\n<b>year<\/b> was sometimes <span class='nobr'>a string<\/span> (e.g. &#8220;2008&#8221;) rather than <span class='nobr'>a number,<\/span> so\njudicious use of <b>parseInt<\/b> where required took care of that.<\/p>\n\n<p>In the new <span class='nobr'>Version 3,<\/span> that section of code is now simply:<\/p>\n\n<pre class='code'>\nvar d = new Date(year, month-1, 1, 0, 0, 0, 0)\n<\/pre>\n\n<style type=\"text\/css\">\n  #post619 pre.code { margin-left:1em;\n                      padding: 5px 0 5px 2em;\n                      border: solid 1px #D8FFD8;\n                      border-left: solid 2px gray;\n                      background-color: #334 }\n  #post619 pre.code i { font-size: 85% }\n<\/style>\n\n\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p> <p>The upgrade is from <b>Version 3 Beta 1<\/b> (a major upgrade released a month ago) to <b>Version 3<\/b>, and incorporates these enhancements:<\/p> 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 [...]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,4],"tags":[],"_links":{"self":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/posts\/619"}],"collection":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/comments?post=619"}],"version-history":[{"count":0,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/posts\/619\/revisions"}],"wp:attachment":[{"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/media?parent=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/categories?post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regex.info\/blog\/wp-json\/wp\/v2\/tags?post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}