Date Validation in ColdFusion

Posted in Programming on March 8th, 2010 by Jamie – Be the first to comment

Someone asked me about Date Validation the other day. Here are two simple approaches for use in your CF apps.

Assume that the strDate variable contains your date. On the server-side, you may use IsDate(strDate). On the client side, !isNaN(new Date(strDate)). I don’t know for sure if the client-side code is the best way to do it. There are RE-based techniques, but these are the most concise.

CFML:

    <cfoutput>
      <cfset strDate1 = "2001 Fazuary 1"/>
      <cfset strDate2 = "2001 Feb 1" />

        #IsDate(strDate1)#<br>
        #isDate(strDate2)#

    </cfoutput>

    <!---

    Outputs:

    NO
    YES

    --->

Client-side Javascript:

    <script>
    // This creates a function to test the string.
    // What is this function doing? It takes the
    // strDate string and attempts to convert it into
    // a Date object using the Date constructor.
    // When the Date constructor cannot convert the
    // string, it returns NaN (not a number).
    // So, we wind up testing for NOT NaN using
    // !isNaN. Don't ask me why the Date constructor
    // returns NaN and not NaD (not a date)! =D
    function isDate(strDate) { return !isNaN(new Date(strDate)); }

    var strDate1 = "2001 Fazuary 1",
        strDate2 = "2001 Feb 1";

    alert(
        isDate(strDate1) + '\n' +
        isDate(strDate2)
    );

    //
    // Brings up an alert window that says:
    //
    // false
    // true

    </script>
Print This Post Print This Post

Twitter Weekly Updates for 2010-03-07

Posted in Twitter on March 7th, 2010 by Jamie – Be the first to comment

Powered by Twitter Tools

Print This Post Print This Post

Twitter Weekly Updates for 2010-03-07

Posted in Twitter on March 7th, 2010 by Jamie – Be the first to comment

Powered by Twitter Tools

Print This Post Print This Post

4-Ball Juggling Practice

Posted in Hobbies on March 6th, 2010 by Jamie – Be the first to comment

The next trick I am trying to work on is 4-ball juggling. Here are some practice takes:

Print This Post Print This Post

MacBook Pro Desktop

Posted in Workstation on March 4th, 2010 by Jamie – 1 Comment

My MacBook desktop. Is there such a thing as too cute?

Print This Post Print This Post

Bubble Breaker Using Canvas!

Posted in Programming, Software on March 2nd, 2010 by Jamie – 1 Comment

I wanted to try out some canvas element functionality, given that I have a feeling it will steal a lot of Flash’s thunder. I whipped up a bubble-breaker game (the mechanic should be very familiar to you) in a few hours. Enjoy the demo! I may do a quick write up at a later point.

I’ve only tested it in Firefox 3.6. I do not know whether it will work in other browsers.

Demo
Project site

bubble breaker 13x13

bubble breaker 13x13

bubble breaker 30x30

bubble breaker 30x30

Print This Post Print This Post

Twitter Weekly Updates for 2010-02-28

Posted in Twitter on February 28th, 2010 by Jamie – Be the first to comment

Powered by Twitter Tools

Print This Post Print This Post

Summary: The Checklist Manifesto – Chapter 9: The Save

Posted in Books on February 27th, 2010 by Jamie – Be the first to comment

Even after all this research Gawande still doesn’t instill all his faith into the checklist as a tool for surgeons. Then, in the spring of 2007, he has a close call with a patient, who experiences complications. Thanks to the checklist, they have a supply of blood ready that is able to keep the patient alive to complete the surgery. Gawande becomes a true believer.

Print This Post Print This Post

Summary: The Checklist Manifesto – Chapter 8: The Hero in the Age of Checklists

Posted in Books on February 25th, 2010 by Jamie – Be the first to comment

Even though checklists seem like a simple, effective solution to the problem of mistakes in procedure, there are behavioral problems to surmount in adoption. Institutions seem more willing to pay for multimillion dollar surgical robots with limited cost-benefit than try to imprlmeent checklists. Doctors are reluctant to accept them, and see the true spirit of these tools, which are to encourage teamwork and strive for discipline. The medical field is still a little liek the test pilot culture of the 50s. There is a cultural legacy that seems threatened by checklists. In finance, there is also hesitation to adopt the checklist as a tool. Psychologist Geoff Smart found the same hesitation in venture capital. Those investors dubbed “Airline Captains” take a methodical approach but most are “Art Critics” or “Sponges.”

Gawande talks about US Airways Flight 1549 and its emergency landing in the Hudson, which was a triumph of the pilot checklist, rather than a single heroic victory of the captain.

All professional occupations have three elements in common:

  • selflessness
  • skill
  • trustworthiness
  • pilots also have: discipline

Maybe we should all strive for more dsicipline? Systems are an integral part of the complex system of heath. The way the health system is designed now is piecemeal. There needs to be more integration. Checklists can be the tool to improve this integration.

Print This Post Print This Post

Drupal Org Chart – Graph Viz Update

Posted in Programming, Software on February 24th, 2010 by Jamie – Be the first to comment

I have updated the Google Code repository with updates to integrate GraphViz. It expects the PEAR GraphViz package to be installed.  To install it, issue command:

# You must install the beta package.

sudo pear install Image_GraphViz-beta

If you’d rather not mess with PEAR, download the package, extract the class Image_GraphViz, and alter two two lines of code that depend on the PEAR::System package. It should be trivial to change these. They are both basically calls like this:

// create a temporary file with the prefix "graph_"
$file = System::mktemp('graph_');

One possible replacement:

// will use default tmp dir
$file = tempnam('', 'graph_');
Print This Post Print This Post