# Shifts Variables

**URL:** <https://forum.inductiveautomation.com/t/shifts-variables/74279>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [May 30, 2023, 7:46am UTC](https://forum.inductiveautomation.com/t/shifts-variables/74279 "2023-05-30T07:46:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aybars.Urut](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aybars.urut/32/32003_2.png) [@Aybars.Urut](https://forum.inductiveautomation.com/u/Aybars.Urut)\
**Post date:** [May 30, 2023, 7:46am UTC](https://forum.inductiveautomation.com/t/shifts-variables/74279/1 "2023-05-30T07:46:33Z")

</div>

Hello there,

I'm currently using v8.1.24 and I want to reach out exist next shift variables.

I'm getting the current shift variables with that script;

```auto
import system
import datetime
import java.util.Date
import java.util.Calendar	

def ScheduleActive(dtValue, schedule):
# Retur True if scheduler (scheduleName) is active at given time point (dtValue)
#	dtValue ...	time point that is checked (datetime)
#	schedule ...	schedule that is checked (BasicSchedule)

	cal = java.util.Calendar.getInstance()  
	cal.setTime(dtValue); 
#	schedule = system.user.getSchedule(scheduleName)
	
	if schedule.observeHolidays:
		holidays = system.user.getHolidays()
		for holiday in holidays:
			if system.date.midnight(holiday.getDate()) == system.date.midnight(dtValue):
				return {"Active":False, "startDate": None, "endDate": None} # today is a holiday
					
	timeline = schedule.getScheduleForDay(cal)
	midnight = system.date.midnight(dtValue)
	msTime = system.date.millisBetween(midnight, dtValue)

	if timeline != None:
		segment = timeline.getSegment(msTime, False, True)
		if segment != None:
			tzOffset = system.date.getTimezoneRawOffset()
			startDate = system.date.fromMillis(system.date.toMillis(midnight)+segment.getStart()) 
			endDate = system.date.fromMillis(system.date.toMillis(midnight)+segment.getEnd())
			return {"Active":True, "startDate": startDate, "endDate":endDate}
		else:
			return {"Active":False, "startDate": None, "endDate": None}
		
	else:
		return {"Active":False, "startDate": None, "endDate": None}

```

How can i get next 1 hour shift variables?

Does anybody have any idea about that?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 30, 2023, 8:08am UTC](https://forum.inductiveautomation.com/t/shifts-variables/74279/2 "2023-05-30T08:08:24Z")

</div>

I'm not sure what you're asking. How does it fit into that script ?

I can recommend a few things though:  
It's good that you're documenting your function, but I suggest doing it like this (or something like this) instead:

```python
def ScheduleActive(dtValue, schedule):
	"""
	Parameters:
		dtValue (datetime): time point that is checked
		schedule (BasicSchedule):	schedule that is checked
	Return:
		True if scheduler (scheduleName) is active at given time point (dtValue)
	"""

```

Also note that the documented return doesn't match the actual return of the function. Be very careful with that.

---

<div class="post-metadata">

**Author:** ![Aybars.Urut](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aybars.urut/32/32003_2.png) [@Aybars.Urut](https://forum.inductiveautomation.com/u/Aybars.Urut)\
**Post date:** [May 30, 2023, 8:15am UTC](https://forum.inductiveautomation.com/t/shifts-variables/74279/3 "2023-05-30T08:15:49Z")

</div>

Hi Pascal,

Thank you for your reply.

I basicly want to get next shift variables such as name, start time, end time.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 30, 2023, 8:29am UTC](https://forum.inductiveautomation.com/t/shifts-variables/74279/4 "2023-05-30T08:29:06Z")

</div>

Is there a built-in concept of shifts in ignition that I don't know about ?  
Or are you talking about the alarm schedules ?

---

<div class="post-metadata">

**Author:** ![Aybars.Urut](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aybars.urut/32/32003_2.png) [@Aybars.Urut](https://forum.inductiveautomation.com/u/Aybars.Urut)\
**Post date:** [May 30, 2023, 8:34am UTC](https://forum.inductiveautomation.com/t/shifts-variables/74279/5 "2023-05-30T08:34:15Z")

</div>

The component name is Schedule Management and it is belong to vision.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/1/b1275982d6ec8d6a3da0b5f2fc56fd407ba0b3e2.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/39ae093373c2b0746196c741c7767c292a7aa269.png)

In that example, currently I'm in the Tuesday 08:00 am - 04:05 pm shift which name is Ass\_1.

I want to get next scheduled shift variables with using script.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 30, 2023, 10:13am UTC](https://forum.inductiveautomation.com/t/shifts-variables/74279/6 "2023-05-30T10:13:07Z")

</div>

Judging from the methods used in your script, it looks like you've already found this documentation:  
[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.20/com/inductiveautomation/ignition/common/user/schedule/BasicScheduleModel.html](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.20/com/inductiveautomation/ignition/common/user/schedule/BasicScheduleModel.html)
