diff --git a/stix2/v20/common.py b/stix2/v20/common.py index 0a0cabc..682d4b3 100644 --- a/stix2/v20/common.py +++ b/stix2/v20/common.py @@ -128,6 +128,16 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin): self._properties.update([ ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), ]) + else: + try: + #statement instances will match the precision given + if kwargs['created'].rfind('.') != -1: + self._properties = copy.deepcopy(self._properties) + self._properties.update([ + ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), + ]) + except AttributeError: + pass if not isinstance(kwargs['definition'], marking_type): defn = _get_dict(kwargs['definition']) diff --git a/stix2/v21/common.py b/stix2/v21/common.py index 13d0ff6..881eced 100644 --- a/stix2/v21/common.py +++ b/stix2/v21/common.py @@ -146,7 +146,7 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin): ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type)), ('created_by_ref', ReferenceProperty(type='identity')), - ('created', TimestampProperty(default=lambda: NOW)), + ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), ('external_references', ListProperty(ExternalReference)), ('object_marking_refs', ListProperty(ReferenceProperty(type='marking-definition'))), ('granular_markings', ListProperty(GranularMarking)), @@ -162,13 +162,6 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin): except KeyError: raise ValueError("definition_type must be a valid marking type") - if marking_type == TLPMarking: - # TLP instances in the spec have millisecond precision unlike other markings - self._properties = copy.deepcopy(self._properties) - self._properties.update([ - ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), - ]) - if not isinstance(kwargs['definition'], marking_type): defn = _get_dict(kwargs['definition']) kwargs['definition'] = marking_type(**defn)