This is MODateFormCell.rtf in view mode; [Download] [Up]
Version 1.0 Copyright ©1992, 1993, 1994 by Mike Ferris. All Rights Reserved. Mike Ferris - October 3rd, 1993 MODateFormCell Inherits From: MORegexFormCell : FormCell : ActionCell : Cell : Object Declared In: MOKit/MODateFormCell.h Class Description MODateFormCell is a subclass of MORegexFormCell which is tuned to validate dates. Because of leap-year calculation and other considerations, dates cannot be validated with only regular expressions. This subclass uses a set of pre-packaged regular expressions to check the format as far as possible, then the more sophisticated checking is carried out by the class itself. The cell can be configured to use American or European date conventions (American means month, day, year ordering; European means day, month, year ordering). Setting this option changes the set of pre-packaged regular expressions to use. The class also provides an extra bonus made possible by the fact that only a single data-type is recognized. MODateFormCells can be set to reformat their input into a user-customizable format. The format is given like a printf format string, but with different % codes. (%d means day number, %D means day number padded to two digits, %m means month number, %M means month number padded to two digits, %n means a three character month name abbreviation, %N means the full name of the month, %y means two digit year, %Y means four digit year.) Any date entered into the field will be transformed to the specified format when the user tabs out of the cell. Valid dates set through the setStringValue method and its kin are also transformed. When specifying a format string, it is important to make sure that the resulting format will be a valid date. For instance, a format string of %m/%d/%Y (which will transform "January 23, 1993" into "1/23/1993") makes good sense for American dates, but not for European dates. Similarly a format of "The date is: %N the %dth, %Y" (which would transform "1/23/93" into "The date is: January the 23th, 1993") is not good because the resulting string is not a valid date. Note: Nothing really bad is going to happen if you specify a format that does not form a valid date. The transformation will happen, but the MODateFormCell methods -day, -month, and -year depend on a valid date being in the field. So do the inherited methods for dealing with subexpressions. So if you transform all entries to invalid date formats, these methods will not be able to work. Instance Variables BOOL isEuropeanDate; BOOL doesFormat; id formatString; isEuropeanDate Indicates whether the cell will use the American format regular expressions or the American ones when validating dates. doesFormat Indicates whether the cell should reformat entered dates according to the formatString. formatString A MOString containing the format string to use to transform entered dates if doesFormat is YES. Method Types Initializing the class +initialize Creating and freeing instances - initTextCell: withRegex: - copyFromZone: - free Validating - isEntryAcceptable: Setting the cell's value - setDoubleValue: - setFloatValue: - setIntValue: - setStringValue: - setStringValueNoCopy: - setStringValueNoCopy: shouldFree: Date Style - isEuropeanStyle - setEuropeanStyle: Reformatting Dates - doesFormatDates - setFormatDates: - formatString - setFormatString: - formatDate - endEditing: Getting at the pieces - day - month - year Archiving - read: - write: Class Methods initialize + initialize Initializes the class instance doing things like setting the version number. Instance Methods copyFromZone: - copyFromZone:(NXZone *)zone Makes a copy of the cell. This method needs to make a copy of the formatString. See also: ±€initTextCell: withRegex:, ±€free day - (int)day If a valid date is in the cell, this method returns the day number of that date. If there is not a valid date in the cell, this method returns -1. See also: ± month, ±€year doesFormatDates - (BOOL)doesFormatDates Returns YES if the cell will reformat entered dates according to the format string. See also: ± setFormatDates:, ±€formatString, ±€setFormatString: endEditing - endEditing:textObject Calls the superclass's implementation, then reformats the date if necessary. See also: ±€formatDate formatDate - formatDate If the cell is set to reformat entered dates and there is a valid date in the cell, Reformats the cell's contents according to the format string. See also: ±€endEditing: formatString - (const char *)formatString Returns a pointer to the format string. This is a pointer to the cell's actual copy, so don't mess with it. See also: ±€doesFormatDates, ± setFormatDates:, ±€setFormatString: free - free Frees the memory we may have allocated for various things. See also: ± initTextCell: withRegex:, ±€copyFromZone: initTextCell: withRegex: - initTextCell:(const char *)aString withRegex:(const char *)re Initializes the cell for American style dates and no reformatting. Ignores the re argument. See also: ± free, ±€copyFromZone: isEntryAcceptable - (BOOL)isEntryAcceptable:(const char *)aString Returns YES if aString is a valid date. NO otherwise. This method (as a side affect of checking the date) sets things up to let the -day, -month, and -year methods to work properly. See also: ±€matchedPatternIndex, ±pieceCount, ±pieceAt: isEuropeanStyle - (BOOL)isEuropeanStyle Returns YES if the cell is set to recognize European dates, NO if it is set for American dates. See also: ±€setEuropeanStyle: month - (int)month If a valid date is in the cell, this method returns the month number of that date. If there is not a valid date in the cell, this method returns -1. See also: ± day, ±€year read - read:(NXTypedStream *)strm Reads the object from the typed stream. Overriden to read in the cell's settings. See also: ±€awake, ±€write: setDoubleValue: - setDoubleValue:(double)aDouble Overrides the standard method to perform formatting on the new value. The formatting only occurs if the value being set is a valid date. Note that it is unlikely that a floating point value will be a valid date. See also: ±€setFloatValue:, ±€setIntValue:, ±€setStringValue:, ±€setStringValueNoCopy:, ±€setStringValueNoCopy: shouldFree: setEuropeanStyle - setEuropeanStyle:(BOOL)flag If flag is YES, sets the cell to recognize European style dates. If NO, sets the cell to recognize American style dates. See also: ±€isEuropeanStyle: setFloatValue: - setFloatValue:(float)aFloat Overrides the standard method to perform formatting on the new value. The formatting only occurs if the value being set is a valid date. Note that it is unlikely that a floating point value will be a valid date. See also: ±€setDoubleValue:, ±€setIntValue:, ±€setStringValue:, ±€setStringValueNoCopy:, ±€setStringValueNoCopy: shouldFree: setFormatDates - setFormatDates:(BOOL)flag Sets whether the cell will reformat entered dates. See also: ±€doesFormatDates, ± formatString, ±€setFormatString: setFormatString - setFormatString:(const char *)str Sets the format string to use to reformat entered dates if doesFormat is true. The string is interpretted similarly to printf format strings. All characters in the format string are copied literally into the reformatted date except the following 2 character codes: %d is replaced by the day number %D is replaced by the day number padded to two digits %m is replaced by the month number %M is replaced by the month number padded to two digits %n is replaced by the abbreviated month name (ie "Jan") %N is replaced by the full month name (ie "January") %y is replaced by a two-digit year number (ie "93") %Y is replaced by a four-digit year number padded to two digits (ie "1993") %% is replaced by a single "%" See the class introduction for some caveats on choosing a date format. See also: ±€doesFormatDates, ±€setFormatDates:, ± formatString setIntValue: - setIntValue:(int)anInt Overrides the standard method to perform formatting on the new value. The formatting only occurs if the value being set is a valid date. Note that it is unlikely, but possible, that an integer value will be a valid date. See also: ±€setDoubleValue:, ±€setFloatValue:, ±€setStringValue:, ±€setStringValueNoCopy:, ±€setStringValueNoCopy: shouldFree: setStringValue: - setStringValue:(const char *)aString Overrides the standard method to perform formatting on the new value. The formatting only occurs if the value being set is a valid date. See also: ±€setDoubleValue:, ±€setFloatValue:, ±€setIntValue:, ±€setStringValueNoCopy:, ±€setStringValueNoCopy: shouldFree: setStringValueNoCopy: - setStringValueNoCopy:(char *)aString Overrides the standard method to perform formatting on the new value. The formatting only occurs if the value being set is a valid date. See also: ±€setDoubleValue:, ±€setFloatValue:, ±€setIntValue:, ±€setStringValue:, ±€setStringValueNoCopy: shouldFree: setStringValueNoCopy: shouldFree: - setStringValueNoCopy:(char *)aString shouldFree:(BOOL)flag Overrides the standard method to perform formatting on the new value. The formatting only occurs if the value being set is a valid date. See also: ±€setDoubleValue:, ±€setFloatValue:, ±€setIntValue:, ±€setStringValue:, ±€setStringValueNoCopy: write - write:(NXTypedStream *)strm Writes the object to the typed stream. Overriden to write the cell's patterns and other settings. See also: ±€read:, ±€awake year - (int)year If a valid date is in the cell, this method returns the (full) year number of that date. If there is not a valid date in the cell, this method returns -1. See also: ± day, ± month
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.