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

CToD returns wrong result with right spaces #1275

Closed
Serggio opened this issue Jun 6, 2023 · 6 comments
Closed

CToD returns wrong result with right spaces #1275

Serggio opened this issue Jun 6, 2023 · 6 comments
Assignees
Milestone

Comments

@Serggio
Copy link

Serggio commented Jun 6, 2023

Consider this:

	SetDateFormat("DD.MM.YYYY")
	SetEpoch(1940)
	
	? CToD("01.01.23")	// prints 01.01.2023 as it should
	? CToD("01.01.2023")	// prints 01.01.2023 as it should
	? CToD("01.01.23  ")	// prints 01.01.0023 while it should be 01.01.2023

This issue is a regression: fails in X# 2.16.0.5 and works in 2.14 as expected. Such an untrimmed string often comes from edit controls where user may enter a two-digit year as a shorthand.

Perhaps, here is the reason:
image

@cpyrgas
Copy link

cpyrgas commented Jun 6, 2023

Robert, if you'd like I can research (how VO behaves in various related cases) and fix this (adjust it to to work the same in X#). Just please tell me know what did this 5881305 commit fix (but also caused this problem), so I will cover this as well.

@RobertvanderHulst
Copy link
Member

I created this change because of a problem that I saw in a customer code. The customer did this (date format MM/DD/YYYY)
CTOD("12/31/"+Str(nYear)) and this created a year number with 6 leading spaces, which was handled correctly in VO but not in X#. This resulted in an empty date in X#.

1 similar comment
@RobertvanderHulst
Copy link
Member

I created this change because of a problem that I saw in a customer code. The customer did this (date format MM/DD/YYYY)
CTOD("12/31/"+Str(nYear)) and this created a year number with 6 leading spaces, which was handled correctly in VO but not in X#. This resulted in an empty date in X#.

@cpyrgas
Copy link

cpyrgas commented Jun 7, 2023

OK, thanks, from what I see VO handles even this "correctly":

CToD("01.02.1*2-$ @ 2023 ")

and produces 01/02/2023, looks like it trims the string and then uses only the 4 last remaining characters from the year part, ignoring anything before those.

Will research it a bit more and will try to make the X# implementation as close as possible to VO. Will then send @Serggio an updated dll to give it a test as well

@cpyrgas cpyrgas self-assigned this Jun 7, 2023
@cpyrgas cpyrgas added this to the 2.17 milestone Jun 7, 2023
cpyrgas pushed a commit that referenced this issue Jun 7, 2023
…ToC() when the year is specified last in the date format template. When that's not the case, VO has a different and an even stranger behavior, if it becomes necessary in the future, we will look into that, too.
@cpyrgas
Copy link

cpyrgas commented Jun 7, 2023

Completely emulating VO's tremendously inconsistent behavior in all cases is simply impossible, so I added a special implementation only for the case where the year is specified last in the date format template. This makes this special (but most commonly used) case compatible enough (but still not 100%) to VO. In all other cases, the previous X# behavior is kept for now.

That should be good enough for the reported issues, @Serggio can you please give this updated dll a try?

XSharp.Core_DToC() fix.zip

@Serggio
Copy link
Author

Serggio commented Jun 7, 2023

@Serggio can you please give this updated dll a try

It works fine! Thank you!

RobertvanderHulst pushed a commit that referenced this issue Aug 21, 2023
…ToC() when the year is specified last in the date format template. When that's not the case, VO has a different and an even stranger behavior, if it becomes necessary in the future, we will look into that, too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants