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 06 Nov 2019 15:18 #11617

  • Kevin Clark's Avatar

  • Kevin Clark

  • Topic Author


  • Posts: 68
  • 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 06 Nov 2019 17:29 #11619

  • FoxProMatt's Avatar

  • FoxProMatt


  • Posts: 385
  • 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.

    date literals in Foxpro 06 Nov 2019 17:43 #11620

  • robert's Avatar

  • robert


  • Posts: 1691
  • 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 06 Nov 2019 18:09 #11621

  • Kevin Clark's Avatar

  • Kevin Clark

  • Topic Author


  • Posts: 68
  • 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 06 Nov 2019 22:42 #11625

  • FoxProMatt's Avatar

  • FoxProMatt


  • Posts: 385
  • 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 07 Nov 2019 04:07 #11629

  • mainhatten's Avatar

  • mainhatten


  • Posts: 139
  • 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 07 Nov 2019 07:13 #11633

  • robert's Avatar

  • robert


  • Posts: 1691
  • 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 07 Nov 2019 10:43 #11637

  • mainhatten's Avatar

  • mainhatten


  • Posts: 139
  • 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 07 Nov 2019 13:05 #11642

  • robert's Avatar

  • robert


  • Posts: 1691
  • 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 08 Nov 2019 00:46 #11649

  • mainhatten's Avatar

  • mainhatten


  • Posts: 139
  • 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 09 Nov 2019 11:23 #11656

  • Karl-Heinz's Avatar

  • Karl-Heinz


  • Posts: 555
  • 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 09 Nov 2019 13:06 #11660

  • robert's Avatar

  • robert


  • Posts: 1691
  • 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 09 Nov 2019 14:22 #11666

  • Karl-Heinz's Avatar

  • Karl-Heinz


  • Posts: 555
  • 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.

    date literals in Foxpro 16 Nov 2019 14:33 #11744

  • Karl-Heinz's Avatar

  • Karl-Heinz


  • Posts: 555
  • Hi Robert,

    How is your decision to implement the Date() and DateTime() functions ? After some attempts with the preprocessor, it seems that this is the only possibility to evaluate a preprocessed Date() function ?

    #XTRANSLATE DATE() => @@DATE()
    #XTRANSLATE DATE ( <year> , <month> , <day> ) 	=> @@Date ( <year>, <month>,<day> ) 
    
    
    FUNCTION DATE() AS DATE
    	
    	RETURN Today()
    
    
    FUNCTION DATE( year AS DWORD , month AS DWORD  , day AS DWORD ) AS DATE
    	
    	RETURN ConDate ( year , month , day  )
    
    
    FUNCTION Start() AS VOID
    
    ?   Evaluate ( "@@Date()+ 1" )   // doesn´t work without the escape sequence
    ?   Evaluate ( "@@Date( 2011 , 12 , 7 ) + 1" )   // doesn´t work without the escape sequence
    
    ?   Eval ( MCompile ( "@@Date()+ 1"   ) )   // doesn´t work without the escape sequence
    ?   Eval ( MCompile ( "@@Date( 2011 , 12 , 7 ) + 1" ) )   // doesn´t work without the escape sequence
    
    ?   Eval ( {|| Date()+ 1 } )
    ?   Eval ( {|| Date( 2011 , 12 , 7 ) + 1} )
    
    ?   Eval ( {|n| DATE()+ n } , 12  )
    ?   Eval ( {|n| DATE( 2011 , 12 , 7 ) + n} , 12  )
    
    
    RETURN
    

    regards
    Karl-Heinz

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

    • Page:
    • 1