Jump to content
Developer Wiki and Function Reference Links ×

VS Date Function - Localized Return?


Recommended Posts

I am trying to determine if the value returned by the Date function is localized or OS dependent.

 

The US English version running on Mac OS 12.6  the value returned by Date(2,0); have the format of MM/DD/YY.

 

Can people using localized version(s) of VW (any OS) or running the US version under windows run the attached script and let me know what the data formats look like?  A screen shot of the Message window would be great.

 

I will update the Dev site for Date with the results.

 

Thanks,

Pat

 

Message('Date(2,0): ',Date(2,0),CHR(13),CHR(13),
		'Date(1,0): ',Date(1,0),CHR(13),CHR(13),
		'Date(0,0): ',Date(0,0));

 

Link to comment

Thank you Julian and Joshua.

 

Still interested in other localizations just for confirmation.

 

I agree that Python would be the better way to go, and if Date was a built in Python data type instead of a module and if I was doing more with it I would probably go that way. But all I am trying to do is get a version of the date that I can use for a time limited demo version of some code I am working on. If I know that the Date return format is always the same I can do what I need with just a couple of Substring or Copy operations. and avoid all the python overhead.  And keep it all in VS so it can be fully encrypted.

 

Everything is a trade off. 😉

 

Link to comment

@Pat Stanford I explored the various responses to Date() several years ago for exactly that purpose. I can confirm that the formats depend on localized settings as well as Mac vs PC. You can get the date in various formats, and make some inferences, but it’s messy and if the user does any kind of custom settings, it breaks. 
 

Yes, the Python date functions are in a module, but it’s built-in, so you don’t need to package it with your script. And if you’re running Python from within VS, it all gets encrypted without doing anything differently. The one thing to flag is that the SetVSVar() call breaks in an encrypted script — use the string repository (Rpstr) commands to pass data between languages. 

Not only will Python let you get the correctly formatted date, you can just diff dates to get the elapsed time span. Between that and the hoops you have to jump through to guess the user’s date format settings, the overhead is way less than an all vs solution. 

  • Like 1
Link to comment

Thank you Joshua.

 

I have on several (or more) occasions told people here on the forum to not doubt you. And here I am doing exactly that.  🤦‍♂️👍

 

Here is a sample that seems to get me what I need, a boolean value if the date reported by the system is > a set date.  The version I will actually need to include will be about 5 lines long. The rest is user input, output reporting, and debugging assistance.

 

This also seemed like a good chance to get a sample of PythonExecute posted to the forum.

 

Procedure Test;
CONST	CR=CHR(13);		{ascii carriage return}
		SQ=CHR(39);		{ascii single quote}

Var
B1:								Boolean;
S0, S1, Year, Month, Day:		DYNARRAY of Char;
rYear, rMonth, rDay:			Real;

BEGIN

{******** Quick and dirty way to let user enter Month/Day/Year values ********}
PtDialog3D('Enter Year, Month, Day', '2022', '11', '1', rYear, rMonth, rDay);
Year:=Num2Str(0,rYear);
Month:=Num2Str(0,rMonth);
Day:=Num2Str(0,rDay);
{******** end of getting user input. ********}

{******** Make a single dynarray of char out of the Python script ********}
{******** Use CR and SQ constants to enter the things that use entry is difficult for ********}
{******** If you stored this in a text file instead you wouldn't need the single quotes ********}
{******** around each part, or the CR (which would be part of the file) or the SQ ********}
{******** which could be just included in the file. ********}
{******** The python script get todays date and compares it to the entered date and stores ********}
{******** it in the value repository for later access by VS. ********}
S0:=Concat('import vs',CR,
'from datetime import date',CR,
'if (date(', Year,', ', Month,', ', Day,') > date.today()) : mybool = True',CR,
'else: mybool = False',CR,
'vs.Rpstr_SetValueBool(',SQ,'WSSplit_DateLimit',SQ,', mybool)',CR);

{******** Message out the Python script for debugging so you can see what is actually being run ********}
message(S0);

{******** Execute the Python Script. ********}
PythonExecute(S0);

{******** Pull the value from the respository into a VS variable ********}
B1:=Rpstr_GetValueBool('WSSplit_DateLimit',TRUE);

{******** Report the Result ********}
AlrtDialog(Concat('Entered Value is After Today: ',B1));

End;

Run(Test);

 

  • Like 1
Link to comment

@Pat Stanford,

   While I was admiring your Python Date function I noticed you are using an IF/ELSE to assign your boolean, which can be simplified by making the assignment directly. It's not much different, but it saves one line of code.

 

S0:=Concat('import vs',CR,
'from datetime import date',CR,
'mybool = date(', Year,', ', Month,', ', Day,') > date.today()',CR,
'vs.Rpstr_SetValueBool(',SQ,'WSSplit_DateLimit',SQ,', mybool)',CR);

 

Thanks for posting.

 

Raymond

Link to comment

Thanks @MullinRJ  I was trying to get the ternary version of IF to work so I could put it on a single line. After an hour or so I gave up and went to what I knew would work.

 

Yours is much more elegant. Thank you.

 

And, since Python accepts both Single and Double Quotes, I could just use double quotes inside the single quotes and avoid the use of the SQ entirely.

 

🤦‍♂️

 

Link to comment

Thank you all.

 

Based on what I see from Julian and Antonio, the returned value of Date() is definitely in the localized format. Which makes it very "challenging" to work with as you either have to come up with another command to help you guess the localization.

 

The two lines of VS and three lines of Python run via PythonExecute seems to handle the situation perfectly.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...