I'm reading Martin Fowler's refactoring and will work out some of his methods (which also apply to building new software) in this blog. Read this to get some background info:
http://sourcemaking.com/refactoring/introduce-parameter-object
http://www.refactoring.com/catalog/introduceParameterObject.html
http://martinfowler.com/ap2/range.html
Below a simple daterangeparameter object, and therebelow a procedure using the daterange object.
CLASS dateRange FINAL:
DEFINE PRIVATE VARIABLE StartTime AS DATETIME NO-UNDO.
DEFINE PRIVATE VARIABLE EndTime AS DATETIME NO-UNDO.
CONSTRUCTOR dateRange (tStart AS DATETIME, tEnd AS DATETIME):
ASSIGN StartTime = tStart
EndTime = tEnd.
END CONSTRUCTOR.
METHOD PUBLIC DATETIME Start ():
RETURN StartTime.
END METHOD.
METHOD PUBLIC DATETIME End ():
RETURN EndTime.
END METHOD.
METHOD PUBLIC DATE dStart ():
RETURN DATE(StartTime).
END METHOD.
METHOD PUBLIC DATE dEnd ():
RETURN DATE(EndTime).
END METHOD.
METHOD PUBLIC INT64 Intv (intervalUnit AS CHARACTER):
RETURN INTERVAL(EndTime,StartTime,intervalUnit).
END METHOD.
METHOD PUBLIC LOGICAL EndAfterStart():
/* Endtime = ? is interpreted as 'far far in the future' */
RETURN IF EndTime > StartTime THEN TRUE
ELSE IF StartTime NE ? AND EndTime = ? THEN TRUE
ELSE ?.
END METHOD.
METHOD PUBLIC LOGICAL Includes(IncludedInRange AS DATETIME):
RETURN EndAfterStart() /* otherwise it's not a range */
AND (IncludedInRange > StartTime
AND (EndTime = ? OR IncludedInRange < EndTime)
).
END METHOD.
END CLASS.
/* a procedure using the daterange object: */
RUN a (NEW daterange(12/30/09,01/02/10)).
PROCEDURE a:
DEFINE INPUT PARAMETER dateRange AS CLASS dateRange NO-UNDO.
MESSAGE DATE(dateRange:Start()) daterange:endafterstart() daterange:intv('hours') daterange:includes(11/30/09)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END PROCEDURE.