uCharToVal

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

uCharToVal

Post by Silvio.Falconi »

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

Code: Select all

#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 ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: uCharToVal

Post by karinha »

Code: Select all

#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
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: uCharToVal

Post by Silvio.Falconi »

???????????????

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: Select all

 cText_date := Date2txt( dDate )
Msginfo(    uCharToVal( cText_date, "D" )   )
it return the right date
on Italian language not run ok
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: uCharToVal

Post by karinha »

Code: Select all

#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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: uCharToVal

Post by nageswaragunupudi »

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" )
Image
Regards

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

Re: uCharToVal

Post by nageswaragunupudi »

Text to Date:

Please try this program:

Code: Select all

#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
 
Image
Regards

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

Re: uCharToVal

Post by nageswaragunupudi »

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: Select all

   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: Select all

   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
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: uCharToVal

Post by Silvio.Falconi »

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

Image

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
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: uCharToVal

Post by nageswaragunupudi »

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
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: uCharToVal

Post by Silvio.Falconi »

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
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply