Skip to content

Commit 35eaa1c

Browse files
committed
Added date support to GanttSeries.
1 parent 7d6d148 commit 35eaa1c

File tree

1 file changed

+25
-9
lines changed
  • highcharts_gantt/options/series/data

1 file changed

+25
-9
lines changed

highcharts_gantt/options/series/data/gantt.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional, List
22
from decimal import Decimal
3-
from datetime import datetime
3+
from datetime import datetime, date
44

55
from validator_collection import validators, checkers
66

@@ -192,7 +192,7 @@ def dependency(self, value):
192192
self._dependency = [x for x in processed_value]
193193

194194
@property
195-
def end(self) -> Optional[datetime]:
195+
def end(self) -> Optional[datetime | date]:
196196
"""The end time of the data point (task).
197197
198198
.. note::
@@ -205,13 +205,19 @@ def end(self) -> Optional[datetime]:
205205
JavaScript object literal notation it will be converted back to a numerical
206206
value.
207207
208-
:rtype: :class:`datetime <python:datetime.datetime>` or :obj:`None <python:None>`
208+
:rtype: :class:`datetime <python:datetime.datetime>` or :class:`date <python:datetime.date>`
209+
or :obj:`None <python:None>`
209210
"""
210211
return self._end
211212

212213
@end.setter
213214
def end(self, value):
214-
self._end = validators.datetime(value, allow_empty = True, coerce_value = True)
215+
if not value:
216+
self._end = None
217+
elif checkers.is_date(value):
218+
self._end = validators.date(value, allow_empty = True)
219+
else:
220+
self._end = validators.datetime(value, allow_empty = True, coerce_value = True)
215221

216222
@property
217223
def milestone(self) -> Optional[bool]:
@@ -247,7 +253,7 @@ def parent(self, value):
247253
self._parent = validators.string(value, allow_empty = True)
248254

249255
@property
250-
def start(self) -> Optional[datetime]:
256+
def start(self) -> Optional[date | datetime]:
251257
"""The start time of the data point (task).
252258
253259
.. note::
@@ -260,13 +266,19 @@ def start(self) -> Optional[datetime]:
260266
JavaScript object literal notation it will be converted back to a numerical
261267
value.
262268
263-
:rtype: :class:`datetime <python:datetime.datetime>` or :obj:`None <python:None>`
269+
:rtype: :class:`datetime <python:datetime.datetime>` or :class:`date <python:datetime.date>`
270+
or :obj:`None <python:None>`
264271
"""
265272
return self._start
266273

267274
@start.setter
268275
def start(self, value):
269-
self._start = validators.datetime(value, allow_empty = True, coerce_value = True)
276+
if not value:
277+
self._start = None
278+
elif checkers.is_date(value):
279+
self._start = validators.date(value, allow_empty = True)
280+
elif checkers.is_datetime(value):
281+
self._start = validators.datetime(value, allow_empty = True, coerce_value = True)
270282

271283
@property
272284
def y(self) -> Optional[int | float | Decimal]:
@@ -332,10 +344,14 @@ def _to_untrimmed_dict(self, in_cls = None) -> dict:
332344
'y': self.y
333345
}
334346

335-
if self.end is not None:
347+
if self.end is not None and hasattr(self.end, 'timestamp'):
336348
untrimmed['end'] = self.end.timestamp()
337-
if self.start is not None:
349+
else:
350+
untrimmed['end'] = self.end
351+
if self.start is not None and hasattr(self.start, 'timestamp'):
338352
untrimmed['start'] = self.start.timestamp()
353+
else:
354+
untrimmed['start'] = self.start
339355

340356
parent_as_dict = super()._to_untrimmed_dict(in_cls = in_cls)
341357
for key in parent_as_dict:

0 commit comments

Comments
 (0)