|
Mac OS 9
|
International Date and Time Interfaces (previously in TextUtils) More...
Go to the source code of this file.
Data Structures | |
| struct | DateCacheRecord |
| struct | DateTimeRec |
| union | LongDateCvt |
| union | LongDateRec |
| struct | TogglePB |
Macros | |
| #define | DateString(dateTime, longFlag, result, intlHandle) IUDatePString(dateTime, longFlag, result, intlHandle) |
| #define | TimeString(dateTime, wantSeconds, result, intlHandle) IUTimePString(dateTime, wantSeconds, result, intlHandle) |
| #define | LongDateString(dateTime, longFlag, result, intlHandle) IULDateString(dateTime, longFlag, result, intlHandle) |
| #define | LongTimeString(dateTime, wantSeconds, result, intlHandle) IULTimeString(dateTime, wantSeconds, result, intlHandle) |
Typedefs | |
| typedef SInt16 | ToggleResults |
| typedef SInt8 | LongDateField |
| typedef SInt8 | DateForm |
| typedef short | StringToDateStatus |
| typedef StringToDateStatus | String2DateStatus |
| typedef struct DateCacheRecord | DateCacheRecord |
| typedef DateCacheRecord * | DateCachePtr |
| typedef struct DateTimeRec | DateTimeRec |
| typedef SInt64 | LongDateTime |
| typedef union LongDateCvt | LongDateCvt |
| typedef union LongDateRec | LongDateRec |
| typedef SInt8 | DateDelta |
| typedef struct TogglePB | TogglePB |
Enumerations | |
| enum | { toggleUndefined = 0 , toggleOK = 1 , toggleBadField = 2 , toggleBadDelta = 3 , toggleBadChar = 4 , toggleUnknown = 5 , toggleBadNum = 6 , toggleOutOfRange = 7 , toggleErr3 = 7 , toggleErr4 = 8 , toggleErr5 = 9 } |
| enum | { smallDateBit = 31 , togChar12HourBit = 30 , togCharZCycleBit , togDelta12HourBit , genCdevRangeBit = 27 , validDateFields = -1 , maxDateField = 10 } |
| enum | { eraMask = 0x0001 , yearMask = 0x0002 , monthMask = 0x0004 , dayMask = 0x0008 , hourMask = 0x0010 , minuteMask = 0x0020 , secondMask = 0x0040 , dayOfWeekMask = 0x0080 , dayOfYearMask = 0x0100 , weekOfYearMask = 0x0200 , pmMask = 0x0400 , dateStdMask } |
| enum | { eraField = 0 , yearField = 1 , monthField = 2 , dayField = 3 , hourField = 4 , minuteField = 5 , secondField = 6 , dayOfWeekField = 7 , dayOfYearField = 8 , weekOfYearField = 9 , pmField = 10 , res1Field = 11 , res2Field = 12 , res3Field = 13 } |
| enum | { shortDate = 0 , longDate = 1 , abbrevDate = 2 } |
| enum | { fatalDateTime , longDateFound = 1 , leftOverChars , sepNotIntlSep , fieldOrderNotIntl , extraneousStrings , tooManySeps , sepNotConsistent , tokenErr , cantReadUtilities = 0x8200 , dateTimeNotFound = 0x8400 , dateTimeInvalid = 0x8800 } |
Functions | |
| void | DateString (long dateTime, DateForm longFlag, Str255 result, Handle intlHandle) |
| void | TimeString (long dateTime, Boolean wantSeconds, Str255 result, Handle intlHandle) |
| void | LongDateString (const LongDateTime *dateTime, DateForm longFlag, Str255 result, Handle intlHandle) |
| void | LongTimeString (const LongDateTime *dateTime, Boolean wantSeconds, Str255 result, Handle intlHandle) |
| OSErr | InitDateCache (DateCachePtr theCache) |
| StringToDateStatus | StringToDate (Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed, LongDateRec *dateTime) |
| StringToDateStatus | StringToTime (Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed, LongDateRec *dateTime) |
| void | LongDateToSeconds (const LongDateRec *lDate, LongDateTime *lSecs) |
| void | LongSecondsToDate (const LongDateTime *lSecs, LongDateRec *lDate) |
| ToggleResults | ToggleDate (LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params) |
| Modify a LongDateTime parameter. More... | |
| short | ValidDate (const LongDateRec *vDate, long flags, LongDateTime *newSecs) |
| Check the validity of a long date record. More... | |
| OSErr | ReadDateTime (unsigned long *time) |
| Copy clock-chip time to Time variable. More... | |
| OSErr | SetDateTime (unsigned long time) |
| Set system date and time in "raw" seconds. More... | |
| void | SetTime (const DateTimeRec *d) |
| Set system date/time, using DateTimeRec format. More... | |
| printf ("Today is %d/%d/%d\n", now.month, now.day, now.year) | |
| printf ("The first day of the rest of your life. . . ") | |
| void | DateToSeconds (const DateTimeRec *d, unsigned long *secs) |
| void | SecondsToDate (unsigned long secs, DateTimeRec *d) |
| void | IUDateString (long dateTime, DateForm longFlag, Str255 result) |
| IUTimeString (nowNum, TRUE, nowStr) | |
| Convert "raw" seconds into ASCII time string. More... | |
| DrawString ("\pThe time is: ") | |
| DrawString (nowStr) | |
| void | IUDatePString (long dateTime, DateForm longFlag, Str255 result, Handle intlHandle) |
| void | IULDateString (LongDateTime *dateTime, DateForm longFlag, Str255 result, Handle intlHandle) |
| void | IULTimeString (LongDateTime *dateTime, Boolean wantSeconds, Str255 result, Handle intlHandle) |
| void | iudatestring (long dateTime, DateForm longFlag, char *result) |
| void | iudatepstring (long dateTime, DateForm longFlag, char *result, Handle intlHandle) |
| void | iutimestring (long dateTime, Boolean wantSeconds, char *result) |
| void | iutimepstring (long dateTime, Boolean wantSeconds, char *result, Handle intlHandle) |
| void | iuldatestring (LongDateTime *dateTime, DateForm longFlag, char *result, Handle intlHandle) |
| void | iultimestring (LongDateTime *dateTime, Boolean wantSeconds, char *result, Handle intlHandle) |
Variables | |
| union LongDateRec | ld |
| secs = Time | |
| Obtain "raw seconds" value of Time variable. More... | |
| GetTime & | now |
| Get current date and time in DateTimeRec format. More... | |
| </pre > *par | Copyright |
| Check if a specified pixel is enclosed by a region. More... | |
| </pre > *par Boolean | wantSeconds |
| </pre > *par Boolean Str255 | result |
| long | nowNum |
| Convert "raw" seconds to time string (with parm) More... | |
| Str255 | nowStr |
| Intl0Hndl | i0h = (Intl0Hndl)IUGetIntl(0) |
| i0h | timeCycle = 0 |
| i0h | timeFmt = secLeadingZ | minLeadingZ | hrLeadingZ |
| </pre > *par Boolean Str255 Handle | intlHandle |
International Date and Time Interfaces (previously in TextUtils)
For bug reports, consult the following page on the World Wide Web:
http://developer.apple.com/bugreporter/
| #define DateString | ( | dateTime, | |
| longFlag, | |||
| result, | |||
| intlHandle | |||
| ) | IUDatePString(dateTime, longFlag, result, intlHandle) |
CALL_NOT_IN_CARBON
| typedef SInt16 ToggleResults |
Here are the current routine names and the translations to the older forms. Please use the newer forms in all new code and migrate the older names out of existing code as maintainance permits.
New Name Old Name(s)
DateString IUDatePString IUDateString InitDateCache LongDateString IULDateString LongTimeString IULTimeString StringToDate String2Date StringToTime TimeString IUTimeString IUTimePString LongDateToSeconds LongDate2Secs LongSecondsToDate LongSecs2Date DateToSeconds Date2Secs SecondsToDate Secs2Date
Carbon only supports the new names. The old names are undefined for Carbon targets. This is true for C, Assembly and Pascal.
InterfaceLib always has exported the old names. For C macros have been defined to allow the use of the new names. For Pascal and Assembly using the new names will result in link errors.
| anonymous enum |
| anonymous enum |
| void DateString | ( | long | dateTime, |
| DateForm | longFlag, | ||
| Str255 | result, | ||
| Handle | intlHandle | ||
| ) |
These routine are available in Carbon with their new name DateString()
| void DateToSeconds | ( | const DateTimeRec * | d, |
| unsigned long * | secs | ||
| ) |
| OSErr InitDateCache | ( | DateCachePtr | theCache | ) |
These routine are available in Carbon and InterfaceLib with their new name InitDateCache()
| void iudatepstring | ( | long | dateTime, |
| DateForm | longFlag, | ||
| char * | result, | ||
| Handle | intlHandle | ||
| ) |
| void IUDatePString | ( | long | dateTime, |
| DateForm | longFlag, | ||
| Str255 | result, | ||
| Handle | intlHandle | ||
| ) |
| void iudatestring | ( | long | dateTime, |
| DateForm | longFlag, | ||
| char * | result | ||
| ) |
CALL_NOT_IN_CARBON OLDROUTINENAMES iudatestring()
| void IUDateString | ( | long | dateTime, |
| DateForm | longFlag, | ||
| Str255 | result | ||
| ) |
These routine are available in InterfaceLib using their old name. Macros allow using the new names in all source code. IUDateString()
| void iuldatestring | ( | LongDateTime * | dateTime, |
| DateForm | longFlag, | ||
| char * | result, | ||
| Handle | intlHandle | ||
| ) |
| void IULDateString | ( | LongDateTime * | dateTime, |
| DateForm | longFlag, | ||
| Str255 | result, | ||
| Handle | intlHandle | ||
| ) |
| void iultimestring | ( | LongDateTime * | dateTime, |
| Boolean | wantSeconds, | ||
| char * | result, | ||
| Handle | intlHandle | ||
| ) |
| void IULTimeString | ( | LongDateTime * | dateTime, |
| Boolean | wantSeconds, | ||
| Str255 | result, | ||
| Handle | intlHandle | ||
| ) |
| void iutimepstring | ( | long | dateTime, |
| Boolean | wantSeconds, | ||
| char * | result, | ||
| Handle | intlHandle | ||
| ) |
| void iutimestring | ( | long | dateTime, |
| Boolean | wantSeconds, | ||
| char * | result | ||
| ) |
| IUTimeString | ( | nowNum | , |
| TRUE | , | ||
| nowStr | |||
| ) |
Convert "raw" seconds into ASCII time string.
IUTimeString converts a binary date/time value into a string of text identifying the corresponding time of day. International styles are taken into consideration for the output. rawSecs is a long integer; the number of seconds since Midnight, 1/1/1904. You can use any time value obtained from a file or catalog information block (see PBGetCatInfo ) or a value obtained via GetDateTime . wantSecs specifies whether to include the seconds (as well as the hour and minute) in the output. It is one of: FALSEDiscard seconds: 12:05 AM TRUEInclude seconds: 12:05:09 AM resultStr is the address of a buffer. Upon return, it will contain the text of the time as a pascal-style, length-prefixed string in the layout identified by 'INTL' resource 0.
none
Use IUDateString and IUTimeString to prepare date and time information for display. These functions rely on information from 'INTL' resources 0 and 1 in determining how to layout the text of the output string. A "programmer's" variation, IUTimePString provides a way to modify the output. For instance, you can force the output into 24-hr format or add leading zeros to the hour. Example #include < Packages.h > long nowNum; Str255 nowStr; GetDateTime ( &nowNum ); /* or today = Time
| void LongDateString | ( | const LongDateTime * | dateTime, |
| DateForm | longFlag, | ||
| Str255 | result, | ||
| Handle | intlHandle | ||
| ) |
| void LongDateToSeconds | ( | const LongDateRec * | lDate, |
| LongDateTime * | lSecs | ||
| ) |
| void LongSecondsToDate | ( | const LongDateTime * | lSecs, |
| LongDateRec * | lDate | ||
| ) |
| void LongTimeString | ( | const LongDateTime * | dateTime, |
| Boolean | wantSeconds, | ||
| Str255 | result, | ||
| Handle | intlHandle | ||
| ) |
| OSErr ReadDateTime | ( | unsigned long * | time | ) |
Copy clock-chip time to Time variable.
ReadDateTime accesses the clock chip directly and stores its return value into the low-memory variable Time (at 0x020C) and into the specified variable. Applications normally use GetDateTime or GetTime . secsis the address of a 4-byte variable. Upon return, it contains the number of seconds since January 1, 1904 (as tracked by the real-time clock hardware).
an OSErr; an integer Error Code . It will be one of: noErr(0) No error clkRdErr (-85) Clock read error
You can convert the secs value to a more easily understood value (i.e., a DateTimeRec ) via Secs2Date . You can set the clock-chip to a new time/date using SetDateTime ; though this is normally performed via the Control Panel DA. Since the base date for the any "raw seconds" value is 1/1/1904 and since secs is a 32-bit value, you won't be able to calculate with dates beyond February 6, 2040.
| void SecondsToDate | ( | unsigned long | secs, |
| DateTimeRec * | d | ||
| ) |
| OSErr SetDateTime | ( | unsigned long | time | ) |
Set system date and time in "raw" seconds.
SetDateTime sets the system data and time by writing a "raw" seconds value to both the low-memory variable Time and the real-time clock chip. It also verifies that the clock chip accepted the change without error. secsspecifies the desired time. It is a count of seconds since Midnight, January 1, 1904.
an OSErr; an integer Error Code . It will be one of: noErr(0) No error clkWrErr (-86) Clock write error clkRdErr (-85) Clock read error
The system time needs to be changed only rarely (e.g, on switching to Daylight Savings Time) and is normally set by the user via the Control Panel DA. The Date2Secs function can be used to convert a DateTimeRec into a "raw" seconds value. You could also use SetTime , which performs the conversion automatically.
| void SetTime | ( | const DateTimeRec * | d | ) |
Set system date/time, using DateTimeRec format.
SetTime sets the system date and time, using the fields of a DateTimeRec structure. The clock/calendar hardware and the global variable Time are updated. dtrpis the address of a 14-byte DateTimeRec structure. Its fields should contain the current year, month, day, etc.
none
SetTime converts dtrp to "raw" seconds and calls SetDateTime to store the converted value into the clock chip and the Time variable. The system time needs to be changed only rarely (e.g, on switching to or from daylight savings time) and is normally set by the user via the Control Panel DA.
| StringToDateStatus StringToDate | ( | Ptr | textPtr, |
| long | textLen, | ||
| DateCachePtr | theCache, | ||
| long * | lengthUsed, | ||
| LongDateRec * | dateTime | ||
| ) |
| StringToDateStatus StringToTime | ( | Ptr | textPtr, |
| long | textLen, | ||
| DateCachePtr | theCache, | ||
| long * | lengthUsed, | ||
| LongDateRec * | dateTime | ||
| ) |
| void TimeString | ( | long | dateTime, |
| Boolean | wantSeconds, | ||
| Str255 | result, | ||
| Handle | intlHandle | ||
| ) |
| ToggleResults ToggleDate | ( | LongDateTime * | lSecs, |
| LongDateField | field, | ||
| DateDelta | delta, | ||
| short | ch, | ||
| const TogglePB * | params | ||
| ) |
Modify a LongDateTime parameter.
The ToggleDate function modifies a LongDateTime parameter by toggling one of the corresponding fields of the long date record up or down or by setting it explicitly.For more information see, Macintosh Worldwide Development: Guide to System Software
a ToggleResults
| short ValidDate | ( | const LongDateRec * | vDate, |
| long | flags, | ||
| LongDateTime * | newSecs | ||
| ) |
Check the validity of a long date record.
The ValidDate function checks the validity of a long date record For more information see, Macintosh Worldwide Development: Guide to System Software.
a short
| </pre > *par Copyright |
Check if a specified pixel is enclosed by a region.
Perform RLL byte compression on arbitrary data.
PtInRgn returns an indication of whether or not a point (actually, the pixel below and to the right of a mathematical coordinate) is enclosed by the outline of a region. thePtis a Point, expressed in local or global coordinates. theRgnis the handle of a region, in the same coordinate system as thePt.
a Boolean value indicating whether the point is inside of the region. It is one of: FALSENot in the region TRUEIn the region
This is useful in determining if a mouse-down event has occurred while the cursor was positioned in the area of a region. Note that since the EventRecord .where field is expressed in global coordinates, so you may need to convert as follows: GetNextEvent ( everyEvent , &theEvent );: GlobalToLocal ( &theEvent.where ); if (PtInRgn ( theEvent.where, theRgn ) { ... /* yes, it was in that region From ToolUtils.iPackBits compresses up to 32,768 bytes of data by replacing sequences of 3 or more identical bytes with a 2-byte code. It is most often used to compress image data, as found in a BitMap or a PixMap. The worst case compression can be calculated using the formula: (srcLen + (srcLen + 126) / 127). srcPtris the address of a pointer to some data to be compressed. Upon return, the pointer has been adjusted to just beyond the data that has been compressed; i.e., ready for the next call. destPtris the address of a pointer to a buffer to hold the compressed data. Upon return, it has been adjusted to just beyond the end of the compressed data. srcLenis the size, in bytes, of the data to be compressed.
none
Since image data is often full of "white-space", this is ideal for packing data for long-term RAM storage and before writing it to disk or storing it in a resource. It is not quite so useful for compressing text or other data. Note the misnomer: PackBits does not pack bits; it packs sequences of bytes. PackBits was formerly limited to compressing data in 127 bytes blocks. To compress more than 127 bytes, a programmer would have to break the data up and make multiple calls to PackBits . Starting with System Software version 6.0.2, this restriction has been lifted. If you want your program to run on Systems prior to version 6.0.2, you must obey the 127-byte limit. Typical usage is to pack each line of a BitMap or PixMap separately, as in the example below. The example procedure, PackScreen, typically compresses a black and white screen image from 32K down to about 4K or 5K. Example #include < ToolUtils.h > PtrsavePtr; longmapSize, PackScreen( Ptr); mapSize = (long) screenBits .bounds.bottom * screenBits .rowBytes; savePtr = NewPtr ( mapSize + 1 ); /* allocate storage buffer
| GetTime& now |
Get current date and time in DateTimeRec format.
GetTime obtains the current date and time in the form a DateTimeRec structure. dtrpis the address of a 14-byte DateTimeRec structure. Upon return, its fields contain the current year, month, day, etc.
none
GetTime calls GetDateTime and converts its "raw" seconds value into corresponding DateTimeRec . For example: DateTimeRec now; /* create a 14-byte record
| long nowNum |
Convert "raw" seconds to time string (with parm)
IUTimePString converts a binary date/time value into a string of text describing the time of day, exactly as described in IUTimeString except that you can specify a custom data structure to override normal output formatting. rawSecs is a long integer; the number of seconds since Midnight, 1/1/1904. You can use any date/time value obtained from a catalog information block (see PBGetCatInfo ) or a value obtained via GetDateTime . wantSecs specifies whether to include the seconds (as well as the hour and minute) in the output. It is one of: FALSEDiscard seconds: 1:05 AM TRUEInclude seconds: 1:05:09 AM resultStr is the address of a buffer. Upon return, it will contain the text of the time as a pascal-style length-prefixed string in the layout identified by flags in 'INTL' resource 0. intlHndl is a Handle leading to either a 32-byte Intl0Rec structure. This is normally a handle obtained via IUGetIntl (0) with selected fields modified.
none
IUTimePString and IUDatePString provide flexibility in how to format the output of time and date strings. Normal usage is to call IUGetIntl (0), modify one or more fields of the Intl0Rec structure, and call IUTimePString , as in the example, below. Example #include < Packages.h > /* outputs time in 24-hr format with leading 0s in all fields; e.g.: 13:04:02
| secs = Time |
Obtain "raw seconds" value of Time variable.
GetDateTime obtains the "raw" seconds value, as known to the system. secsis the address of a 4-byte variable. Upon return, it contains the number of seconds since Midnight, January 1, 1904 (as read from the real-time clock hardware at startup and updated periodically by the Time Manager ).
none
GetDateTime simply copies the value of the low-memory variable Time (at 0x020C) and into the specified variable. Thus, the following are functionally equivalent: unsigned long secs; GetDateTime ( &secs); /* is the same as . . .