FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour uCharToVal
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
uCharToVal
Posted: Tue Apr 07, 2020 03:00 PM
On this topic uCharToVal( "Monday, 04 March 2019", "D" ) Nages sad
uCharToVal( "Monday, 04 March 2019", "D" )
works well with English only.
From FWH1904 onwards, it will work with other codepage languages.
I tried today and it not run ( I tested with FiveWin for Harbour ver. Jannuary 2020)

My test
#include "fivewin.ch"

request hb_lang_it
request hb_codepage_itwin



Function test()
Local dtoday
Local cText_date

   HB_LANGSELECT( "IT" )
   HB_SETCODEPAGE( "ITWIN" )

   dtoday:=date()

  cText_date:=date2txt(dToday)

  MsgInfo(cText_date)

  Msginfo(    uCharToVal( cText_date, "D" )   )
return nil

//----------------------------------------------------------------------------------//
Function Date2Txt(dTemp)
   LOCAL f, m, cMese, dFech,dDay,d
   Local i,c
   local aMesi[ 12 ]
   local aWeek[ 7 ]

   AEval( aMesi,  { |c,i| aMesi[ i ]  := NToCMonth( i ) } )
   AEval( aWeek, { |c,i| aWeek[ i ] :=  NToCDOW( i ) } )

   f:=DTOS (dTemp)
   m:=MONTH(dTemp)
   d:=dow(dtemp)

   cMese:=LEFT(IF(m<>0, aMesi[m] ,"" ),3)
   dday :=LEFT(IF(d<>0, oemtoansi(aWeek[d]) ,""),3)

   dFech:=IF(m<>0,dday+", "+ SubStr(f,7,2)+' '+cMese+' '+SubStr(f,1,4),'')
   RETURN (dFech)

Any solution ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: uCharToVal
Posted: Tue Apr 07, 2020 04:09 PM
#include "fivewin.ch"

REQUEST hb_lang_it
REQUEST hb_codepage_itwin

FUNCTION Test()

   LOCAL dtoday, dDate
   LOCAL cText_Date

   SET DATE BRITISH
   SET CENTURY ON

   HB_LANGSELECT( "IT" )
   HB_SETCODEPAGE( "ITWIN" )

   dToday     := Date()
   dDate      := uCharToVal( dToday, 'D' )
   cText_date := Date2txt( dDate )

   MsgInfo( cText_Date )

   Msginfo( dDate )

RETURN nil

//----------------------------------------------------------------------------------//

FUNCTION Date2Txt( dTemp )

   LOCAL f, m, cMese, dFech, dDay, d, d1
   LOCAL i, c
   LOCAL aMesi[ 12 ]
   LOCAL aWeek[ 7 ]

   AEval( aMesi,  { |c, i| aMesi[ i ]  := NToCMonth( i ) } )
   AEval( aWeek, { |c, i| aWeek[ i ] :=  NToCDOW( i ) } )

   f  := DTOS ( Date() )
   m  := MONTH( Date() )
   d  := DAY( Date() )
   d1 := Dow( Date() )

   cMese := LEFT( IF( m <> 0, aMesi[m] ,"" ), 3 )

   dday := LEFT( IF( d <> 0, OemToAnsi(aWeek[d] ) ,"" ), 3 )

   dFech := IF( m <> 0, dday + ", " + SubStr( f,7,2 ) + ' ' + cMese + ' ' + SubStr( f,1,4 ), '' )

RETURN ( dFech )
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: uCharToVal
Posted: Tue Apr 07, 2020 04:15 PM
???????????????

I wish converte the string "Mar, 07, Apr 2020 " into date format 07/04/2020

your test is wrong

it is logic ( on you test) Msginfo( dDate ) show the date 07/04/2020

if you read Nages sentence you can understood another question

On English Language if you make

Code (fw): Select all Collapse
 cText_date := Date2txt( dDate )
Msginfo(    uCharToVal( cText_date, "D" )   )


it return the right date
on Italian language not run ok
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: uCharToVal
Posted: Tue Apr 07, 2020 06:38 PM
#include "fivewin.ch"

REQUEST HB_Lang_IT
REQUEST HB_CODEPAGE_ITWIN

STATIC nLanguage

FUNCTION Test()

   LOCAL dtoday, dDate, dItalia
   LOCAL cText_Date

   DEFAULT nLanguage := FWSetLanguage()

   SET DATE ITALIAN
   SET CENTURY ON
   SET DATE FORMAT TO "dd-mm-yyyy"

   HB_LANGSELECT( "IT" )
   HB_SETCODEPAGE( "ITWIN" )

   FWSetLanguage( 6 ) // Italian language

   dToday     := Date()
   dDate      := uCharToVal( dToday, 'D' )
   dItalia    := dDate

   cText_date := Date2txt( dDate )

   MsgInfo( cText_Date )

   Msginfo( dItalia )

