Different Revision time value between versions

We recently upgraded (Aspose Words for Java) from version 21.10 to version 22.12 and noticed that when executing the getDateTime().getTime() method on the Revision instance, a different value is obtained (method getTime() returns a long data type that represents the time value in ms, counting from 1.1.1970).

Specifically, for each revision in the document, with version 21.10 we got the value 1616515560000, while version 22.12 returns us the value 1616511960000.

I don’t know if this is the expected behavior or if it’s a bug, but we need to get the value we were getting before (1616515560000), so please fix it or let us know how to get it come.

In the attachment, I am sending an example of the code that you can use to reproduce the above and the file on which the same should be executed.

PS
If it matters, we’ve noticed that the behavior change has been occurring since version 22.6 and is also present in 23.1.

Thanks!
Nenad

report.zip (10.4 KB)

@zpredojevic The current updated behavior is correct. You should convert the returned Date to LocalDate to get the desired output:

public static LocalDate convertToLocalDateViaInstant(Date dateToConvert) {
    return dateToConvert.toInstant()
        .atZone(ZoneId.systemDefault())
        .toLocalDate();
}

@alexey.noskov

The solution you suggested us to use returns the local time we already have.

We need time corresponding to UTC+00:00 zone.

@zpredojevic Revision in your document is specified in the following format:

<w:ins w:id="0" w:author="user" w:date="2021-03-23T16:06:00Z">

Your expected value is the following:

DateFormat dateFormat = new SimpleDateFormat("yyyy-MMMM-dd hh:mm:ss aa");
Date expected = new Date(1616515560000L);
System.out.println("Expected date: " + dateFormat.format(expected.getTime()));

that returns:

Expected date:2021-March-23 06:06:00 PM

That corresponds the date without taking time zone in account. Aspose.Words returns the same value as displayed in MS Word UI:

The following code:

System.out.println("Date in human readable format: " + dateFormat.format(revision.getDateTime().getTime()));

returns:

Date in human readable format: 2021-March-23 04:06:00 PM

To get the desired output you should do the follwoing:

LocalDateTime localDate = convertToLocalDateTimeViaInstant(revision.getDateTime());
ZonedDateTime zdt = localDate.atZone(ZoneId.of("UTC"));
Date date = Date.from(zdt.toInstant());
System.out.println("Date as local, Time (offset in ms from 1970): " + date.getTime());
System.out.println("Date as local: " + dateFormat.format(date));
public static LocalDateTime convertToLocalDateTimeViaInstant(Date dateToConvert) {
    return dateToConvert.toInstant()
            .atZone(ZoneId.systemDefault())
            .toLocalDateTime();
}

@alexey.noskov

We managed to overcome the problem. Thank you for your cooperation!

1 Like