We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words - CurrentThreadSettings seems to be ignored

Hello.

When populating a Word document with Date values, Aspose.Words uses timezone of a server/jvm. This means end users get documents in jvm timezone rather than in user’s timezone.

Environment is as follows:

  • A server with Aspose.Words in timezone1, java8
  • A user from timezone2 initiates document generation.
  • Aspose takes a simple word template like shown below, where “event.date” is a java.util.Date object in timezone2
    <<foreach [event in events]>> <<[event.date]>> <</foreach>>
  • ReportingEngine.buildReport(…) generates a document, where “event.date” is converted to timezone1 (server’s timezone)

As a result, user gets invalid date (in invalid timezone).

According to the link below, there is CurrentThreadSettings public API class
https://docs.aspose.com/display/wordsjava/Aspose.Words+for+Java+17.3.0+Release+Notes

Indeed found it in apose.words jar, but couldn’t make it work: compiles ok, but seems to be ignored.

Questions:

  1. What would be the correct way of overriding timezone on a per document basis? In my case, server can generate documents from multiple users/timezones in different threads thus need timezone settings per-document.
  2. Is there API doc for the CurrentThreadSettings class? I could not find docs for it. Could you please provide a link?
  3. The CurrentThreadSettings class has setTimeZone. But it doesn’t seem to fix timezone issue. Is this correct way to use it?
    CurrentThreadSettings.setTimeZone(TimeZone.getTimeZone(“Australia/Darwin”));
    Document doc = new Document(…);

Thank you.

@zuzuzu

Aspose.Words does not set the Locale on document level. You need to set the locale according to your requirement at the system where you are generating the document.

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

DateIssue.zip (10.0 MB)
Attached zip contains java sources and two documents, that were generated by running main.
One document (dateAustralia.doc) generated for “Australia/Darwin” timezone, second (dateLondon.doc) generated for “Europe/London” timezone. If you look into generated documents, both have the same date inserted, even though CurrentThreadSettings.setTimeZone was used.
I believe both dates are equal because Aspose took the timezone from machine where documents were generated (which for testing was set to +9, Yakutsk, Russian Federation).

Expected output from the code I attached: documents have different times, because CurrentThreadSettings.setTimeZone gets set to different value before each document.

Thanks.

@zuzuzu

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSJAVA-2097. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

1 Like

The issues you have found earlier (filed as WORDSJAVA-2097) have been fixed in this Aspose.Words for .NET 19.7 update and this Aspose.Words for Java 19.7 update.

1 Like

A post was split to a new topic: The time zone is not set to “America/New_York”