File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff line change 1+ import datetime
2+
13from aiida import orm
4+ from aiida .orm import Data
25
36
47class 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 )
You can’t perform that action at this time.
0 commit comments