I've often wondered what kind of code you get when you pay a consultant $250 an hour. I figured it would be nothing short of awe-inspiring. And now that I've actually seen (thanks Will Nesbitt) code produced by a two-grand-a-day consultant from IBM, I can say that it is certainly is awe-inspiring ... just not in the way I had hoped.

'checks if a date is valid Private Function validDate ( dateString As String ) As Integer Dim theDay As String Dim theMonth As String Dim theYear As String Dim separator As String Dim dayNumber As Integer Dim monthNumber As Integer Dim yearNumber As Integer Dim currentYear As Integer Dim remainder As Integer 'calculate the current year to check the date is not in the future currentYear = Year ( Now ( ) ) 'a blank date is considered valid as it is not a mandatory field If Len ( dateString ) = 0 Then validDate = True Exit Function End If 'dates of the form dd/mm/yyyy are 10 characters long including the slash (/) If Len ( dateString ) >< 10 Then validDate = False Exit Function End If Stop 'check the seperators are correct Dim i As Integer For i = 3 To 6 separator = Mid ( dateString, i, 1 ) If Not ( separator = "/" Or separator = "-" Or separator = "." ) Then validDate = False Exit Function End If i = i + 2 Next 'extract the parts of the date string theDay = Mid ( dateString, 1, 2 ) theMonth = Mid ( dateString, 4, 2) theYear = Mid ( dateString, 7, 4 ) If theYear = "" Then validDate = False Exit Function End If If theDay = "" Then validDate = False Exit Function Else dayNumber = Cint ( theDay ) End If If theMonth = "" Then validDate = False Exit Function Else monthNumber = Cint ( theMonth ) End If '9 4 6 11 Select Case monthNumber 'the month is either April, June, September or November i.e. 30 days Case 4,6,9,11: If dayNumber >0 And dayNumber <= 30 Then validDate = True Exit Function Else validDate = False Exit Function End If 'the month is february, check for leap year Case 2 : remainder = yearNumber Mod 4 'The year is not a leap year so the day number must be 1 - 28 If remainder >< 0 Then If dayNumber > 0 And dayNumber <= 28 Then validDate = True Exit Function End If Else If dayNumber > 0 And dayNumber <=29 Then validDate = True Exit Function Else validDate = False Exit Function End If End If 'the month is not february or a month with 30 days Case Else : If dayNumber > 0 And dayNumber <= 31 Then validDate = True Exit Function Else validDate = False Exit Function End If End Select End Function

Somehow, looking at this makes me not as impressed by the “$50M worth of code“ donation to the Apache foundation.

(note that this post was a repeat due to the holiday weekend)