Service Board > Max for Developers > Max Groovy APIs > Shift Plan API > Shift Plan API Usage Example
Shift Plan API Usage Example
import com.servicemax.businesshours.ShiftManager
import com.servicemax.businesshours.HolidayManager

//Please find details of joda time API: http://www.joda.org/joda-time/apidocs/
import org.joda.time.DateTime
import org.joda.time.Duration

import com.servicemax.businesshours.*
import com.servicemax.core.*
import org.joda.time.*

//Create shift plan
MaxObject shiftPlan = Max.executeAsAdmin{
ShiftManager.createShiftPlan('This is my shift plan 2', new LocalDate(2017, 5, 1), 1, ShiftCycleUnit.WEEK, 'US/Pacific')
}

//Create shift
MaxObject shift = Max.executeAsAdmin{
ShiftManager.createShift(shiftPlan.io_uuid, 'This is my shift')
}

//Create shift segment
// could be found under Shift Segment Type object, shipped out of box, also user can define their own segment type.
UUID work = UUID.fromString('36643254-9579-45d2-b4e7-774170b2a744')
MaxObject shiftSegment = ShiftManager.createWeekShiftSegment(shift.io_uuid, 'This is my shift segment', ['week1'], ['monday'], new LocalTime(8*1000*60*60), Period.hours(9), work)


DateTimeZone US = DateTimeZone.forID('US/Pacific')

//Add API
DateTime start = new DateTime(2017, 6, 21, 10, 0, US)
Duration hour = new Duration(1000*60*60)
DateTime result = ShiftManager.add(start, hour)

//Diff API
DateTime start = new DateTime(2017, 7, 1, 10, 0, US)
DateTime end = new DateTime(2017, 7, 7, 18, 0, US)
Duration result = ShiftManager.diff(start, end)

//IsWithin API
DateTime target = new DateTime(2017, 7, 21, 10, 0, US)
boolean result = ShiftManager.isWithin(target)

//Gantt Shift API
import com.servicemax.dc.service.GanttEventService

def params = [:]
params.with {
resource = 'f5e41031-fde7-4278-a7b3-320b33ab99c1'
startDt = '2020-03-23T00:00:00.000Z'
endDt = '2020-03-24T00:00:00.000Z'
isDaily = false
}
def shiftInfo = Max.svmx_shift_information_manager(params)
// shiftInfo will be a string of shift information which contains list of shift segments with attributes: resourceId, startDate, endDate, type, isAvailable.
* 
The Shift Plan time zone affects the date and time defined in Shift Plan and Shift Segment records. When you call this Groovy API, unless you specify the time zone to be used to create start and end date and time values, the server default time zone is used. For holiday calendars, the time zone set in User Preferences is used. If no user-level time zone is defined, system-level settings are used by default.
For more information:
Was this helpful?