MCPcopy Create free account
hub / github.com/scanny/python-pptx / _set_element_datetime

Method _set_element_datetime

src/pptx/oxml/coreprops.py:256–271  ·  view source on GitHub ↗

Set date/time value of child element having `prop_name` to `value`.

(self, prop_name: str, value: dt.datetime)

Source from the content-addressed store, hash-verified

254 return timestamp
255
256 def _set_element_datetime(self, prop_name: str, value: dt.datetime) -> None:
257 """Set date/time value of child element having `prop_name` to `value`."""
258 if not isinstance(value, dt.datetime): # pyright: ignore[reportUnnecessaryIsInstance]
259 tmpl = "property requires <type 'datetime.datetime'> object, got %s"
260 raise ValueError(tmpl % type(value))
261 element = self._get_or_add(prop_name)
262 dt_str = value.strftime("%Y-%m-%dT%H:%M:%SZ")
263 element.text = dt_str
264 if prop_name in ("created", "modified"):
265 # These two require an explicit 'xsi:type="dcterms:W3CDTF"'
266 # attribute. The first and last line are a hack required to add
267 # the xsi namespace to the root element rather than each child
268 # element in which it is referenced
269 self.set(qn("xsi:foo"), "bar")
270 element.set(qn("xsi:type"), "dcterms:W3CDTF")
271 del self.attrib[qn("xsi:foo")]
272
273 def _set_element_text(self, prop_name: str, value: str) -> None:
274 """Set string value of `name` property to `value`."""

Callers 3

created_datetimeMethod · 0.95
lastPrinted_datetimeMethod · 0.95
modified_datetimeMethod · 0.95

Calls 2

_get_or_addMethod · 0.95
qnFunction · 0.90

Tested by

no test coverage detected