RETURN nil

//----------------------------------------------------------------------------------//

FUNCTION Date2Txt( dItalia )

   LOCAL f, m, cMese, dFech, dDay, d, d1
   LOCAL i, c
   LOCAL aMesi[ 12 ]
   LOCAL aWeek[ 7 ]

   AEval( aMesi,  { |c, i| aMesi[ i ]  := NToCMonth( i ) } )
   AEval( aWeek, { |c, i| aWeek[ i ] :=  NToCDOW( i ) } )

   f  := DTOS ( Date() )
   m  := MONTH( Date() )
   d  := DAY( Date() )
   d1 := Dow( Date() )

   cMese := LEFT( IF( m <> 0, aMesi[m] ,"" ), 3 )

   dday := LEFT( IF( d1 <> 0, OemToAnsi(aWeek[d1] ) ,"" ), 3 )

   dFech := IF( m <> 0, dday + ", " + SubStr( f,7,2 ) + ' ' + cMese + ' ' + SubStr( f,1,4 ), '' )
   
   dItalia := dFech

   // ? dItalia, dFech

RETURN( dItalia )
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: uCharToVal
Posted: Tue Apr 07, 2020 07:54 PM
First thing:
You do not need to write such long and tedious functions to convert date into text.
Instead, you can use FW_TRANSFORM()

Please try this:
dDate := Date()
? FW_TRANSFORM( dDate--, "ddd, dd mmm yyyy" ), FW_TRANSFORM( dDate--, "dddd, dd mmmm yyyy" ), ;
FW_TRANSFORM( dDate--, "ddd, dd-mmm-yyyy" ), FW_TRANSFORM( dDate--, "dddd, dd-mmmm-yyyy" )


Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: uCharToVal
Posted: Tue Apr 07, 2020 08:10 PM
Text to Date:

Please try this program:
#include "fivewin.ch"

REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN

function Main()

   local dDate := Date()
   local cDate

   HB_LANGSELECT( "IT" )
   HB_SETCODEPAGE( "ITWIN" )

   SET DATE ITALIAN
   SET CENTURY ON

   ? cDate := FW_TRANSFORM( --dDate, "ddd, dd mmm yyyy" ),   uCharToVal( cDate, "D" ), ;
     cDate := FW_TRANSFORM( --dDate, "dddd, dd mmmm yyyy" ), uCharToVal( cDate, "D" )

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: uCharToVal
Posted: Tue Apr 07, 2020 08:18 PM
I tried today and it not run ( I tested with FiveWin for Harbour ver. Jannuary 2020)


Mr. Silvio
You are right. There is a bug. Conversion of text to date is working when and only when the month name is at the beginning of the text or is preceded by a space character but not any character like "-" or "/".

Thanks for pointing out this.

We are fixing this in the next version.

We suggest this fix for now.

\fwh\source\valtostr.prg.
static function dAlphaToDate( cDate )
Please locate these lines:
Code (fw): Select all Collapse
   for n := 1 to 12
     if FW_AT( " " + Left( NTOCMonth( n ), 3 ), " " + cDate ) > 0
         m  := n
         exit
      endif
   next n


Please replace these lines with this revised code:
Code (fw): Select all Collapse
   for n := 1 to 12
      c  := NTOCMonth( n )
      if FW_At( Left( c, 3 ), cDate, nil, nil, .t. ) > 0 .or. FW_At( c, cDate, nil, nil, .t. ) > 0
         m  := n
         EXIT
      endif
   next


This should solve the issue raised by Mr. Silvio.
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: uCharToVal
Posted: Wed Apr 08, 2020 02:27 PM
Nages Now run ok ...

I use it on my application where I have the date as "Merc, 8 Apr 2020" for a sample on gets



As you can see here I use get and you XbrGetDate func because on dtpicker I cannot set a calendar limit

then I have procedures and many function need the format 8/04/2020 and so I need to recovert the cdate from "Merc, 8 Apr 2020" string

Now these solutions are good
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: uCharToVal
Posted: Wed Apr 08, 2020 02:41 PM
Now these solutions are good

So is your problem solved now?

For your information, we can set range for normal dtpicker also from the next release. This will be useful to you and many others.
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: uCharToVal
Posted: Wed Apr 08, 2020 02:59 PM

yes the problem is solved

i am trying to understand how to insert in my source.

Nice idea to implement date limits in datepick even if I really like your calendar created with xbrowse

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion