Page 1 of 2
date literals in Foxpro
Posted: Wed Nov 06, 2019 2:18 pm
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.
date literals in Foxpro
Posted: Wed Nov 06, 2019 4:29 pm
by FoxProMatt
There is also the Strict Date format:
If STRICTDATE is on, you must use this format for date literals (notice the caret symbol before the year):
.
or
date literals in Foxpro
Posted: Wed Nov 06, 2019 4:43 pm
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
for a literal date.
Just to be clear:
will be an array with one cell with a date value.
Robert
date literals in Foxpro
Posted: Wed Nov 06, 2019 5:09 pm
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
date literals in Foxpro
Posted: Wed Nov 06, 2019 9:42 pm
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
date literals in Foxpro
Posted: Thu Nov 07, 2019 3:07 am
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
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
date literals in Foxpro
Posted: Thu Nov 07, 2019 6:13 am
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
date literals in Foxpro
Posted: Thu Nov 07, 2019 9:43 am
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
date literals in Foxpro
Posted: Thu Nov 07, 2019 12:05 pm
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
date literals in Foxpro
Posted: Thu Nov 07, 2019 11:46 pm
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