#851 HisRead method from .Net ProjectHaystack.Client throws Invalid DateTime format error while running a...

Indumathi Anbumani Fri 28 Aug

Hi,

When using the "hisRead" ops method from ProjectHaystack.Client nuget package in code like below I get the output in Postman as expected while running my application at my local:

var auth = new NonHaystackBasicAuthenticator(Username, Password);

var client = new HttpAsyncClient(auth, new Uri(BaseUrl));

client.AuthUri = new Uri(BaseUrl + "user/auth");

await client.OpenAsync();

var response = client.hisRead(HRef.make(Id), "2020-08-21,2020-08-22").ToString();

outPut:

"ver:\"3.0\" id:@JACE7-5894 hisStart:2020-08-21T21:28:31.337+10:00 Sydney hisEnd:2020-08-22T18:21:54.646+10:00 Sydney\nts,val\n2020-08-21T21:28:31.337+10:00 Sydney,22.0951\n2020-08-21T21:46:32.966+10:00 Sydney,22.5137\n2020-08-22T06:09:06.676+10:00 Sydney,22.2695\n2020-08-22T06:33:29.923+10:00 Sydney,22.5137\n2020-08-22T18:05:03.882+10:00 Sydney,22.2695\n2020-08-22T18:21:54.646+10:00 Sydney,22.5137\n"

I have to run the my .net core 3.0 application containing the above code in docker as a docker container, on the Ubuntu 16.04 OS. When I use postman to trigger the "HisRead" ops api running as docker container:

I am getting "Invalid DateTime format for string 2020-08-21T21:28:31.337+10:00 Sydney for Timezone Name Sydney not able to convert from IANA to Windows Time Zone, exception occurred (Parameter name))" error.

I tried to run the "about" ops method that also has date as part of the output using the below code, I get the expected successful output both from my local and from running docker container without any issues :

var auth = new NonHaystackBasicAuthenticator(Username, Password);

var client = new HttpAsyncClient(auth, new Uri(BaseUrl));

client.AuthUri = new Uri(BaseUrl + "user/auth");

await client.OpenAsync();

Dictionary<string, string> searchParams = new Dictionary<string, string>();

result = await client.GetStringAsync("about", searchParams, "application/json", "application/json");

OutPut:

ver:"3.0" productUri,tz,moduleName,serverName,productName,haystackVersion,productVersion,moduleVersion,serverTime,serverBootTime "http://www.kodaro.com","Sydney","kodarohaystack","JACE7","KodaroHaystack","3.0","4.6.96.28.1.0.23","ModuleId",2020-08-17T10:32:20.494+10:00 Sydney,2020-08-10T07:26:16.829+10:00 Sydney

The DateTime format output from ops "about" is the same format used in "HisRead" ops as well. I am unable to figure out why it throws the dateTime format error only for "HisRead" and not for "about" ops method when the application is containerized in docker. I also tried converting "HisRead" method toJson and toZinc as well and I get the same error for them too. Since I was getting the same error irrespective of the type of conversion, I tried to run the "HisRead" ops method without any conversion like below to check and this direct method itself throws the DateTime format error from the docker container:

var response = client.hisRead(HRef.make(Id), "2020-08-21,2020-08-22");

Since I get error from the above code, I am not sure how to handle the DateTime format issue in .net core 3.0 application. Please note "HisRead" method works as expected in my local. The problem happens when "HisRead" method is triggered from the running containerized docker application.

I am really struggling to understand what is happening here, any guidance or advice with regards to this issue will really help. Thanks a lot.

Chris Breederveld Sat 29 Aug

Hi Indumathi,

The library currently uses the TimeZoneConverter.TZConvert.IanaToWindows function from the TimeZoneConverter NuGet package, which in this case cannot find the conversion for the given Sydney timezone.

I would suggest you try upgrading that NuGet package to the latest version to see if that solves your problem. Otherwise you can create some simple test using only that library to see if you can reproduce it only on that library as well and if so reach out to the community of that library.

When I have time I will see if I too can reproduce and solve this issue on a Ubuntu server using other means.

Indumathi Anbumani Tue 1 Sep

Thanks a lot for your quick response Chris.

As mentioned by you I double checked the version of the TimeZoneConverter NuGet package and it was the latest. Based on your comments I tried to debug the project haystack source code and found the error. It occurs in the HTimeZone.cs file at the method make(string name, bool bChecked)in the lines:

tziFound = TimeZoneInfo.FindSystemTimeZoneById(strWindowsTimeZoneID);

The strWindowsTimeZoneID has the value "AUS Eastern Standard Time" and it is unable to find the timezone file corresponding to "AUS Eastern Standard Time" in the /usr/share/zoneinfo folder in my docker container. The container has timezone files corresponding to IANA timezones and not Windows.It is because Iam running the .net application as container inside Ubuntu 16.04 OS. Each system have different timezone names.

In the method make(string name, bool bChecked) mentioned it is converting the IANA timezone Id "Australia/Sydney" found to Windows TimeZone Id "AUS Eastern Standard Time" in the below section of code. In my case this is the one causing the error as I want the IANA timezone Id "Australia/Sydney" and have the file corresponding to it in the system.

while ((!bFound) && (iCurIndex < iLength))

{

if (TimeZoneConverter.TZConvert.KnownIanaTimeZoneNames.ToArray()[iCurIndex].ToUpper().Contains(strNameToSearch.ToUpper()))

{

bFound = true;

strIANATimeZoneID = TimeZoneConverter.TZConvert.KnownIanaTimeZoneNames.ToArray()[iCurIndex];

}

iCurIndex++;

}

if (bFound)

{

try

{

strWindowsTimeZoneID = TimeZoneConverter.TZConvert.IanaToWindows(strIANATimeZoneID);

tziFound = TimeZoneInfo.FindSystemTimeZoneById(strWindowsTimeZoneID);

}

Requesting if this method could be kindly modified to include a check to see if IANA timezone Id like "Australia/Sydney" is present in the system, if not then proceed to convert IANA id to Windows timezone Id like "AUS Eastern Standard Time". I think this modification will really help any one running .net applications as docker containers with Linux system.

Thanks a lot Chris

Chris Breederveld Tue 1 Sep

Hi Indumathi,

Thanks for the detailed feedback. I haven't managed to test on an Ubuntu system yet, but I have seen that the make method uses the TimeZoneInfo class in the conversion, while TimeZoneConverter should also suffice. With that in mind I have created this branch which you may want to check out to see if this solves your problem (also contains a couple of new unit tests for this issue): https://github.com/Strukton-Worksphere/haystack-csharp/tree/bugfix/linux-iata

If this solves your problem I will integrate it and release a new version, if not you are also very welcome to create your own fork and create a PR with a fix of your own.

Indumathi Anbumani Wed 2 Sep

Thanks a lot Chris for the quick code update to fix the time conversion issue. I was able to test your updated solution successfully in my Ubuntu Virtual Machine. Kindly integrate them to the new version.

Chris Breederveld Wed 2 Sep

No problem Indumathi, I'm happy my blind fix did the job.

A new version of the package, 1.5.2, is now available with the fix.

Indumathi Anbumani Thu 3 Sep

Thanks for the new version Chris, I tested my application again with the new version and it works perfectly well.

Login or Signup to reply.