diff --git a/examples/example_p1.json b/examples/example_p1.json index 1fd33ba..5639a9c 100644 --- a/examples/example_p1.json +++ b/examples/example_p1.json @@ -22,17 +22,17 @@ { "relation_type": "IS_PART_OF", "related_identifier": "https://example.org/collection", - "datetime_log": "2024-02-19T00:00:00Z" + "datetime_log": "2024-02-19T00:00:00+00:00" }, { "relation_type": "IS_REFERENCED_BY", "related_identifier": "https://example.org/referenced", - "datetime_log": "2024-02-19T00:00:00Z" + "datetime_log": "2024-02-19T00:00:00+00:00" } ], "change_log": [ { - "datetime_log": "2024-02-19T00:00:00Z", + "datetime_log": "2024-02-19T00:00:00+00:00", "has_agent": { "name": "Data Fuzzi", "email": "data.fuzzi@example.org", @@ -44,7 +44,7 @@ "description": "Registration completed." }, { - "datetime_log": "2024-05-15T15:51:15Z", + "datetime_log": "2024-05-15T15:51:15+00:00", "has_agent": { "name": "Data Fuzzi", "email": "data.fuzzi@example.org", diff --git a/examples/example_p1_dataclasses.py b/examples/example_p1_dataclasses.py index 8207e5e..84f891e 100644 --- a/examples/example_p1_dataclasses.py +++ b/examples/example_p1_dataclasses.py @@ -1,8 +1,13 @@ +import sys +from datetime import datetime from linkml_runtime.dumpers import json_dumper from pid4cat_model.datamodel import pid4cat_model as p4c # Demonstrate the use of Python DataClass-based model +if sys.version_info < (3, 11): + raise RuntimeError("Python 3.11 or higher is required due to the use of datetime.fromisoformat") + p1_Agent = p4c.Agent( name="Data Fuzzi", email="data.fuzzi@example.org", @@ -15,12 +20,12 @@ p4c.PID4CatRelation( relation_type=p4c.RelationType.IS_PART_OF, related_identifier="https://example.org/collection", - datetime_log="2024-02-19T00:00:00Z", + datetime_log=datetime.fromisoformat("2024-02-19T00:00:00Z"), ), p4c.PID4CatRelation( relation_type=p4c.RelationType.IS_REFERENCED_BY, related_identifier="https://example.org/referenced", - datetime_log="2024-02-19T00:00:00Z", + datetime_log=datetime.fromisoformat("2024-02-19T00:00:00Z"), ), ] @@ -43,13 +48,13 @@ p1_log = [ p4c.LogRecord( - datetime_log="2024-02-19T00:00:00Z", + datetime_log=datetime.fromisoformat("2024-02-19T00:00:00Z"), has_agent=p1_Agent, changed_field=p4c.ChangeLogField.STATUS, description="Registration completed.", ), p4c.LogRecord( - datetime_log="2024-05-15T15:51:15Z", + datetime_log=datetime.fromisoformat("2024-05-15T15:51:15Z"), has_agent=p1_Agent, changed_field=p4c.ChangeLogField.RESOURCE_INFO, description="as requested in issue #234", diff --git a/examples/example_p1_pydantic.py b/examples/example_p1_pydantic.py index cc9fb0d..dcafae9 100644 --- a/examples/example_p1_pydantic.py +++ b/examples/example_p1_pydantic.py @@ -1,9 +1,14 @@ +import sys +from datetime import datetime from pathlib import Path from linkml_runtime.dumpers import json_dumper, yaml_dumper from pid4cat_model.datamodel import pid4cat_model_pydantic as p4c # Demonstrate the use of Pydantic models +if sys.version_info < (3, 11): + raise RuntimeError("Python 3.11 or higher is required due to the use of datetime.fromisoformat") + p1_Agent = p4c.Agent( name="Data Fuzzi", email="data.fuzzi@example.org", @@ -16,12 +21,12 @@ p4c.PID4CatRelation( relation_type=p4c.RelationType.IS_PART_OF, related_identifier="https://example.org/collection", - datetime_log="2024-02-19T00:00:00Z", + datetime_log=datetime.fromisoformat("2024-02-19T00:00:00Z"), ), p4c.PID4CatRelation( relation_type=p4c.RelationType.IS_REFERENCED_BY, related_identifier="https://example.org/referenced", - datetime_log="2024-02-19T00:00:00Z", + datetime_log=datetime.fromisoformat("2024-02-19T00:00:00Z"), ), ] @@ -44,13 +49,13 @@ p1_log = [ p4c.LogRecord( - datetime_log="2024-02-19T00:00:00Z", + datetime_log=datetime.fromisoformat("2024-02-19T00:00:00Z"), has_agent=p1_Agent, changed_field=p4c.ChangeLogField.STATUS, description="Registration completed.", ), p4c.LogRecord( - datetime_log="2024-05-15T15:51:15Z", + datetime_log=datetime.fromisoformat("2024-05-15T15:51:15Z"), has_agent=p1_Agent, changed_field=p4c.ChangeLogField.RESOURCE_INFO, description="as requested in issue #234", @@ -73,6 +78,8 @@ print(p1) +print(yaml_dumper.dumps(c)) + print(json_dumper.dumps(p1)) # write json to file @@ -80,5 +87,3 @@ with open(script_folder / "example_p1.json", "w", encoding="utf-8") as f: f.write(json_dumper.dumps(p1)) - -print(yaml_dumper.dumps(c))