Page 1 of 1

uCharToVal

Posted: Tue Apr 07, 2020 3:00 pm
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 ?

Re: uCharToVal

Posted: Tue Apr 07, 2020 4:09 pm
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 )
 

Re: uCharToVal

Posted: Tue Apr 07, 2020 4:15 pm
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

Re: uCharToVal

Posted: Tue Apr 07, 2020 6:38 pm
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 )
 

Re: uCharToVal

Posted: Tue Apr 07, 2020 7:54 pm
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

Re: uCharToVal

Posted: Tue Apr 07, 2020 8:10 pm
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

Re: uCharToVal

Posted: Tue Apr 07, 2020 8:18 pm
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.

Re: uCharToVal

Posted: Wed Apr 08, 2020 2:27 pm
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

Re: uCharToVal

Posted: Wed Apr 08, 2020 2:41 pm
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.

Re: uCharToVal

Posted: Wed Apr 08, 2020 2:59 pm
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