Skip to content

Commit baa0bb6

Browse files
committed
Move DateTimeData from WorkGraph to here
1 parent d3e9780 commit baa0bb6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Source = "https://github.com/aiidateam/aiida-pythonjob"
6565
"pythonjob.numpy.int64" = "aiida.orm.nodes.data.int:Int"
6666
"pythonjob.numpy.bool_" = "aiida.orm.nodes.data.bool:Bool"
6767
"pythonjob.numpy.ndarray" = "aiida.orm.nodes.data.array.array.ArrayData"
68+
"pythonjob.datetime.datetime" = "pythonjob.orm.data:DateTimeData"
6869

6970
[project.entry-points."aiida.calculations"]
7071
"pythonjob.pythonjob" = "aiida_pythonjob.calculations.pythonjob:PythonJob"

src/aiida_pythonjob/data/common_data.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import datetime
2+
13
from aiida import orm
4+
from aiida.orm import Data
25

36

47
class NoneData(orm.Data):
@@ -24,3 +27,22 @@ def __repr__(self) -> str:
2427

2528
def __str__(self) -> str:
2629
return "NoneData()"
30+
31+
32+
class DateTimeData(Data):
33+
"""AiiDA node to store a datetime.datetime object."""
34+
35+
def __init__(self, value: datetime.datetime, **kwargs):
36+
if not isinstance(value, datetime.datetime):
37+
raise TypeError(f"Expected datetime.datetime, got {type(value)}")
38+
super().__init__(**kwargs)
39+
# Store as ISO string for portability
40+
self.base.attributes.set("datetime", value.isoformat())
41+
42+
@property
43+
def value(self) -> datetime.datetime:
44+
"""Return the stored datetime as a datetime object."""
45+
return datetime.datetime.fromisoformat(self.base.attributes.get("datetime"))
46+
47+
def __str__(self):
48+
return str(self.value)

0 commit comments

Comments
 (0)