February 21, 2008
ColdFusion IsDate() gotcha
I must be a slow learner because I've been bitten by the following gotcha in the ColdFusion IsDate() function more than once. So I'm writing this here mostly for my own sake, but it may be of value to others also.
I've used IsDate() many times in form validation logic to verify that a user entered a valid date into an HTML field. Usually, I need to verify that the input is something like 02/21/2008 or 2-21-08, and this function has saved me from writing a regular expression to validate the correct format.
But it turns out that IsDate() is pretty liberal in it's definition of a "date". According to the ColdFusion documentation, IsDate() returns true "if [the] string can be converted to a date/time value." This means that the following strings are all considered valid dates according to this function:
- 4:03 pm
- 21-02-08 4:03pm
It's the dd/mm/yyyy format that's caused me trouble before. If I'm expecting a date in mm/dd/yyyy format and IsDate() allows the user to enter 21/02/2008 then strange things start happening in my applications.
My solution is to replace IsDate() with IsValid("USdate", string_value) which will only return true if the string is a valid date in the mm/dd/yy format (with 1-2 digit days and months and 1-4 digit years).
Don’t break the web?
Since Microsoft’s announcement that Internet Explorer 8 would use something called “version targeting” everyone has been chiming in with their thoughts and opinions on the issue. Many people are for it and many are opposed to the idea. I find myself increasingly annoyed at this whole situation and at Microsoft’s recently proposed solution.
Microsoft’s main justification for version targeting is to avoid “breaking the web”. I find their altruistic concern over this matter more than a little ironic and very hypocritical.
If Microsoft was really that concerned with not breaking the web, then why aren’t they more concerned with not breaking the desktop? Anyone who’s upgraded to Windows Vista is familiar with the problem of incompatible applications and drivers that worked perfectly fine in Windows XP but for whatever reason don’t work right in Vista because of Vista’s “improvements”. In addition, in a few short weeks, Vista SP1 will be released to the masses and we’re already being warned about problems and incompatibilities with this upgrade. How many things that work fine in Vista right now won’t work after the SP1 upgrade?
Here’s another example: I’ve got Office 2007 installed on my Vista machine. But I can’t use Outlook 2007 to connect to my work’s old Exchange 5.5 Server because Outlook 2007 effectively “broke” backwards compatibility with this version of Exchange server. If Microsoft is so worried about not breaking the web, why are they so willing to break the desktop?
Anyone who’s worked with computers for a while accepts the fact that you can’t maintain backwards compatibility forever. At some point, you have to sacrifice backwards compatibility for improvements and innovation. As they say, you can’t have your cake and eat it too.
I would like to see Microsoft step up to the plate and accept full responsibility for this mess. The problem really isn’t “unenlightened” web developers or poorly written web authoring tools. Sure these factors have contributed to the problem, but the real heart of the problem is Microsoft’s crappy browser. Had IE had better standards support right from the beginning, there would be no such thing as unenlightened developers or bad authoring tools because these people were just follow Microsoft’s lead.
But for whatever reason, all I’m seeing is Microsoft trying to shift the blame off of themselves and offering yet another lame patch in an attempt to cover up the issue while mindlessly repeating their hypocritical mantra of “don’t break the web”. Microsoft, unfortunately you already broke the web a long time ago! It’s time that you accept this fact and start fixing it for good.
February 4, 2008
Automatically stretch Webshots backgrounds redux
As I mentioned in a previous entry, a while back I created a little script to automatically stretch my Webshots wallpaper images to fill my widescreen monitor. However, after upgrading to Windows Vista this script didn't work correctly since it is basically just a macro that simulates the keystrokes a user would type to open up Display Properties and change the wallpaper mode to stretch.
I tried to update this macro with the Vista-specific keystrokes, but for some unknown reason, the program seemed to work fine when run manually, but when I tried to run it as a scheduled task, it would hang. It may have had something to do with Vista's more restrictive security policies. Anyway, try as I might, I was unable to get it to work reliably as a scheduled task, which totally defeated the purpose of the script.
So I did some research on other ways to accomplish my task and stumbled upon the "correct" way to change the wallpaper mode programmatically. It basically requires that you update the registry key containing the wallpaper mode setting and then make a special call to the user32.dll to instruct Windows to reread the registry key and update the settings as specified.
After some tinkering, I was able to get this to work. The best news is that now the script is even shorter and faster! I've included the AutoIt script below:
; AutoIt Version: 3.0
; Language: English
; Platform: Windows Vista
; Author: Richard Davies (Richard@richarddavies.us)
; Script Function:
; Changes wallpaper mode to 'stretch'.
Dim $wp = RegRead("HKCU\Control Panel\Desktop", "WallPaper")
RegWrite("HKCU\Control Panel\Desktop", "WallpaperStyle", "REG_SZ", 2)
DllCall("user32.dll", "none", "SystemParametersInfo", "int", 20, "int", 0, "str", $wp, "int", 0x02)