date literals in Foxpro

This forum is meant for questions about the Visual FoxPro Language support in X#.

User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

date literals in Foxpro

Post by kevclark64 »

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.
FoxProMatt

date literals in Foxpro

Post by FoxProMatt »

There is also the Strict Date format:

Code: Select all

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):
.

Code: Select all

{^2019-11-06}
or

Code: Select all

{^2019/11/06}
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

date literals in Foxpro

Post by robert »

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

Code: Select all

2019.12.31
for a literal date.

Just to be clear:

Code: Select all

{ 2019.12.31}
will be an array with one cell with a date value.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

date literals in Foxpro

Post by kevclark64 »

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
FoxProMatt

date literals in Foxpro

Post by FoxProMatt »

Robert - I reported this date format to you back on April 23 in this post:

https://www.xsharp.eu/forum/public-prod ... e-to-a-var

And you said:
I am planning to add that syntax as allowed syntax for Date Literals to the FoxPro dialect
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

date literals in Foxpro

Post by mainhatten »

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

Code: Select all

2019.12.31
for a literal date.
Hi Robert,
IMO xSharp should offer 2 "vfp" ways to create dates

Code: Select all

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 https://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
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

date literals in Foxpro

Post by robert »

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
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

date literals in Foxpro

Post by mainhatten »

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

Code: Select all

*-- 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
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

date literals in Foxpro

Post by robert »

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
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

date literals in Foxpro

Post by mainhatten »

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
Post Reply