fbpx
Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC: date literals in Foxpro

date literals in Foxpro 1 week 1 day ago #11617

  Kevin Clark's Avatar Topic Author Kevin Clark Offline Posts: 9
I don't know if this issue has been discussed already, but ... in Foxpro you can enter a date literal using curly brackets, such as:

myNewDate={12/31/2019}

Currently the compiler is taking curly bracket values as array entries. I wonder whether this might be switched for the Foxpro dialect to accept this as a date literal. To get a little more complex, it seems like it would be possible to support both date literals and array values if the compiler took anything within curly brackets in a correct date format as a date while considering non-date-format entries to be array values.

Please Log in or Create an account to join the conversation.

date literals in Foxpro 1 week 23 hours ago #11619

  FoxProMatt_MattSlay's Avatar FoxProMatt_MattSlay Offline Posts: 276
There is also the Strict Date format:
SET STRICTDATE TO [0 | 1 | 2]

If STRICTDATE is on, you must use this format for date literals (notice the caret symbol before the year):
.
{^2019-11-06}
or
{^2019/11/06}

Please Log in or Create an account to join the conversation.

Last edit: by FoxProMatt_MattSlay.

date literals in Foxpro 1 week 23 hours ago #11620

  robert's Avatar robert Offline Posts: 1309
Kevin,
I did not know about this date format. At this moment we support the Strict dateformat that matt refers to and you can also use
2019.12.31
for a literal date.

Just to be clear:
{ 2019.12.31}
will be an array with one cell with a date value.


Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

Last edit: by robert.

date literals in Foxpro 1 week 22 hours ago #11621

  Kevin Clark's Avatar Topic Author Kevin Clark Offline Posts: 9
So it looks like to assign a date to a variable you can use:

myNewDate=2019.12.31 && not valid Foxpro but valid XSharp
myNewDate=CTOD("12/31/2019") && valid Foxpro and valid XSharp

You cannot use:

myNewDate={12/31/2019} && valid Foxpro not valid XSharp
myNewDate=DATE(2019,12,31) && valid Foxpro not valid XSharp

Please Log in or Create an account to join the conversation.

date literals in Foxpro 1 week 18 hours ago #11625

  FoxProMatt_MattSlay's Avatar FoxProMatt_MattSlay Offline Posts: 276
Robert - I reported this date format to you back on April 23 in this post:

www.xsharp.info/forum/public-product/118...igning-date-to-a-var

And you said:

I am planning to add that syntax as allowed syntax for Date Literals to the FoxPro dialect

Please Log in or Create an account to join the conversation.

date literals in Foxpro 1 week 12 hours ago #11629

  mainhatten's Avatar mainhatten Offline Posts: 30

robert wrote: I did not know about this date format. At this moment we support the Strict dateformat that matt refers to and you can also use

2019.12.31
for a literal date.

Hi Robert,
IMO xSharp should offer 2 "vfp" ways to create dates
local ldMyDate as DATE
ldmyDate := {^2019.11.07}   && the "strictdate" variant
ldmyDate := Date(2019,11,07)   && in vfp date with no parameter returns current date, with parameters specific date
**************************************
*-- this is Working xSharp
ldmyDate := Date{2019,11,07}  && as constructor of date type
******************************************
* but even if I define
FUNCTION DATE(tnYear AS INT, tnMonth AS INT, tnday AS INT) AS DATE
	RETURN DATE{tnYear, tnMonth, tnDay}
the call intended for the Function throws an error, expecting a method - probably as "Date" is already a "special" type, as compared to the "basic data type" it is in vfp.
From vivaclipper.wordpress.com/?s=date%28%29
the function call without parameters is in Clipper and vfp
As I am somewhat bushed I have not found a way to call a function with same name as a type - did not even try for real...

The benefit of "strictdate" format is that you can employ vfp to smoke out ambiguous code parts, and using date() and datetime() functions as constructors is much safer than converting strings/literals of switchable set date [ansi,american, british, german...] formats

my 0.02€
thomas

Please Log in or Create an account to join the conversation.

Last edit: by mainhatten.

date literals in Foxpro 1 week 9 hours ago #11633

  robert's Avatar robert Offline Posts: 1309
Thomas,

A function with the same name as a built-in type (Date, Array, Float etc) is not possible at this moment. I will see what I can do to make this possible.

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

date literals in Foxpro 1 week 6 hours ago #11637

  mainhatten's Avatar mainhatten Offline Posts: 30

robert wrote: A function with the same name as a built-in type (Date, Array, Float etc) is not possible at this moment. I will see what I can do to make this possible.

Hi Robert,
thx for the quick update. -had been afraid of that. If there is no way on making it possible on the xSharp side, one possible solution could be to create a "vfp_date()" function in the vfp (plus un-overloaded with no parameters for clipper) dialect in xSharp and those wishing to have the same code run under original vfp and xSharp will have to substiture the sources fed to MS-vfp compiler via #define, for instance like
*-- this has to be in the vfp side, probably guarded by further switch to disable substitution in xSharp
#define vfp_date date
? vfp_date()
which is probably no problem at all for early adopters currently here, but might scare off less adventurous types just wishing to test xSharp waters. It is easier to argue for fixes to existingvfp code like strictdate or even "typing" vfp vars as it helps readabilty, making the source "better".
#define creates no runtime penalty, so not really a "loss", but it is a slippery road I would prefer to use only later, not for "basic" vfp functionality as preprocessor usage has some quirks in vfp like limited amount of levels for #include. No real showstoppers, but anything making code "unnormal" in typical vfp users eyes might keep people away...

regards
thomas

Please Log in or Create an account to join the conversation.

Last edit: by mainhatten.

date literals in Foxpro 1 week 3 hours ago #11642

  robert's Avatar robert Offline Posts: 1309
Thomas,

I think we can manage to add these function for the FoxPro language without having to use preprocessor tricks.
Can you add a Github issue, so we won't forget this and you will be notified when this is finished.

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

date literals in Foxpro 6 days 16 hours ago #11649

  mainhatten's Avatar mainhatten Offline Posts: 30

robert wrote: Can you add a Github issue, so we won't forget this and you will be notified when this is finished.

Done, mentioning DateTime() as well

Please Log in or Create an account to join the conversation.

date literals in Foxpro 5 days 5 hours ago #11656

  Karl-Heinz's Avatar Karl-Heinz Offline Posts: 390

robert wrote: Thomas,
I think we can manage to add these function for the FoxPro language without having to use preprocessor tricks.

because you mentioned the preprocessor, i gave it a try - and it works :-).

#TRANSLATE Date ( <year> , <month> , <day> ) => @@Date( <year>, <month>,<day> ) 
#TRANSLATE Date ( ) => @@Date()

FUNCTION @@DATE(tnYear AS INT, tnMonth AS INT, tnday AS INT) AS DATE 
RETURN ConDate ( (DWORD) tnYear , (DWORD) tnMonth , (DWORD) tnday  )   
	
FUNCTION @@DATE() AS DATE 
RETURN Today()


FUNCTION Start() AS VOID

? Date()

? Date ( 2000 , 12 , 1 )

RETURN 

It seems that the escape chars in the Function declarations are not really needed, because it also works without these chars.

FUNCTION DATE(tnYear AS INT, tnMonth AS INT, tnday AS INT) AS DATE
RETURN ConDate ( (DWORD) tnYear , (DWORD) tnMonth , (DWORD) tnday )

FUNCTION DATE() AS DATE
RETURN Today()

The abilities of the preprocessor are impressive !

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

date literals in Foxpro 5 days 3 hours ago #11660

  robert's Avatar robert Offline Posts: 1309
Karl-Heinz ,

Thanks. So maybe we will not have to add this to the compiler but can handle it in the header file.
Btw why are you declaring the arguments as int and then casting them to a dword ? Why not simply declare them as DWORD.
And did you consider to write the UDCs as:
#TRANSLATE Date ( <year> , <month> , <day> ) => ConDate( <year>, <month>,<day> ) 
#TRANSLATE Date ( ) => Today()


Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

date literals in Foxpro 5 days 2 hours ago #11666

  Karl-Heinz's Avatar Karl-Heinz Offline Posts: 390
Hi Robert,

i simply used the INT sample that Thomas posted. The main goal was to see if and how the escape chars are handled.

#TRANSLATE Date ( <year> , <month> , <day> ) => ConDate( <year>, <month>,<day> )
#TRANSLATE Date ( ) => Today()

yeah, didn´t investigate further, because i thought you don´t want the preprocessor to do the job.

regards
Karl-Heinz

Please Log in or Create an account to join the conversation.

  • Page:
  • 1