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

Reflection.SetNauAttributes doesn't parse date string correctly if OS is not set to English #121

Open
sonntam opened this issue Feb 18, 2018 · 2 comments

Comments

@sonntam
Copy link

sonntam commented Feb 18, 2018

The method Reflection.SetNauAttributes() fails on my windows machine that is set to German if I try to read a file date from the XML to set the property of a FileDateCondition.

The date of the example file SampleUpdateFeed.xml, i.e. 20091010T000000 is not parsed correctly.
I made a fix in my fork that uses the InvariantCulture from System.Globalizationfor the TryParse() call and adds a layer that tries to parse the above format explicitly.

Maybe you could have a look at my fix and possibly do a cherry-pick: sonntam/NAppUpdate@33f7b8c

@synhershko
Copy link
Owner

The fix looks good, although the magic string yyyyMMdd\\THHmmss does bother me a bit. Can you submit a PR along with a test?

@sonntam
Copy link
Author

sonntam commented Feb 27, 2018

Well, the date format yyyyMMdd\\THHmmss seems to only work for your culture settings. May I ask what culture setting in your OS you use and if you customized your date display format? It doesn't work with the InvariantCulture culture setting and I also couldn't get it to work using en-US.

One thing we could also do is try parsing the date string using the specific culture that you use on your machine. That way it would work without having to provide that "magic" format string.

The code would read something like

if( DateTime.TryParse( attValue,
    System.Globalization.CultureInfo.CreateSpecificCulture("xx-XX"),
    System.Globalization.DateTimeStyles.None, out dt ) )
{
    pi.SetValue(fieldsHolder, dt, null);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants