CFLib.org – Common Function Library Project

GetShift(Date, StartDate, Sequence)

Last updated December 17, 2002

author

Rob Rusher

Version: 2 | Requires: CF5 | Library: DateLib

Description:
Returns the work shift for a sequence based work schedule. Mostly used by public organizations such as fire and police depts.

Return Values:
Returns a string.

Example:

<cfoutput>
Today's shift: #GetShift(Now(), "12/31/2001", "B,A,C,A,C,B,C,B,A", 9)#
</cfoutput>

Parameters:

Name Description Required
Date Date to return the shift for. Yes
StartDate Start date of the sequence. Yes
Sequence Comma delimited list defining the shift sequence. Yes

Full UDF Source:

/**
 * Returns the work shift for a sequence based work schedule.
 * v2 by Raymond Camden
 * 
 * @param Date 	 Date to return the shift for. (Required)
 * @param StartDate 	 Start date of the sequence. (Required)
 * @param Sequence 	 Comma delimited list defining the shift sequence. (Required)
 * @return Returns a string. 
 * @author Rob Rusher (rob@robrusher.com) 
 * @version 2, December 17, 2002 
 */
function GetShift(date, startDate, sequence) {
  var daysDiff = DateDiff("d",startDate,date);
  var key = daysDiff mod listLen(sequence) + 1;
  return listGetAt(sequence,key);
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson