I wonder if there’s a better way to see if a user schedule is active inside a python script.
Currently I have this script to get a timeline from a schedule, and see if it’s active. It works but it’s not elegant (way too much date types used, and I have to go too deep in the Ignition classes).
Does someone have something more elegant?
import java.util.Date
import java.util.Calendar
import datetime
def isScheduleActive(scheduleName):
now = java.util.Date()
cal = java.util.Calendar.getInstance();
cal.setTime(now);
schedule = system.user.getSchedule("Example")
timeline = schedule.getScheduleForDay(cal)
dtNow = datetime.datetime.now()
midnight = dtNow.replace(hour=0, minute=0, second=0, microsecond=0)
msTime = (dtNow - midnight).seconds * 1000
return timeline.getSegment(msTime, False) != None