date literals in Foxpro
- kevclark64
- Posts: 127
- Joined: Thu Aug 15, 2019 7:30 pm
- Location: USA
date literals in Foxpro
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.
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
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
Code: Select all
SET STRICTDATE TO [0 | 1 | 2]
.
Code: Select all
{^2019-11-06}
Code: Select all
{^2019/11/06}
date literals in Foxpro
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
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
Just to be clear:
Code: Select all
{ 2019.12.31}
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- kevclark64
- Posts: 127
- Joined: Thu Aug 15, 2019 7:30 pm
- Location: USA
date literals in Foxpro
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
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
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:
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
-
- Posts: 200
- Joined: Wed Oct 09, 2019 6:51 pm
date literals in Foxpro
Hi Robert,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 usefor a literal date.Code: Select all
2019.12.31
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}
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
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
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
The Netherlands
robert@xsharp.eu
-
- Posts: 200
- Joined: Wed Oct 09, 2019 6:51 pm
date literals in Foxpro
Hi Robert,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.
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()
#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
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
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
The Netherlands
robert@xsharp.eu
-
- Posts: 200
- Joined: Wed Oct 09, 2019 6:51 pm
date literals in Foxpro
Done, mentioning DateTime() as wellrobert wrote: Can you add a Github issue, so we won't forget this and you will be notified when this is finished.