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

DateTimeConverter encodign correct #686

Closed
PaxHumana opened this issue Mar 29, 2021 · 3 comments
Closed

DateTimeConverter encodign correct #686

PaxHumana opened this issue Mar 29, 2021 · 3 comments

Comments

@PaxHumana
Copy link

Calls to string.Format in the DateTimeConverter does not make use of DATE_TIME_CULTURE_INFO, the decoder does use is. Result is this will only work if encoding party uses the expected cultureinfo

See ex public static string Convert(System.DateTime dt, TimeStampPrecision precision ) line 242, should be:

public static string Convert(System.DateTime dt, TimeStampPrecision precision )
{
if (precision == TimeStampPrecision.Nanosecond)
{
return string.Format(DATE_TIME_CULTURE_INFO, DATE_TIME_FORMAT_WITH_NANOSECONDS, dt, dt.SubsecondAsNanoseconds());
}
else
{
var format = DATE_TIME_PRECISION_TO_FORMAT[precision];
return string.Format(DATE_TIME_CULTURE_INFO, format, dt);
}
}

@PaxHumana
Copy link
Author

Same issue in the UtcDateTimeSerializer, ToString does not use cultureinfo.InvariantCulture

@esamdal-aurora
Copy link

This problem can be reproduced by setting the time separator in the current thread's culture to something else than ":".
E.g.

`
var culture = CultureInfo.CreateSpecificCulture(Thread.CurrentThread.CurrentCulture.Name);
DateTimeFormatInfo dtfi = culture.DateTimeFormat;
dtfi.TimeSeparator = ".";
Thread.CurrentThread.CurrentCulture = culture;

var field = new DateTimeField(9999, DateTime.UtcNow);
Console.WriteLine("The time is invalid here:" + field.ToString());
`

@gbirchmeier
Copy link
Member

Fixed by #764 (and may yet be improved by #765)

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

3 participants