Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale dependant usage inspection for Implicit Date to String conversions #2445

Open
ThunderFrame opened this Issue Dec 21, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@ThunderFrame
Copy link
Member

ThunderFrame commented Dec 21, 2016

There are many functions that accept string parameters. for example, the Replace function accepts strings for its first three parameters, but passing a date-typed argument will have the date converted to a string using the user's regional settings.

That can result in unpredictable results, either because of unexpected characters in the date-string, or because the order/appearance of the various date-parts might differ by region.

For example, this code tries to fix the invalid characters in a filename, but doesn't fix the date-parts

DateNow = Date()
filename = Replace(DateNow, "/", "-")
'Who knows what filename looks like at this point...

A better solution, in this instance, would be:

DateNow = Date()
filename = Format$(DateNow, "YYYY-MM-DD")

linking #2045

@ThunderFrame ThunderFrame added this to the v2.1 milestone Dec 21, 2016

@ThunderFrame ThunderFrame changed the title Locale dependant usage inspection for passing Date variables to String functions Locale dependant usage inspection for Implicit Date to String conversions Dec 21, 2016

@ThunderFrame

This comment has been minimized.

Copy link
Member Author

ThunderFrame commented Dec 21, 2016

Using concatenation operators with dates is another implicit conversion:

Dim myVar
myVar = Now & 1
@retailcoder

This comment has been minimized.

Copy link
Member

retailcoder commented Dec 21, 2016

Adding code path analysis, since for this one to be implemented properly we'll need to evaluate/resolve the type of the argument expressions being passed to string parameters, and be able to locate date-typed components of a string-valued expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.