Mac OS 9
DateTimeUtils.h
Go to the documentation of this file.
1 
19 #ifndef __DATETIMEUTILS__
20 #define __DATETIMEUTILS__
21 
22 #ifndef __CONDITIONALMACROS__
23 #include <ConditionalMacros.h>
24 #endif
25 
26 #ifndef __MACTYPES__
27 #include <MacTypes.h>
28 #endif
29 
30 #if PRAGMA_ONCE
31 #pragma once
32 #endif
33 
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #endif
38 
39 #if PRAGMA_IMPORT
40 #pragma import on
41 #endif
42 
43 #if PRAGMA_STRUCT_ALIGN
44 #pragma options align = mac68k
45 #elif PRAGMA_STRUCT_PACKPUSH
46 #pragma pack(push, 2)
47 #elif PRAGMA_STRUCT_PACK
48 #pragma pack(2)
49 #endif
50 
81  typedef SInt16 ToggleResults;
82  enum
83  {
86  toggleOK = 1,
87  toggleBadField = 2,
88  toggleBadDelta = 3,
89  toggleBadChar = 4,
90  toggleUnknown = 5,
91  toggleBadNum = 6,
92  toggleOutOfRange = 7,
94  toggleErr4 = 8,
95  toggleErr5 = 9
96  };
97 
98  enum
99  {
104  29,
106  28,
109  maxDateField = 10
110  };
111 
112  enum
113  {
114  eraMask = 0x0001,
115  yearMask = 0x0002,
116  monthMask = 0x0004,
117  dayMask = 0x0008,
118  hourMask = 0x0010,
119  minuteMask = 0x0020,
120  secondMask = 0x0040,
121  dayOfWeekMask = 0x0080,
122  dayOfYearMask = 0x0100,
123  weekOfYearMask = 0x0200,
124  pmMask = 0x0400,
125  dateStdMask =
126  0x007F
127  };
128 
129  typedef SInt8 LongDateField;
130  enum
131  {
132  eraField = 0,
133  yearField = 1,
134  monthField = 2,
135  dayField = 3,
136  hourField = 4,
137  minuteField = 5,
138  secondField = 6,
139  dayOfWeekField = 7,
140  dayOfYearField = 8,
141  weekOfYearField = 9,
142  pmField = 10,
143  res1Field = 11,
144  res2Field = 12,
145  res3Field = 13
146  };
147 
148  typedef SInt8 DateForm;
149  enum
150  {
151  shortDate = 0,
152  longDate = 1,
153  abbrevDate = 2
154  };
155 
156  enum
157  {
159  fatalDateTime =
160  0x8000,
162  leftOverChars =
163  2,
164  sepNotIntlSep =
165  4,
167  8,
169  16,
170  tooManySeps =
171  32,
173  64,
174  tokenErr =
175  0x8100,
177  dateTimeNotFound = 0x8400,
178  dateTimeInvalid = 0x8800
179  };
180 
181  typedef short StringToDateStatus;
182  typedef StringToDateStatus String2DateStatus;
184  {
185  short hidden[256];
186  };
187  typedef struct DateCacheRecord DateCacheRecord;
188  typedef DateCacheRecord *DateCachePtr;
189  struct DateTimeRec
190  {
191  short year;
192  short month;
193  short day;
194  short hour;
195  short minute;
196  short second;
197  short dayOfWeek;
198  };
199  typedef struct DateTimeRec DateTimeRec;
200 
201  typedef SInt64 LongDateTime;
203  {
204  SInt64 c;
205  struct
206  {
207  UInt32 lHigh;
208  UInt32 lLow;
209  } hl;
210  };
211  typedef union LongDateCvt LongDateCvt;
221  {
222  short era;
223  short year;
224  short month;
225  short day;
226  short hour;
227  short minute;
228  short second;
229  short dayOfWeek;
230  short dayOfYear;
231  short weekOfYear;
232  short pm;
233  short res;
234  short res;
235  short res;
236  } ld;
238  typedef union LongDateRec LongDateRec;
239 
240  typedef SInt8 DateDelta;
241  struct TogglePB
242  {
243  long togFlags;
244  ResType amChars;
245  ResType pmChars;
246  long reserved[4];
247  };
248  typedef struct TogglePB TogglePB;
260  void
261  DateString(long dateTime, DateForm longFlag, Str255 result, Handle intlHandle);
262 
271  void
272  TimeString(long dateTime, Boolean wantSeconds, Str255 result, Handle intlHandle);
273 
282  void
283  LongDateString(const LongDateTime *dateTime, DateForm longFlag, Str255 result,
284  Handle intlHandle);
285 
294  void
295  LongTimeString(const LongDateTime *dateTime, Boolean wantSeconds, Str255 result,
296  Handle intlHandle);
297 
309  OSErr
311 
320  StringToDateStatus
321  StringToDate(Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed,
322  LongDateRec *dateTime);
323 
332  StringToDateStatus
333  StringToTime(Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed,
334  LongDateRec *dateTime);
335 
344  void
346 
355  void
357 
374  ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch,
375  const TogglePB *params);
376 
390  short
391  ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs);
392 
420 #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
421 #pragma parameter __D0 ReadDateTime(__A0)
422 #endif
423  OSErr
424  ReadDateTime(unsigned long *time);
425 
442  secs = Time;
443 It is recommended that you obtain the value using the GetDateTime trap
444 rather than using the low-memory variable however, as it is possible that
445 low-memory variables may change in the future.
446 You can convert the secs value to a more understandable value (i.e., a
447 DateTimeRec ) via Secs2Date .
448 The ReadDateTime function may return a slightly more accurate value
449 since it is possible for the Time variable to lose seconds when interrupts
450 get disabled for very long.
451 Since the base date for the "raw seconds" value is 1/1/1904 and since secs
452 is a 32-bit value, you won't be able to calculate with dates beyond February
453 6, 2040.
454 </pre>
455  * \copyright THINK Reference © 1991-1992 Symantec Corporation
456  * \non_carbon_cfm in InterfaceLib 7.1 and later
457  * \carbon_lib in CarbonLib 1.0 and later
458  * \mac_os_x in version 10.0 and later
459  */
460 #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
461 #pragma parameter GetDateTime(__A0)
462 #endif
463 void
464 GetDateTime(unsigned long *secs);
465 
492 #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
493 #pragma parameter __D0 SetDateTime(__D0)
494 #endif
495 OSErr
496 SetDateTime(unsigned long time);
497 
520 #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
521 #pragma parameter SetTime(__A0)
522 #endif
523 void
524 SetTime(const DateTimeRec *d);
525 
539 GetTime(&now);
540 printf("Today is %d/%d/%d\n", now.month, now.day, now.year);
541 printf("The first day of the rest of your life. . . ");
542 </ pre>
543  * \copyright THINK Reference © 1991 - 1992 Symantec Corporation
544  * \non_carbon_cfm in InterfaceLib 7.1 and
545  later
546  * \carbon_lib in CarbonLib 1.0 and
547  later
548  * \mac_os_x in version 10.0 and
549  later
550  * /
551 #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
552 #pragma parameter GetTime(__A0)
553 #endif
554  void
555  GetTime(DateTimeRec *d);
556 
565 void
566 DateToSeconds(const DateTimeRec *d, unsigned long *secs);
567 
576 #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
577 #pragma parameter SecondsToDate(__D0, __A0)
578 #endif
579  void
580  SecondsToDate(unsigned long secs, DateTimeRec *d);
581 
586 #if CALL_NOT_IN_CARBON
595  void
596  IUDateString(long dateTime, DateForm longFlag, Str255 result);
597 
628  IUTimeString(nowNum, TRUE, nowStr); /* exclude seconds */
629  DrawString("\pThe time is: ");
630  DrawString(nowStr);
631  </ pre>
632  * \copyright THINK Reference © 1991 - 1992 Symantec Corporation
633  * \non_carbon_cfm in InterfaceLib 7.1 and
634  later
635  * \carbon_lib not available * \mac_os_x not available *
636  /
637  void
638  IUTimeString(long dateTime, Boolean wantSeconds, Str255 result);
639 
648  void
649  IUDatePString(long dateTime, DateForm longFlag, Str255 result,
650  Handle intlHandle);
651 
682  long nowNum;
683  Str255 nowStr;
684  Intl0Hndl i0h; /* handle to an Intl0Rec */
685  i0h = (Intl0Hndl)IUGetIntl(0); /* get current settings */
686  (*i0h)->timeCycle = 0; /* 24-hr format */
687  (*i0h)->timeFmt |= secLeadingZ | minLeadingZ | hrLeadingZ;
688  </ pre>
689  * \copyright THINK Reference © 1991 - 1992 Symantec Corporation
690  * \non_carbon_cfm in InterfaceLib 7.1 and
691  later
692  * \carbon_lib not available * \mac_os_x not available *
693  /
694  void
695  IUTimePString(long dateTime, Boolean wantSeconds, Str255 result,
696  Handle intlHandle);
697 
706  void
707  IULDateString(LongDateTime *dateTime, DateForm longFlag, Str255 result,
708  Handle intlHandle);
709 
718  void
719  IULTimeString(LongDateTime *dateTime, Boolean wantSeconds, Str255 result,
720  Handle intlHandle);
721 
722 #endif /** CALL_NOT_IN_CARBON */
723 
724 #if CALL_NOT_IN_CARBON
725 #define DateString(dateTime, longFlag, result, intlHandle) \
726  IUDatePString(dateTime, longFlag, result, intlHandle)
727 #define TimeString(dateTime, wantSeconds, result, intlHandle) \
728  IUTimePString(dateTime, wantSeconds, result, intlHandle)
729 #define LongDateString(dateTime, longFlag, result, intlHandle) \
730  IULDateString(dateTime, longFlag, result, intlHandle)
731 #define LongTimeString(dateTime, wantSeconds, result, intlHandle) \
732  IULTimeString(dateTime, wantSeconds, result, intlHandle)
733 #endif /** CALL_NOT_IN_CARBON */
734 #if OLDROUTINENAMES
735 #define String2Date(textPtr, textLen, theCache, lengthUsed, dateTime) \
736  StringToDate(textPtr, textLen, theCache, lengthUsed, dateTime)
737 #define String2Time(textPtr, textLen, theCache, lengthUsed, dateTime) \
738  StringToTime(textPtr, textLen, theCache, lengthUsed, dateTime)
739 #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
740 #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
741 #define Date2Secs(d, secs) DateToSeconds(d, secs)
742 #define Secs2Date(secs, d) SecondsToDate(secs, d)
743 #endif /** OLDROUTINENAMES */
744 
745 #if CALL_NOT_IN_CARBON
754  void
755  iudatestring(long dateTime, DateForm longFlag, char *result);
756 
765  void
766  iudatepstring(long dateTime, DateForm longFlag, char *result,
767  Handle intlHandle);
768 
777  void
778  iutimestring(long dateTime, Boolean wantSeconds, char *result);
779 
788  void
789  iutimepstring(long dateTime, Boolean wantSeconds, char *result,
790  Handle intlHandle);
791 
800  void
801  iuldatestring(LongDateTime *dateTime, DateForm longFlag, char *result,
802  Handle intlHandle);
803 
812  void
813  iultimestring(LongDateTime *dateTime, Boolean wantSeconds, char *result,
814  Handle intlHandle);
815 
816 #endif /** CALL_NOT_IN_CARBON */
817 
818 #if PRAGMA_STRUCT_ALIGN
819 #pragma options align = reset
820 #elif PRAGMA_STRUCT_PACKPUSH
821 #pragma pack(pop)
822 #elif PRAGMA_STRUCT_PACK
823 #pragma pack()
824 #endif
825 
826 #ifdef PRAGMA_IMPORT_OFF
827 #pragma import off
828 #elif PRAGMA_IMPORT
829 #pragma import reset
830 #endif
831 
832 #ifdef __cplusplus
833 }
834 #endif
835 
836 #endif /** __DATETIMEUTILS__ */
837 * /*/*/ * /*/*/ * /*/*/
Set up for compiler independent conditionals.
SInt16 ToggleResults
Definition: DateTimeUtils.h:81
@ cantReadUtilities
Definition: DateTimeUtils.h:176
@ fatalDateTime
Definition: DateTimeUtils.h:159
@ leftOverChars
Definition: DateTimeUtils.h:162
@ extraneousStrings
Definition: DateTimeUtils.h:168
@ sepNotIntlSep
Definition: DateTimeUtils.h:164
@ tokenErr
Definition: DateTimeUtils.h:174
@ fieldOrderNotIntl
Definition: DateTimeUtils.h:166
@ sepNotConsistent
Definition: DateTimeUtils.h:172
@ tooManySeps
Definition: DateTimeUtils.h:170
@ longDateFound
Definition: DateTimeUtils.h:161
void LongSecondsToDate(const LongDateTime *lSecs, LongDateRec *lDate)
secs
Obtain "raw seconds" value of Time variable.
Definition: DateTimeUtils.h:442
@ toggleErr3
Definition: DateTimeUtils.h:93
@ toggleUndefined
Definition: DateTimeUtils.h:85
short ValidDate(const LongDateRec *vDate, long flags, LongDateTime *newSecs)
Check the validity of a long date record.
OSErr InitDateCache(DateCachePtr theCache)
StringToDateStatus StringToDate(Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed, LongDateRec *dateTime)
void LongDateToSeconds(const LongDateRec *lDate, LongDateTime *lSecs)
void LongTimeString(const LongDateTime *dateTime, Boolean wantSeconds, Str255 result, Handle intlHandle)
void TimeString(long dateTime, Boolean wantSeconds, Str255 result, Handle intlHandle)
StringToDateStatus StringToTime(Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed, LongDateRec *dateTime)
void LongDateString(const LongDateTime *dateTime, DateForm longFlag, Str255 result, Handle intlHandle)
ToggleResults ToggleDate(LongDateTime *lSecs, LongDateField field, DateDelta delta, short ch, const TogglePB *params)
Modify a LongDateTime parameter.
#define DateString(dateTime, longFlag, result, intlHandle)
Definition: DateTimeUtils.h:725
@ smallDateBit
Definition: DateTimeUtils.h:101
@ togCharZCycleBit
Definition: DateTimeUtils.h:103
@ togChar12HourBit
Definition: DateTimeUtils.h:102
@ genCdevRangeBit
Definition: DateTimeUtils.h:107
@ validDateFields
Definition: DateTimeUtils.h:108
@ togDelta12HourBit
Definition: DateTimeUtils.h:105
OSErr ReadDateTime(unsigned long *time)
Copy clock-chip time to Time variable.
Basic Macintosh data types.
unsigned char Boolean
Definition: MacTypes.h:318
@ date
Definition: ROMDefs.h:267
Definition: DateTimeUtils.h:184
Definition: DateTimeUtils.h:190
Definition: DateTimeUtils.h:242
ResType amChars
Definition: DateTimeUtils.h:244
ResType pmChars
Definition: DateTimeUtils.h:245
Definition: MacTypes.h:104
Definition: DateTimeUtils.h:203
Definition: DateTimeUtils.h:221