adeu icon indicating copy to clipboard operation
adeu copied to clipboard

A revision and its comment are dated from different clocks

Open houfu opened this issue 2 months ago • 1 comments

Summary

A tracked change and the comment attached to it are dated from two different clocks. Revisions use RedlineEngine.timestamp, which is taken once when the engine is constructed (redline/engine.py). Comments use datetime.now() at the moment each comment is written (redline/comments.py, in the comment-creation path). When time passes between constructing the engine and applying the batch, the change and its own comment carry different times.

Reproduce

Python engine, 3.0.6 from PyPI, and main at 965736d2.

import io, re, time, zipfile
from docx import Document
from adeu import ModifyText, RedlineEngine

doc = Document(); doc.add_paragraph("The Supplier shall deliver the Goods.")
buf = io.BytesIO(); doc.save(buf)

engine = RedlineEngine(io.BytesIO(buf.getvalue()), author="Tester")
time.sleep(3)   # the caller plans its edits, or waits on a model
engine.process_batch([ModifyText(target_text="deliver", new_text="supply", comment="Wider verb.")])

z = zipfile.ZipFile(io.BytesIO(engine.save_to_stream().getvalue()))
part = next(n for n in z.namelist() if re.fullmatch(r"word/comments\d*\.xml", n))
print(set(re.findall(r'<w:(?:ins|del) [^>]*w:date="([^"]+)"', z.read("word/document.xml").decode())))
print(set(re.findall(r'<w:comment [^>]*w:date="([^"]+)"', z.read(part).decode())))
# {'2026-10-04T00:43:33Z'}
# {'2026-10-04T00:43:36Z'}

Why it matters

  • A reviewer in Word sees a change and its explanation stamped at different times, which reads as two sittings.
  • A caller that wants a fixed date on its output (for reproducible files, or to date a redline with the time of the run that produced it) can assign engine.timestamp (there is no argument for it), and gets that date on the revisions and the wall clock on the comments.

Expected

Comments created during a batch use the engine's timestamp, so one batch carries one date. A timestamp argument on RedlineEngine would make the fixed-date case a supported one.

Workaround in use

After the batch, set w:date on each comment the batch added to engine.timestamp.

Drafted with Claude Code; the reproduction above was run as shown.

houfu avatar Oct 04 '26 00:10 houfu

Thank you @houfu! This is fixed in main and will be included in the next release.

Git-Uzair avatar Oct 05 '26 10:10 Git-Uzair