Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pydifact/segmentcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def __init__(
sender: Element,
recipient: Element,
control_reference: Element,
syntax_identifier: Element,
syntax_identifier: tuple[str, int],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to move here to an even more specific Element, but tuple[str, int] is ok for me for the moment.

timestamp: Optional[datetime.datetime] = None,
*args,
**kwargs,
Expand All @@ -379,7 +379,7 @@ def __init__(
def get_header_segment(self) -> Segment:
return Segment(
self.HEADER_TAG,
[str(i) for i in self.syntax_identifier],
[self.syntax_identifier[0], str(self.syntax_identifier[1])],
self.sender,
self.recipient,
["{:%y%m%d}".format(self.timestamp), "{:%H%M}".format(self.timestamp)],
Expand Down Expand Up @@ -499,10 +499,19 @@ def from_segments(
else:
raise EDISyntaxError("Timestamp of file-creation malformed.")

if (
isinstance(unb.elements[0], list)
and len(unb.elements[0]) == 2
and unb.elements[0][1].isdecimal()
):
syntax_identifier = (unb.elements[0][0], int(unb.elements[0][1]))
else:
raise EDISyntaxError("Syntax identifier malformed.")

datetime_str = "-".join(unb.elements[3])
timestamp = datetime.datetime.strptime(datetime_str, datetime_fmt)
interchange = Interchange(
syntax_identifier=unb.elements[0],
syntax_identifier=syntax_identifier,
sender=unb.elements[1],
recipient=unb.elements[2],
timestamp=timestamp,
Expand Down
Loading