Skip to content

Commit 6d6de04

Browse files
authored
Merge pull request #375 from sartography/bugfix/correct-and-simplify-date-calculations
bugfix for invalid date
2 parents e4ceff4 + 55ca268 commit 6d6de04

File tree

1 file changed

+11
-7
lines changed
  • SpiffWorkflow/bpmn/specs/event_definitions

1 file changed

+11
-7
lines changed

SpiffWorkflow/bpmn/specs/event_definitions/timer.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ def get_timedelta_from_start(parsed_duration, start=None):
3737
months += years * 12
3838

3939
for idx in range(int(months)):
40-
year, month = start.year + idx // 12, start.month + idx % 12
40+
year = start.year + (start.month + idx - 1) // 12
41+
month = (start.month + idx) % 12 or 12
4142
days += monthrange(year, month)[1]
4243

43-
year, month = start.year + months // 12, start.month + months % 12
44+
year = start.year + (start.month + months - 1) // 12
45+
month = (start.month + months) % 12 or 12
4446
days += (months - int(months)) * monthrange(year, month)[1]
47+
4548
parsed_duration['days'] = days
4649
return timedelta(**parsed_duration)
4750

@@ -53,12 +56,13 @@ def get_timedelta_from_end(parsed_duration, end):
5356

5457
for idx in range(1, int(months) + 1):
5558
year = end.year - (1 + (idx - end.month) // 12)
56-
month = 1 + (end.month - idx - 1) % 12
59+
month = (end.month - idx) % 12 or 12
5760
days += monthrange(year, month)[1]
5861

59-
days += (months - int(months)) * monthrange(
60-
end.year - (1 + (int(months)- end.month) // 12),
61-
1 + (end.month - months - 1) % 12)[1]
62+
year = end.year - (1 + (months - end.month) // 12)
63+
month = (end.month - months) % 12 or 12
64+
days += (months - int(months)) * monthrange(year, month)[1]
65+
6266
parsed_duration['days'] = days
6367
return timedelta(**parsed_duration)
6468

@@ -200,4 +204,4 @@ def details(self, my_task):
200204
event_value = my_task._get_internal_data('event_value')
201205
if event_value is not None and event_value['cycles'] != 0:
202206
event_value = event_value['next']
203-
return PendingBpmnEvent(self.name, self.__class__.__name__, event_value)
207+
return PendingBpmnEvent(self.name, self.__class__.__name__, event_value)

0 commit comments

Comments
 (0)