Important: The information in this document is obsolete and should not be used for new development.
ToggleDate
You can use theToggleDate
function to modify a date and time, by modifying one specific component of a date and time (day, hour, minute, seconds, day of week, and so on). For example, you can use theToggleDate
function to increase a date and time by one minute, decrease a date and time by one minute, or explicitly add or subtract a number of seconds to or from a date and time.
FUNCTION ToggleDate (VAR lSecs: LongDateTime; field: LongDateField; delta: DateDelta; ch: Integer; params: TogglePB) : ToggleResults;
lSecs
- The date-time information to modify, expressed as the number of seconds elapsed since midnight, January 1, 1904.
field
- The name of the field in the date-time record you want modify. Use one of the
LongDateField
enumeration constants for the value of this parameter.delta
- A signed byte specifying the action you want to perform on the value specified in the
field
parameter. Setdelta
to 1, to increase the value in the field by 1. Setdelta
to -1, to decrease the value of the field by 1. Setdelta
to 0. If you want to set the value of the field explicitly; pass the new value through thech
field, described next.ch
- If the value in the
delta
field is 0, the value of the field in the date-time record (specified by thefield
parameter) is set to the value in thech
parameter. If the value in thedelta
field is not equal to 0, the value in thech
parameter is ignored.params
- The settings of the toggle parameter block settings. Note that you are responsible for setting this field.
--> togFlags
LongInt The fields to be checked by the ValidDate
function.--> amChars ResType A.M. characters from 'itl0'
resource.--> pmChars ResType P.M. characters from 'itl0'
resource.--> reserved ARRAY [0...3] OF LongInt Reserved; set each element to 0. DESCRIPTION
TheToggleDate
function first converts the number of seconds, specified in thelSecs
parameter, to a date and time--making each component of the date and time (day, minute, seconds, day of week, and so on) available through a long date-time record. TheToggleDate
function then modifies the value of the field, specified by thefield
parameter. If the value in thedelta
field is greater than 0, the value of the field (specified in thefield
parameter) increases by 1; if the value in thedelta
field is less than 0, the value of the field decreases by 1; and if the value ofdelta
is 0, the value of the field is explicitly set to the value specified in thech
field.After the
ToggleDate
function modifies the field, it calls theValidDate
function. TheValidDate
function checks the long date-time record for correctness, using the values of thetogFlags
field in the toggle parameter block that theToggleDate
function passes to it. If any of the record fields are invalid, theValidDate
function returns aLongDateField
value corresponding to the field in error. Otherwise, it returns the result code forvalidDateFields
. Note thatValidDate
reports only the least significant erroneous field.After the
ToggleDate
function checks the validity of the modified field, it converts the modified date and time back into a number of seconds (the number of seconds elapsed since midnight, January 1, 1904) and returns these seconds in thelSecs
parameter.The following constants specify the
LongDateRec
fields for theValidDate
function to check:
CONST eraMask = $0001; {verify the era} yearMask = $0002; {verify the year} monthMask = $0004; {verify the month} dayMask = $0008; {verify the day} hourMask = $0010; {verify the hour} minuteMask = $0020; {verify the minute} secondMask = $0040; {verify the second} dateStdMask = $007F; {verify the era through second} dayOfWeekMask = $0080; {verify the day of the week} dayOfYearMask = $0100; {verify the day of the year} weekOfYearMask = $0200; {verify the week of the year} pmMask = $0400; {verify the evening (P.M.)}SPECIAL CONSIDERATIONS
AlthoughToggleDate
does not move or purge memory, you should not call it at interrupt time.RESULT CODES
TheToggleDate
function returns its own set of result codes. TheToggleResults
data type defines the result code of theToggleDate
function:
TYPE ToggleResults = Integer; {ToggleDate function return type}The following list gives the result codes defined for this function:
toggleUndefined 0 Undefined error toggleOK 1 No error toggleBadField 2 Invalid field number toggleBadDelta 3 Invalid delta value toggleBadChar 4 Invalid character toggleUnknown 5 Unknown error toggleBadNum 6 Tried to use character as number toggleOutOfRange 7 Out of range (synonym for toggleErr3
)toggleErr3 7 Reserved toggleErr4 8 Reserved toggleErr5 9 Reserved SEE ALSO
To learn more about theLongDateTime
data type, see page 4-25. For more information on theLongDateRec
structure, see page 4-26. The toggle parameter block record is described on page 4-30.For more information about the
GetIntlResource
function, see the chapter "Script Manager" in Inside Macintosh: Text. For details on theUppercaseText
procedure, see the chapter "Text Utilities" in Inside Macintosh: Text. TheValidDate
function is described next.