On 3-May-07, at 9:49 AM, Dennis Birch wrote:

> On 5/2/07, Steve Garman <[EMAIL PROTECTED]> wrote:
>>> You don't think so what?  That someone's birthday should be  
>>> assumed to
>>> be in the past?
>>
>> Seems like a reasonable request to me.
>>
>> I've added optional parameter assumePastFuture
>>
>> leave it as zero for current century, so it still works as a drop-in
>> replacement
>>
>> set it to a negative integer for the past or a positive integer  
>> for the
>> future
>
> I just checked this out, and there's one major item I've noticed that
> makes this not quite a drop-in replacement for ParseDate.
>
> If you call this function without first creating a new date you get a
> NilObjectException, whereas ParseDate creates the date instance for
> you. This is easily fixed by adding:
>
> if value = nil Then
>   value = new Date
> end if
>
> I was also hoping that this routine would restore the old ParseDate
> capability of interpreting an incomplete US-style date, e.g. "5/3" as
> being that date in the current year: 5/3/2006. I'm going to see if I
> can add that without messing things up too much.

Since I added the test for 2 separators try replacing this code

         // the string should be exactly 2 chars long now
          if len(tmp) <> 2 then
            // unable to understand the format entered
            return false
          end if
        
          sep = mid(tmp,1,1)
          if sep <> mid(tmp,2,1) then
            // invalid - two different separators
            return false
          end if
        
          //make array of elements
          Dim dats() as String = Split( text, sep )
        
          if UBound( dats ) <> 2 then
            //invalid date - should never get here.
            Return false
          end if

with this code

        // first figure out what separator they gave us .. have to both be  
the same one
        for i = 0 to 9
            tmp = replaceAll(tmp,format(i,"0"),"")
        next

        select case len(tmp)
        case 0
            // unable to understand the format entered
            return false
        case 1
            sep = tmp
        case 2
        
            sep = mid(tmp,1,1)
            if sep <> mid(tmp,2,1) then
              // invalid - two different separators
              return false
            end if
        
        else
            return false
        end select
        
        //make array of elements
        Dim dats() as String = Split( text, sep )
        
        if UBound( dats ) <> 2 then
            // add in the missing year ?
            dim tmpDate as new date
            dats.Insert  yearPos, format(tmpDate.year,"0000")
        end if
                
        if UBound( dats ) <> 2 then
            //invalid date - should never get here.
            Return false
        end if

Also right before the value is set add the check for a nil value and  
create it if it is nil

          if value is nil then
            value = new Date
          end if
        
          //populate value ( ByRef side-effect )
          value.totalseconds = 0
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to