mikhail-barg / jsonata.net.native

.Net native implementation of JSONata query and transformation language (http://jsonata.org)
MIT License
40 stars 6 forks source link

$fromMillis is not working as expected in C# #17

Closed sureshssb07 closed 1 year ago

sureshssb07 commented 1 year ago

$fromMillis is not working as expected in C#

Code: var jsonQ = "$toMillis('10/12/2018', '[D]/[M]/[Y]') ~> $fromMillis('[M]/[D]/[Y]')"; // It is mentioned in Date/Time processing as example var jsonQuery = new JsonataQuery(jsonQ); var jsonValue = jsonQuery.Eval(jsonData); return jsonValue;

Exception : D3136 : Failed to parse tdate/time from '10/12/2018'

But above example is working in JSONata Exerciser tool

And We tried with alternate approach with the format $toMillis('10/12/2018', 'dd/MM/yyyy') ~> $fromMillis('dd/MM/yyyy'). Parse is success but we are getting incorrect date in $fromMillis method "09/12/2018"

mikhail-barg commented 1 year ago

Hi @sureshssb07, thanks for reporting this.

For the part where you try original jsonata-js "picture" (format) strings like '[D]/[M]/[Y]' it is expected not to work. As mentioned in readme, my implementation uses

C# custom and standard format strings for picture argument instead of XPath format used in JSonataJS

But the second thing where $toMillis('10/12/2018', 'dd/MM/yyyy') ~> $fromMillis('dd/MM/yyyy') does not give original date, it surely a bug.

I've found a reason for this behavior (using local time when parsing date with toMillis()), and I will get to release a fix soon.

mikhail-barg commented 1 year ago

Just released v2.4.1 with a fix. Will close this for now. Please feel free to re-open the issue, if the fix does not help.