uCharToVal returns "01/01/2020" as 20/09/0090

uCharToVal returns "01/01/2020" as 20/09/0090

Postby hua » Mon May 04, 2020 6:05 pm

Hi Rao,
Is my usage of uCharToVal() wrong?

Code: Select all  Expand view

#include "fivewin.ch"

proc main()
  set century on
  set date british

  ? uCharToVal("01/01/2020", "D")
return
 


The above snippet gave result as 20/09/0090.

Compiled with Harbour+FWH1912

TIA
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1070
Joined: Fri Oct 28, 2005 2:27 am

Re: uCharToVal returns "01/01/2020" as 20/09/0090

Postby Antonio Linares » Mon May 04, 2020 6:07 pm

? DToS( CToD( "01/01/2020" ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41858
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: uCharToVal returns "01/01/2020" as 20/09/0090

Postby nageswaragunupudi » Tue May 05, 2020 9:22 am

We will look into the function.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10465
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: uCharToVal returns "01/01/2020" as 20/09/0090

Postby nageswaragunupudi » Fri May 08, 2020 1:35 pm

The bug is fixed in version FWH2005 to be released.

You can make this correction and test.

In the module \fwh\source\function\valtostr.prg:
please replace the existing
static function dCharToDate( cDate )
with the following revised function:

Code: Select all  Expand view
static function dCharToDate( cDate )

   local cFormat, cc, cfmt
   local dDate

   if ( cc := Upper( cDate ) ) != Lower( cDate )
      return dAlphaToDate( cc )
   endif

   if Len( cDate ) >= 8 .and. IsDigit( SubStr( cDate, 3 ) ) .and. IsDigit( SubStr( cDate, 5 ) ) .and. ;
      ! Empty( dDate := SToD( Left( cDate, 8 ) ) )
      return dDate
   endif
   if Len( cDate ) >= 10 .and. IsDigit( SubStr( cDate, 3 ) ) .and. !IsDigit( SubStr( cDate, 5 ) ) .and. ;
      !IsDigit( SubStr( cDate, 8 ) ) .and. ;
      ! Empty( dDate := StoD( Left( cDate, 4 ) + SubStr( cDate, 6, 2 ) + SubStr( cDate, 9, 2 ) ) )
      return dDate
   endif

   // check for single digit date/month
   if !IsDigit( SubStr( cDate, 2 ) )
      cDate    := "0" + cDate
   endif
   if !IsDigit( SubStr( cDate, 5 ) )
      cDate    := Left( cDate, 3 ) + "0" + SubStr( cDate, 4 )
   endif
   //

   cFormat  := Lower( Set( _SET_DATEFORMAT ) )
   dDate    := CToD( cDate )
   if Empty( dDate )
      cc    := Left( cFormat, 2 )

      for each cFmt in { "dd/mm/yy", "mm/dd/yy", "yy/mm/dd" }
         if !( Left( cFmt, 2 ) == cc )
            SET( _SET_DATEFORMAT, cFmt )
            if !Empty( dDate := CTOD( cDate ) )
               EXIT
            endif
         endif
      next

   endif
   Set( _SET_DATEFORMAT, cFormat )

return dDate
 


We'll be glad if you can test and let us have your feedback.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10465
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: uCharToVal returns "01/01/2020" as 20/09/0090

Postby hua » Fri May 08, 2020 10:44 pm

Hi Rao,
Yes I got the expected result with the fixed version.

Thank you
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1070
Joined: Fri Oct 28, 2005 2:27 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 43 guests