Setting comment timestamps not reflected in word document when opening

Currently we are inserting comment into Aspose with a UTC timestamp. When we open the document in Word we would expect our local timestamp to show up. This is not the case and it is staying at the UTC timestamp.

While investigating we found that when creating comments in the word application a “CommentsExtensible.xml” file shows up. However when creating comments programmatically with Aspose there is no such file in the word zip.

We have tried 22.6, 23.11 and 24.3 all versions of the product are having this problem.

@rogarg CommentsExtensible.xml is created when MS Word document is optimized for MS Word 2019. So if you create document using the following code, CommentsExtensible.xml will be there in the output:

Document doc = new Document();

Comment c = new Comment(doc, "Aspose", "AW", new DateTime(2024, 4, 4, 16, 00, 00));
Paragraph p = c.AppendChild(new Paragraph(doc));
p.AppendChild(new Run(doc, "This is a cool comment"));
doc.FirstSection.Body.FirstParagraph.AppendChild(c);

doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2019);
doc.Save(@"C:\Temp\out.docx");

@alexey.noskov Thanks for helping a follow up question.

I am having issues when reading comment timestamps for documents created on a another machine.

  1. Create a file in say EST timezone and comment at 1pm
  2. Send the file to a machine in CST
  3. use aspose library to read from file in cst timezone
  4. what we ready from comment is a local time of 1PM however dateTime library treats this like a CST time not a UTC time. Meaning one additional hour is added to convert to UTC. wWe would expect to read a local time of 12PM if reading a document on a CST machine.

Another example
comment at 10:32 PST (5:32 PM UTC)
Send this document to a server in CST
When reading from the document aspose will read 10:33 local time and convert that to 3:32 UTC rather then 5:32 UTC.
I would expect aspose to read 12:32 local time and convert that to 5:32 UTC

How do I read the timezone localized to the machine aspose is running on rather then the machine that created the document and left the comment.

@rogarg Could you please attach your input documents and expected outputs? We will check the issue and provide you more information.
According to the comments in the code comment date is written as is, without conversion to UTC. When reading, kind of comment date is set to Local.

BeginningOfDocumentComments.docx (16.6 KB)

Expected:
UTC Timestamp of 5:32 and 5:33 for the two comments when reading from aspose

@rogarg Aspose.Words returns time stored in the document as is:

<w:comment w:id="0" w:author="Bill Winter" w:date="2024-04-08T10:32:00Z" w:initials="BW">
<w:comment w:id="1" w:author="Bill Winter" w:date="2024-04-08T10:33:00Z" w:initials="BW">

The following code returns the same values:

Document doc = new Document(@"C:\Temp\in.docx");
foreach (Comment c in doc.GetChildNodes(NodeType.Comment, true))
{
    Console.WriteLine(c.DateTime);
}
4/8/2024 10:32:00
4/8/2024 10:33:00

@alexey.noskov that is only the correct time printed if you are Pacific timezone.
If I ran that code from a machine in EST I would expect to see 1:32 printed.

c.DateTime.ToUTCDateTime() will print the incorrect time as well. Regardless of region that should print out 5:32, but instead it will print out a different value based on the timezone of the machine you are running the code on.

Also that is the incorrect timezone value stored as the value indicates that the time is 10:32 UTC. But the time is 10:32 PST which is 5:32PM UTC.

@rogarg Aspose.Words returns an expected output. Aspose.Words reads comment DateTime as is and sets kind of comment date to Local.

Document doc = new Document(@"C:\Temp\in.docx");
foreach (Comment c in doc.GetChildNodes(NodeType.Comment, true))
{
    Console.WriteLine(c.DateTime); // Returns 4/8/2024 10:32:00
    Console.WriteLine(c.DateTime.Kind); // Returns local
    Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(c.DateTime)); // Returns 4/8/2024 07:32:00 on my side
}

Please see Microsoft documentation for more information:
https://learn.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones

@alexey.noskov
That is the incorrect time, as mentioned earlier the PST time is 10:32AM and the UTC should be 5:32PM not 7:32AM. Please advise on this ASAP.
Open the file locally on your computer in word and you will see that the values are different

@rogarg The values are correct. As I have mentioned Aspose.Words read the value stored in the document as is and sets kind of comment date to Local. You can convert this value as it is required for your needs.
If you check comments.xml you will see the following:

<w:comment w:id="0" w:author="Bill Winter" w:date="2024-04-08T10:32:00Z" w:initials="BW">
<w:comment w:id="1" w:author="Bill Winter" w:date="2024-04-08T10:33:00Z" w:initials="BW">

i.e. dates returned by Comment.DateTime property.
If you check commentsExtensible.xml you will see the following:

<w16cex:commentExtensible w16cex:durableId="12EC8C19" w16cex:dateUtc="2024-04-08T17:32:00Z"/>
<w16cex:commentExtensible w16cex:durableId="483A933D" w16cex:dateUtc="2024-04-08T17:33:00Z"/>

i.e. values returned by Comment.DateTime.ToUniversalTime().

@alexey.noskov these are the correct values in commentsextensible.xml, but Aspose is NOT returning the correct values. You mentioned yourself above that Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(c.DateTime)); // Returns 4/8/2024 07:32:00 on my side

Proper UTC Time in CommentsExtensible: 5:32PM
Time returned by c.DateTime.ToUniversalTim() => Returns a different value depending what timezone your server running the code is in.
Please provide guidance on this!

@rogarg As I have mentioned Aspose.Words reads the comment date specified in comments.xml as is and sets kind of comment date to Local. In your particular case it is w:date="2024-04-08T10:32:00Z". If commentsExtensible.xml does not exist in the document and it is required to write it, Aspose.Words converts the local date read from comments.xml to UTC using DataTime.ToUniversalTime().

Actually I do not understand from where the value of 5.32PM should be taken because value stored in commentsExtensible.xml is w16cex:dateUtc="2024-04-08T17:33:00Z".

@alexey.noskov

The value of 5:32 is also in the document, if you see comments extensible you can see that thre is a comment with UTC timestmap of 5:32 PM (17:33) UTC

Okay so Aspose is implemented to read the local time, is there any way to get Aspose to read the UTC time instead? If the machine that is running Aspose is on a different timezone to the machine that created the comments then we will be reading the incorrect times. We want to read the dateUtc time per comment NOT the local time.

@rogarg
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): WORDSNET-26923

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.