DateTimeUtils.h
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:21k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2.      File:       DateTimeUtils.h
  3.  
  4.      Contains:   International Date and Time Interfaces (previously in TextUtils)
  5.  
  6.      Version:    Technology: Mac OS 8.5
  7.                  Release:    QuickTime 6.0.2
  8.  
  9.      Copyright:  (c) 1994-2001 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:      For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __DATETIMEUTILS__
  18. #define __DATETIMEUTILS__
  19. #ifndef __CONDITIONALMACROS__
  20. #include "ConditionalMacros.h"
  21. #endif
  22. #ifndef __MACTYPES__
  23. #include "MacTypes.h"
  24. #endif
  25. #if PRAGMA_ONCE
  26. #pragma once
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #if PRAGMA_IMPORT
  32. #pragma import on
  33. #endif
  34. #if PRAGMA_STRUCT_ALIGN
  35.     #pragma options align=mac68k
  36. #elif PRAGMA_STRUCT_PACKPUSH
  37.     #pragma pack(push, 2)
  38. #elif PRAGMA_STRUCT_PACK
  39.     #pragma pack(2)
  40. #endif
  41. /*
  42.     Here are the current routine names and the translations to the older forms.
  43.     Please use the newer forms in all new code and migrate the older names out of existing
  44.     code as maintainance permits.
  45.     
  46.     New Name                    Old Name(s)
  47.     
  48.     DateString                  IUDatePString IUDateString 
  49.     InitDateCache
  50.     LongDateString              IULDateString
  51.     LongTimeString              IULTimeString
  52.     StringToDate                String2Date
  53.     StringToTime                                
  54.     TimeString                  IUTimeString IUTimePString
  55.     LongDateToSeconds           LongDate2Secs
  56.     LongSecondsToDate           LongSecs2Date
  57.     DateToSeconds               Date2Secs
  58.     SecondsToDate               Secs2Date
  59.     Carbon only supports the new names.  The old names are undefined for Carbon targets.
  60.     This is true for C, Assembly and Pascal.
  61.     
  62.     InterfaceLib always has exported the old names.  For C macros have been defined to allow
  63.     the use of the new names.  For Pascal and Assembly using the new names will result
  64.     in link errors. 
  65.     
  66. */
  67. typedef SInt16 ToggleResults;
  68. enum {
  69.                                                                 /* Toggle results */
  70.     toggleUndefined             = 0,
  71.     toggleOK                    = 1,
  72.     toggleBadField              = 2,
  73.     toggleBadDelta              = 3,
  74.     toggleBadChar               = 4,
  75.     toggleUnknown               = 5,
  76.     toggleBadNum                = 6,
  77.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  78.     toggleErr3                  = 7,
  79.     toggleErr4                  = 8,
  80.     toggleErr5                  = 9
  81. };
  82. enum {
  83.                                                                 /* Date equates */
  84.     smallDateBit                = 31,                           /*Restrict valid date/time to range of Time global*/
  85.     togChar12HourBit            = 30,                           /*If toggling hour by char, accept hours 1..12 only*/
  86.     togCharZCycleBit            = 29,                           /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  87.     togDelta12HourBit           = 28,                           /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  88.     genCdevRangeBit             = 27,                           /*Restrict date/time to range used by genl CDEV*/
  89.     validDateFields             = -1,
  90.     maxDateField                = 10
  91. };
  92. enum {
  93.     eraMask                     = 0x0001,
  94.     yearMask                    = 0x0002,
  95.     monthMask                   = 0x0004,
  96.     dayMask                     = 0x0008,
  97.     hourMask                    = 0x0010,
  98.     minuteMask                  = 0x0020,
  99.     secondMask                  = 0x0040,
  100.     dayOfWeekMask               = 0x0080,
  101.     dayOfYearMask               = 0x0100,
  102.     weekOfYearMask              = 0x0200,
  103.     pmMask                      = 0x0400,
  104.     dateStdMask                 = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  105. };
  106. typedef SInt8 LongDateField;
  107. enum {
  108.     eraField                    = 0,
  109.     yearField                   = 1,
  110.     monthField                  = 2,
  111.     dayField                    = 3,
  112.     hourField                   = 4,
  113.     minuteField                 = 5,
  114.     secondField                 = 6,
  115.     dayOfWeekField              = 7,
  116.     dayOfYearField              = 8,
  117.     weekOfYearField             = 9,
  118.     pmField                     = 10,
  119.     res1Field                   = 11,
  120.     res2Field                   = 12,
  121.     res3Field                   = 13
  122. };
  123. typedef SInt8 DateForm;
  124. enum {
  125.     shortDate                   = 0,
  126.     longDate                    = 1,
  127.     abbrevDate                  = 2
  128. };
  129. enum {
  130.                                                                 /* StringToDate status values */
  131.     fatalDateTime               = 0x8000,                       /* StringToDate and String2Time mask to a fatal error */
  132.     longDateFound               = 1,                            /* StringToDate mask to long date found */
  133.     leftOverChars               = 2,                            /* StringToDate & Time mask to warn of left over characters */
  134.     sepNotIntlSep               = 4,                            /* StringToDate & Time mask to warn of non-standard separators */
  135.     fieldOrderNotIntl           = 8,                            /* StringToDate & Time mask to warn of non-standard field order */
  136.     extraneousStrings           = 16,                           /* StringToDate & Time mask to warn of unparsable strings in text */
  137.     tooManySeps                 = 32,                           /* StringToDate & Time mask to warn of too many separators */
  138.     sepNotConsistent            = 64,                           /* StringToDate & Time mask to warn of inconsistent separators */
  139.     tokenErr                    = 0x8100,                       /* StringToDate & Time mask for 'tokenizer err encountered' */
  140.     cantReadUtilities           = 0x8200,
  141.     dateTimeNotFound            = 0x8400,
  142.     dateTimeInvalid             = 0x8800
  143. };
  144. typedef short                           StringToDateStatus;
  145. typedef StringToDateStatus              String2DateStatus;
  146. struct DateCacheRecord {
  147.     short                           hidden[256];                /* only for temporary use */
  148. };
  149. typedef struct DateCacheRecord          DateCacheRecord;
  150. typedef DateCacheRecord *               DateCachePtr;
  151. struct DateTimeRec {
  152.     short                           year;
  153.     short                           month;
  154.     short                           day;
  155.     short                           hour;
  156.     short                           minute;
  157.     short                           second;
  158.     short                           dayOfWeek;
  159. };
  160. typedef struct DateTimeRec              DateTimeRec;
  161. typedef SInt64                          LongDateTime;
  162. union LongDateCvt {
  163.     SInt64                          c;
  164.     struct {
  165.         UInt32                          lHigh;
  166.         UInt32                          lLow;
  167.     }                                 hl;
  168. };
  169. typedef union LongDateCvt               LongDateCvt;
  170. union LongDateRec {
  171.     struct {
  172.         short                           era;
  173.         short                           year;
  174.         short                           month;
  175.         short                           day;
  176.         short                           hour;
  177.         short                           minute;
  178.         short                           second;
  179.         short                           dayOfWeek;
  180.         short                           dayOfYear;
  181.         short                           weekOfYear;
  182.         short                           pm;
  183.         short                           res1;
  184.         short                           res2;
  185.         short                           res3;
  186.     }                                 ld;
  187.     short                           list[14];                   /*Index by LongDateField!*/
  188.     struct {
  189.         short                           eraAlt;
  190.         DateTimeRec                     oldDate;
  191.     }                                 od;
  192. };
  193. typedef union LongDateRec               LongDateRec;
  194. typedef SInt8                           DateDelta;
  195. struct TogglePB {
  196.     long                            togFlags;                   /*caller normally sets low word to dateStdMask=$7F*/
  197.     ResType                         amChars;                    /*from 'itl0', but uppercased*/
  198.     ResType                         pmChars;                    /*from 'itl0', but uppercased*/
  199.     long                            reserved[4];
  200. };
  201. typedef struct TogglePB                 TogglePB;
  202. /*
  203.     These routine are available in Carbon with their new name
  204. */
  205. EXTERN_API( void )
  206. DateString                      (long                   dateTime,
  207.                                  DateForm               longFlag,
  208.                                  Str255                 result,
  209.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  210. EXTERN_API( void )
  211. TimeString                      (long                   dateTime,
  212.                                  Boolean                wantSeconds,
  213.                                  Str255                 result,
  214.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  215. EXTERN_API( void )
  216. LongDateString                  (LongDateTime *         dateTime,
  217.                                  DateForm               longFlag,
  218.                                  Str255                 result,
  219.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  220. EXTERN_API( void )
  221. LongTimeString                  (LongDateTime *         dateTime,
  222.                                  Boolean                wantSeconds,
  223.                                  Str255                 result,
  224.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  225. /*
  226.     These routine are available in Carbon and InterfaceLib with their new name
  227. */
  228. EXTERN_API( OSErr )
  229. InitDateCache                   (DateCachePtr           theCache)                           FOURWORDINLINE(0x2F3C, 0x8204, 0xFFF8, 0xA8B5);
  230. EXTERN_API( StringToDateStatus )
  231. StringToDate                    (Ptr                    textPtr,
  232.                                  long                   textLen,
  233.                                  DateCachePtr           theCache,
  234.                                  long *                 lengthUsed,
  235.                                  LongDateRec *          dateTime)                           FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF6, 0xA8B5);
  236. EXTERN_API( StringToDateStatus )
  237. StringToTime                    (Ptr                    textPtr,
  238.                                  long                   textLen,
  239.                                  DateCachePtr           theCache,
  240.                                  long *                 lengthUsed,
  241.                                  LongDateRec *          dateTime)                           FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF4, 0xA8B5);
  242. EXTERN_API( void )
  243. LongDateToSeconds               (const LongDateRec *    lDate,
  244.                                  LongDateTime *         lSecs)                              FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  245. EXTERN_API( void )
  246. LongSecondsToDate               (const LongDateTime *   lSecs,
  247.                                  LongDateRec *          lDate)                              FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  248. EXTERN_API( ToggleResults )
  249. ToggleDate                      (LongDateTime *         lSecs,
  250.                                  LongDateField          field,
  251.                                  DateDelta              delta,
  252.                                  short                  ch,
  253.                                  const TogglePB *       params)                             FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  254. EXTERN_API( short )
  255. ValidDate                       (const LongDateRec *    vDate,
  256.                                  long                   flags,
  257.                                  LongDateTime *         newSecs)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  258.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  259.                                                                                             #pragma parameter __D0 ReadDateTime(__A0)
  260.                                                                                             #endif
  261. EXTERN_API( OSErr )
  262. ReadDateTime                    (unsigned long *        time)                               ONEWORDINLINE(0xA039);
  263.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  264.                                                                                             #pragma parameter GetDateTime(__A0)
  265.                                                                                             #endif
  266. EXTERN_API( void )
  267. GetDateTime                     (unsigned long *        secs)                               TWOWORDINLINE(0x20B8, 0x020C);
  268.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  269.                                                                                             #pragma parameter __D0 SetDateTime(__D0)
  270.                                                                                             #endif
  271. EXTERN_API( OSErr )
  272. SetDateTime                     (unsigned long          time)                               ONEWORDINLINE(0xA03A);
  273.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  274.                                                                                             #pragma parameter SetTime(__A0)
  275.                                                                                             #endif
  276. EXTERN_API( void )
  277. SetTime                         (const DateTimeRec *    d)                                  TWOWORDINLINE(0xA9C7, 0xA03A);
  278.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  279.                                                                                             #pragma parameter GetTime(__A0)
  280.                                                                                             #endif
  281. EXTERN_API( void )
  282. GetTime                         (DateTimeRec *          d)                                  THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  283. EXTERN_API( void )
  284. DateToSeconds                   (const DateTimeRec *    d,
  285.                                  unsigned long *        secs);
  286.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  287.                                                                                             #pragma parameter SecondsToDate(__D0, __A0)
  288.                                                                                             #endif
  289. EXTERN_API( void )
  290. SecondsToDate                   (unsigned long          secs,
  291.                                  DateTimeRec *          d)                                  ONEWORDINLINE(0xA9C6);
  292. /*
  293.     These routine are available in InterfaceLib using their old name.
  294.     Macros allow using the new names in all source code.
  295. */
  296. #if CALL_NOT_IN_CARBON
  297. EXTERN_API( void )
  298. IUDateString                    (long                   dateTime,
  299.                                  DateForm               longFlag,
  300.                                  Str255                 result)                             TWOWORDINLINE(0x4267, 0xA9ED);
  301. EXTERN_API( void )
  302. IUTimeString                    (long                   dateTime,
  303.                                  Boolean                wantSeconds,
  304.                                  Str255                 result)                             THREEWORDINLINE(0x3F3C, 0x0002, 0xA9ED);
  305. EXTERN_API( void )
  306. IUDatePString                   (long                   dateTime,
  307.                                  DateForm               longFlag,
  308.                                  Str255                 result,
  309.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  310. EXTERN_API( void )
  311. IUTimePString                   (long                   dateTime,
  312.                                  Boolean                wantSeconds,
  313.                                  Str255                 result,
  314.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  315. EXTERN_API( void )
  316. IULDateString                   (LongDateTime *         dateTime,
  317.                                  DateForm               longFlag,
  318.                                  Str255                 result,
  319.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  320. EXTERN_API( void )
  321. IULTimeString                   (LongDateTime *         dateTime,
  322.                                  Boolean                wantSeconds,
  323.                                  Str255                 result,
  324.                                  Handle                 intlHandle)                         THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  325. #endif  /* CALL_NOT_IN_CARBON */
  326. #if CALL_NOT_IN_CARBON
  327. #define DateString(dateTime, longFlag, result, intlHandle) 
  328.          IUDatePString( dateTime, longFlag, result, intlHandle)
  329. #define TimeString(dateTime, wantSeconds, result, intlHandle) 
  330.          IUTimePString(dateTime, wantSeconds, result, intlHandle)
  331. #define LongDateString(dateTime, longFlag, result, intlHandle) 
  332.          IULDateString(dateTime, longFlag, result, intlHandle)
  333. #define LongTimeString(dateTime, wantSeconds, result, intlHandle) 
  334.          IULTimeString(dateTime, wantSeconds, result, intlHandle)
  335. #endif /* CALL_NOT_IN_CARBON */
  336. #if OLDROUTINENAMES
  337. #define String2Date(textPtr, textLen, theCache, lengthUsed, dateTime)  
  338.          StringToDate(textPtr, textLen, theCache, lengthUsed, dateTime)
  339. #define String2Time(textPtr, textLen, theCache, lengthUsed, dateTime)  
  340.          StringToTime(textPtr, textLen, theCache, lengthUsed, dateTime)
  341. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  342. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  343. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  344. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  345. #endif  /* OLDROUTINENAMES */
  346. #if CALL_NOT_IN_CARBON
  347. EXTERN_API_C( void )
  348. iudatestring                    (long                   dateTime,
  349.                                  DateForm               longFlag,
  350.                                  char *                 result);
  351. EXTERN_API_C( void )
  352. iudatepstring                   (long                   dateTime,
  353.                                  DateForm               longFlag,
  354.                                  char *                 result,
  355.                                  Handle                 intlHandle);
  356. EXTERN_API_C( void )
  357. iutimestring                    (long                   dateTime,
  358.                                  Boolean                wantSeconds,
  359.                                  char *                 result);
  360. EXTERN_API_C( void )
  361. iutimepstring                   (long                   dateTime,
  362.                                  Boolean                wantSeconds,
  363.                                  char *                 result,
  364.                                  Handle                 intlHandle);
  365. EXTERN_API_C( void )
  366. iuldatestring                   (LongDateTime *         dateTime,
  367.                                  DateForm               longFlag,
  368.                                  char *                 result,
  369.                                  Handle                 intlHandle);
  370. EXTERN_API_C( void )
  371. iultimestring                   (LongDateTime *         dateTime,
  372.                                  Boolean                wantSeconds,
  373.                                  char *                 result,
  374.                                  Handle                 intlHandle);
  375. #endif  /* CALL_NOT_IN_CARBON */
  376. #if PRAGMA_STRUCT_ALIGN
  377.     #pragma options align=reset
  378. #elif PRAGMA_STRUCT_PACKPUSH
  379.     #pragma pack(pop)
  380. #elif PRAGMA_STRUCT_PACK
  381.     #pragma pack()
  382. #endif
  383. #ifdef PRAGMA_IMPORT_OFF
  384. #pragma import off
  385. #elif PRAGMA_IMPORT
  386. #pragma import reset
  387. #endif
  388. #ifdef __cplusplus
  389. }
  390. #endif
  391. #endif /* __DATETIMEUTILS__ */