uCharToVal

uCharToVal

Postby Silvio.Falconi » Tue Apr 07, 2020 3:00 pm

On this topic [url]uCharToVal( "Monday, 04 March 2019", "D" )[/url] 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  Expand view
#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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: uCharToVal

Postby karinha » Tue Apr 07, 2020 4:09 pm

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7825
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: uCharToVal

Postby Silvio.Falconi » Tue Apr 07, 2020 4: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: Select all  Expand view
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: uCharToVal

Postby karinha » Tue Apr 07, 2020 6:38 pm

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7825
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: uCharToVal

Postby nageswaragunupudi » Tue Apr 07, 2020 7: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" )


Image
Regards

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

Re: uCharToVal

Postby nageswaragunupudi » Tue Apr 07, 2020 8:10 pm

Text to Date:

Please try this program:
Code: Select all  Expand view
#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: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: uCharToVal

Postby nageswaragunupudi » Tue Apr 07, 2020 8: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: Select all  Expand view
  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  Expand view
  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
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: uCharToVal

Postby Silvio.Falconi » Wed Apr 08, 2020 2: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

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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: uCharToVal

Postby nageswaragunupudi » Wed Apr 08, 2020 2: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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: uCharToVal

Postby Silvio.Falconi » Wed Apr 08, 2020 2: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 76 guests

cron