# Preventing calendar start overlapping end date etc

**URL:** <https://forum.inductiveautomation.com/t/preventing-calendar-start-overlapping-end-date-etc/6687>\
**Category:** Ignition\
**Created:** [June 11, 2013, 12:59pm UTC](https://forum.inductiveautomation.com/t/preventing-calendar-start-overlapping-end-date-etc/6687 "2013-06-11T12:59:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brett\_Yeomans](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Brett\_Yeomans](https://forum.inductiveautomation.com/u/Brett_Yeomans)\
**Post date:** [June 11, 2013, 12:59pm UTC](https://forum.inductiveautomation.com/t/preventing-calendar-start-overlapping-end-date-etc/6687/1 "2013-06-11T12:59:03Z")

</div>

Hi,  
Has anyone got a good foolproof method of stopping two calendar dates overlapping whilst displaying the selected dates? I can have some script display a message if the ‘start’ date is after the ‘end’ date etc and stop the selected date from getting to the ‘report’ start/end date but the calendar still displays the out-lawed date chosen rather than revert back to what was originally selected. If I use a message box to inform the user this has to be acknowledged twice and the script gets run again by the propertyChange ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

Don’t suppose there is a way of shading out the ‘out-lawed’ dates like web pages usualy do i.e. the return calendar stops you even seeing dates before the depart date?

---

<div class="post-metadata">

**Author:** ![Brett\_Yeomans](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Brett\_Yeomans](https://forum.inductiveautomation.com/u/Brett_Yeomans)\
**Post date:** [June 12, 2013, 8:24am UTC](https://forum.inductiveautomation.com/t/preventing-calendar-start-overlapping-end-date-etc/6687/2 "2013-06-12T08:24:03Z")

</div>

[code]if event.propertyName == “date”:  
from java.util import \*

```
start = event.source.parent.getComponent('startDate').date
end = event.source.date

startYear = system.db.dateFormat(start, "yyyy")
startMonth = system.db.dateFormat(start, "MM" )
startDay = system.db.dateFormat(start, "dd" )
startHour = system.db.dateFormat(start, "HH" )
startMinute = system.db.dateFormat(start, "mm")
startSeconds = system.db.dateFormat(start, "ss" )

calStart = Calendar.getInstance()
calStart.set(Calendar.YEAR, int(startYear))
calStart.set(Calendar.MONTH, int(startMonth)-1)
calStart.set(Calendar.DAY_OF_MONTH, int(startDay))
calStart.set(Calendar.HOUR_OF_DAY, int(startHour))
calStart.set(Calendar.MINUTE, int(startMinute))
calStart.set(Calendar.SECOND, int(startSeconds))
startTime=calStart.getTime()

endYear = system.db.dateFormat(end, "yyyy")
endMonth = system.db.dateFormat(end, "MM" )
endDay = system.db.dateFormat(end, "dd" )
endHour = system.db.dateFormat(end, "HH" )
endMinute = system.db.dateFormat(end, "mm")
endSeconds = system.db.dateFormat(end, "ss" )

calEnd = Calendar.getInstance()
calEnd.set(Calendar.YEAR, int(endYear))
calEnd.set(Calendar.MONTH, int(endMonth)-1)
calEnd.set(Calendar.DAY_OF_MONTH, int(endDay))
calEnd.set(Calendar.HOUR_OF_DAY, int(endHour))
calEnd.set(Calendar.MINUTE, int(endMinute))
calEnd.set(Calendar.SECOND, int(endSeconds))
endTime=calEnd.getTime()

now2 = Calendar.getInstance()
now = now2.getTime()
print "1"
if endTime.after(startTime) and endTime.before(now):
	event.source.parent.endDate = endTime
	event.source.test = 0
	print "2"
elif endTime.after(now):
	if event.source.test == 0:
		system.gui.messageBox("End Time Cannot Be After Now, Reselect Another End Date","End Date Error" )
		event.source.test = 1
		event.source.date = event.oldValue
		print "3"						
elif endTime.before(startTime):
	if event.source.test == 0:
		system.gui.messageBox("End Time Cannot Be Before Start Time, Reselect Another End Date","End Date Error" )
		event.source.date = event.oldValue
		event.source.test = 1
		event.source.date = event.oldValue
		print "4"[/code]

```

Put the above code in and when the end date is before now etc (good) the console shows:  
1,2  
When a put in an end date in the future (wrong) the console shows:  
1 waits with messageBox displayed, click OK  
1,2,3,1 waits with messageBox displayed, click OK  
1,2,3

![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:") My very limited knowledge of python says that an if elif routine breaks if one ‘if’ is true so how can I ever get 2 followed by a 3??? ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [July 12, 2013, 11:38pm UTC](https://forum.inductiveautomation.com/t/preventing-calendar-start-overlapping-end-date-etc/6687/3 "2013-07-12T23:38:58Z")

</div>

Yes, if and elif statements that are at the same tab level will be exclusive. getting a 2 and a 3 with this script should not be possible without another 1 in there. Are you sure both the 2 and 3 are coming from the same script? Can you change them to a,b,c and see if you get the same behavior?

---

<div class="post-metadata">

**Author:** ![Brett\_Yeomans](https://avatars.discourse-cdn.com/v4/letter/b/35a633/32.png) [@Brett\_Yeomans](https://forum.inductiveautomation.com/u/Brett_Yeomans)\
**Post date:** [June 17, 2014, 12:00pm UTC](https://forum.inductiveautomation.com/t/preventing-calendar-start-overlapping-end-date-etc/6687/4 "2014-06-17T12:00:10Z")

</div>

A solution was found that worked.
