docx/custom-properties-types--filetime

The ``docProps/custom.xml`` part stores user-defined name/value pairs with a typed child from the ``vt:`` namespace. This family covers one case per type python-docx can emit: lpwstr, bool, i4, r8, filetime, and (as of 2026.05.7) date.

Library verdicts: python-docx: — docxjs: —

Metadata

Feature iddocx/custom-properties-types--filetime
Formatdocx
Categorymetadata
Familydocx/custom-properties-types
Axis valuestype=filetime
Spececma-376-5-part-2 § 11.2

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
custom-filetime-present
docProps/custom.xml
exist
TestProp must carry a <vt:filetime> child.
//op:property[@name='TestProp']/vt:filetime
custom-filetime-value
docProps/custom.xml
equal = 2026-01-15T12:30:45Z
TestProp's <vt:filetime> must carry the expected literal text.
//op:property[@name='TestProp']/vt:filetime

Render assertions

No render assertions declared.

Generator source

scripts/gen_custom_properties_types.py

#!/usr/bin/env python3
"""Generate ``fixtures/docx/custom-properties-types--<type>.docx`` fixtures.

Parameterised generator; drives ``features/docx/custom-properties-types.json``.
One .docx per vt: type python-docx can emit; the custom property is always
named ``TestProp``.
"""

from __future__ import annotations

import argparse
import datetime as _dt
from pathlib import Path

from docx import Document

_REPO_ROOT = Path(__file__).resolve().parent.parent

_PINNED_CREATED = _dt.datetime(2026, 1, 1, 0, 0, 0, tzinfo=_dt.timezone.utc)
_PINNED_MODIFIED = _dt.datetime(2026, 1, 2, 0, 0, 0, tzinfo=_dt.timezone.utc)


def _coerce(vt_id: str, value: str):
    if vt_id == "lpwstr":
        return value
    if vt_id == "bool":
        return value.lower() == "true"
    if vt_id == "i4":
        return int(value)
    if vt_id == "r8":
        return float(value)
    if vt_id == "filetime":
        # Naive datetime; python-docx treats it as UTC and serialises with Z.
        return _dt.datetime.strptime(value, "%Y-%m-%dT%H:%M:%S")
    if vt_id == "date":
        # Calendar date with no time/zone — serialised as vt:date YYYY-MM-DD.
        return _dt.datetime.strptime(value, "%Y-%m-%d").date()
    raise SystemExit(f"Unknown vt type id: {vt_id!r}")


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--type", dest="type_id", required=True)
    parser.add_argument("--value", required=True)
    parser.add_argument(
        "--out",
        default=str(_REPO_ROOT / "fixtures" / "docx" / "custom-properties-types.docx"),
    )
    args = parser.parse_args()

    out_path = Path(args.out)
    if not out_path.is_absolute():
        out_path = _REPO_ROOT / out_path

    doc = Document()
    doc.core_properties.created = _PINNED_CREATED
    doc.core_properties.modified = _PINNED_MODIFIED
    doc.custom_properties["TestProp"] = _coerce(args.type_id, args.value)
    doc.add_paragraph("Body content; custom property is the feature under test.")
    out_path.parent.mkdir(parents=True, exist_ok=True)
    doc.save(out_path, reproducible=True)
    print(out_path)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "docx/custom-properties-types--filetime",
  "kind": "literal",
  "title": "Custom document properties: one case per vt: type",
  "format": "docx",
  "category": "metadata",
  "summary": "The ``docProps/custom.xml`` part stores user-defined name/value pairs with a typed child from the ``vt:`` namespace. This family covers one case per type python-docx can emit: lpwstr, bool, i4, r8, filetime, and (as of 2026.05.7) date.",
  "spec": {
    "source": "ecma-376-5-part-2",
    "clause": "11.2",
    "notes": "ECMA-376 Part 2 / ISO 29500-2 section 11.2 defines the OPC custom-properties part. Each property must have a unique name, a fmtid, a pid >= 2, and exactly one typed child from the ``vt:`` (officeDocument/2006/docPropsVTypes) namespace. Supported authoring-side types in python-docx: ``str`` -> ``vt:lpwstr``, ``int`` -> ``vt:i4``, ``float`` -> ``vt:r8``, ``bool`` -> ``vt:bool``, ``datetime.datetime`` -> ``vt:filetime``, ``datetime.date`` -> ``vt:date`` (ECMA-376 Part 1 §22.4.2.7 — a calendar date with no time or zone, added in python-docx 2026.05.7 / Wave 8 W8-E)."
  },
  "fixtures": {
    "machine": "docx/custom-properties-types--filetime"
  },
  "generator": {
    "python": "scripts/gen_custom_properties_types.py",
    "arg_template": "--type {type.id} --value \"{type.value}\" --out fixtures/docx/custom-properties-types--{type.id}.docx"
  },
  "_expansion": {
    "parent_id": "docx/custom-properties-types",
    "bindings": {
      "type": "filetime"
    }
  },
  "assertions": [
    {
      "id": "custom-filetime-present",
      "part": "docProps/custom.xml",
      "namespaces": {
        "op": "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",
        "vt": "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
      },
      "xpath": "//op:property[@name='TestProp']/vt:filetime",
      "must": "exist",
      "description": "TestProp must carry a <vt:filetime> child."
    },
    {
      "id": "custom-filetime-value",
      "part": "docProps/custom.xml",
      "namespaces": {
        "op": "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties",
        "vt": "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"
      },
      "xpath": "//op:property[@name='TestProp']/vt:filetime",
      "must": "equal",
      "value": "2026-01-15T12:30:45Z",
      "description": "TestProp's <vt:filetime> must carry the expected literal text."
    }
  ]
}

Fixture

Download custom-properties-types--filetime.docx (19.0 KB)

Reference preview

No rendered reference is available for this case.

Spec notes

ECMA-376 Part 2 / ISO 29500-2 section 11.2 defines the OPC custom-properties part. Each property must have a unique name, a fmtid, a pid >= 2, and exactly one typed child from the ``vt:`` (officeDocument/2006/docPropsVTypes) namespace. Supported authoring-side types in python-docx: ``str`` -> ``vt:lpwstr``, ``int`` -> ``vt:i4``, ``float`` -> ``vt:r8``, ``bool`` -> ``vt:bool``, ``datetime.datetime`` -> ``vt:filetime``, ``datetime.date`` -> ``vt:date`` (ECMA-376 Part 1 §22.4.2.7 — a calendar date with no time or zone, added in python-docx 2026.05.7 / Wave 8 W8-E).