Incorrect date/time parsing

Hello, I use Aspose Words for Java with LINQ reporting engine version 24.8 and have trouble with date time parsing when using setExactDateTimeParseFormats, seems like the time part is ignored and every date parsed with 00:00 time. I’m using JsonDataSource and setting options as described below. Also attaching sample json data and docx template.

    public JsonDataLoadOptions jsonDataLoadOptions() {
        var options = new JsonDataLoadOptions();
        options.setExactDateTimeParseFormats(List.of("yyyy-MM-dd", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd'T'HH:mm:ssXXX"));
        return options;
    }

json file:

{ 
  "dose" : "2001-07-04T12:08:56.235-07:00",
  "ex2" : "2024-07-25T21:15:00+00:00",
  "ex3" : "1722431394346",
  "ex4" : "1994-03-04"
}

The output I get:

Example: 03 Jul 2001 22:00
Example 2: 24 Jul 2024 22:00
Example 3: 31 Jul 2024 13:09
Example 4: 03 Mar 1994

Can you advise further steps to resolve the issue?

example.docx (8.6 KB)

@smialekp

JsonDataLoadOptions.setExactDateTimeParseFormats accepts .NET date-time format strings, so the following formats should be used instead:

options.setExactDateTimeParseFormats(Arrays.asList("yyyy-MM-dd", "yyyy-MM-dd'T'HH:mm:ss.fffzzz", "yyyy-MM-dd'T'HH:mm:sszzz"));

However, even if these formats are applied, the issue still remains. For the sake of correction, we have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSJAVA-2976

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks @ivan.lyagin
We observed that when we don not pass JsonDataLoadOptions at all dates seem to be parsed correctly along with time. We pass strings like 1/1 that are also parsed as Date, which we don’t want, thats why we tried to narrow the list of formats. Can you suggest a workaround for that issue while the fix is being developed? We are also facing another issue with Locale, seems like CurrentThreadSettings.setLocale(Locale.forLanguageTag("en_US")); is being ignored and the Locale from the machine running the reporting engine is used instead, any thoughts on that?

Best regards,
Przemek

@smialekp

You have correctly identified the way to restrict date-time parsing. Unfortunately, there is no other way around.

It seems like Locale.forLanguageTag may be misused in this case. Please compare results of the following calls:

System.out.println("With '_': " + Locale.forLanguageTag("en_US").getLanguage());
System.out.println("With '-': " + Locale.forLanguageTag("en-US").getLanguage());

If switching to “en-US” instead of “en_US” does not solve the issue, please share your sample template, data, and code reproducing the issue for further analysis on our end.

@ivan.lyagin I see WORDSJAVA-2976 is closed, was the issue resolved in latest aspose version?

@smialekp yes, the issue is already resolve in the current codebase. The fix will be included into the next 24.10 version of Aspose.Words. We will be sure to let you know once it is released.

The issues you have found earlier (filed as WORDSJAVA-2976) have been fixed in this Aspose.Words for Java 24.10 update.