datetime.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. (******************************************************************************
  2. *
  3. * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
  4. * All rights reserved.
  5. *
  6. * File: DateTime.h
  7. *
  8. * Release: Palm OS SDK 4.0 (63220)
  9. *
  10. * Description:
  11. * Date and Time calculations
  12. *
  13. * History:
  14. * 1/19/95 rsf - Created by Roger Flores
  15. * 7/15/99 rsf - moved some types in from Preferences.h
  16. * 12/23/99 jmp - eliminated bogus maxTime definition
  17. * 05/16/00 CS Changed DayOfWeekType ot DayOfMonthType.
  18. *
  19. *****************************************************************************)
  20. unit datetime;
  21. interface
  22. uses palmos, coretraps, chars, localemgr;
  23. type
  24. TimeFormatType = Enum;
  25. const
  26. tfColon = 0;
  27. tfColonAMPM = Succ(tfColon); // 1:00 pm
  28. tfColon24h = Succ(tfColonAMPM); // 13:00
  29. tfDot = Succ(tfColon24h);
  30. tfDotAMPM = Succ(tfDot); // 1.00 pm
  31. tfDot24h = Succ(tfDotAMPM); // 13.00
  32. tfHoursAMPM = Succ(tfDot24h); // 1 pm
  33. tfHours24h = Succ(tfHoursAMPM); // 13
  34. tfComma24h = Succ(tfHours24h); // 13,00
  35. type
  36. DaylightSavingsTypes = Enum;
  37. const
  38. dsNone = 0; // Daylight Savings Time not observed
  39. dsUSA = Succ(dsNone); // United States Daylight Savings Time
  40. dsAustralia = Succ(dsUSA); // Australian Daylight Savings Time
  41. dsWesternEuropean = Succ(dsAustralia); // Western European Daylight Savings Time
  42. dsMiddleEuropean = Succ(dsWesternEuropean); // Middle European Daylight Savings Time
  43. dsEasternEuropean = Succ(dsMiddleEuropean); // Eastern European Daylight Savings Time
  44. dsGreatBritain = Succ(dsEasternEuropean); // Great Britain and Eire Daylight Savings Time
  45. dsRumania = Succ(dsGreatBritain); // Rumanian Daylight Savings Time
  46. dsTurkey = Succ(dsRumania); // Turkish Daylight Savings Time
  47. dsAustraliaShifted = Succ(dsTurkey); // Australian Daylight Savings Time with shift in 1986
  48. // pass a TimeFormatType
  49. // Use24HourFormat(t) ((t) == tfColon24h || (t) == tfDot24h || (t) == tfHours24h || (t) == tfComma24h)
  50. // TimeSeparator(t) ((Char) ( t <= tfColon24h ? ':' : (t <= tfDot24h ? '.' : ',')))
  51. type
  52. DateFormatType = Enum;
  53. const
  54. dfMDYWithSlashes = 0; // 12/31/95
  55. dfDMYWithSlashes = Succ(dfMDYWithSlashes); // 31/12/95
  56. dfDMYWithDots = Succ(dfDMYWithSlashes); // 31.12.95
  57. dfDMYWithDashes = Succ(dfDMYWithDots); // 31-12-95
  58. dfYMDWithSlashes = Succ(dfDMYWithDashes); // 95/12/31
  59. dfYMDWithDots = Succ(dfYMDWithSlashes); // 95.12.31
  60. dfYMDWithDashes = Succ(dfYMDWithDots); // 95-12-31
  61. dfMDYLongWithComma = Succ(dfYMDWithDashes); // Dec 31, 1995
  62. dfDMYLong = Succ(dfMDYLongWithComma); // 31 Dec 1995
  63. dfDMYLongWithDot = Succ(dfDMYLong); // 31. Dec 1995
  64. dfDMYLongNoDay = Succ(dfDMYLongWithDot); // Dec 1995
  65. dfDMYLongWithComma = Succ(dfDMYLongNoDay); // 31 Dec, 1995
  66. dfYMDLongWithDot = Succ(dfDMYLongWithComma); // 1995.12.31
  67. dfYMDLongWithSpace = Succ(dfYMDLongWithDot); // 1995 Dec 31
  68. dfMYMed = Succ(dfYMDLongWithSpace); // Dec '95
  69. dfMYMedNoPost = Succ(dfMYMed); // Dec 95 (added for French 2.0 ROM)
  70. dfMDYWithDashes = Succ(dfMYMedNoPost); // 12-31-95 (added for 4.0 ROM)
  71. type
  72. DateTimeType = record
  73. second: Int16;
  74. minute: Int16;
  75. hour: Int16;
  76. day: Int16;
  77. month: Int16;
  78. year: Int16;
  79. weekDay: Int16; // Days since Sunday (0 to 6)
  80. end;
  81. DateTimePtr = ^DateTimeType;
  82. // This is the time format. Times are treated as words so don't
  83. // change the order of the members in this structure.
  84. //
  85. TimeType = record
  86. hours: UInt8;
  87. minutes: UInt8;
  88. end;
  89. TimePtr = ^TimeType;
  90. const
  91. noTime = -1; // The entire TimeType is -1 if there isn't a time.
  92. // This is the date format. Dates are treated as words so don't
  93. // change the order of the members in this structure.
  94. //
  95. type
  96. DateType = record
  97. Bits: UInt16;
  98. {
  99. UInt16 year :7; // years since 1904 (MAC format)
  100. UInt16 month :4;
  101. UInt16 day :5;
  102. }
  103. end;
  104. DatePtr = ^DateType;
  105. (************************************************************
  106. * Date Time Constants
  107. *************************************************************)
  108. // Maximum lengths of strings return by the date and time formating
  109. // routine DateToAscii and TimeToAscii.
  110. const
  111. timeStringLength = 9;
  112. dateStringLength = 9;
  113. longDateStrLength = 15;
  114. dowDateStringLength = 19;
  115. dowLongDateStrLength = 25;
  116. timeZoneStringLength = 50;
  117. firstYear = 1904;
  118. numberOfYears = 128;
  119. lastYear = firstYear + numberOfYears - 1;
  120. // Constants for time calculations
  121. // Could change these from xIny to yPerX
  122. secondsInSeconds = 1;
  123. minutesInSeconds = 60;
  124. hoursInMinutes = 60;
  125. hoursInSeconds = hoursInMinutes * minutesInSeconds;
  126. hoursPerDay = 24;
  127. // daysInSeconds ((Int32)(hoursPerDay) * ((Int32)hoursInSeconds))
  128. daysInSeconds = $15180; // cc bug
  129. daysInWeek = 7;
  130. daysInYear = 365;
  131. daysInLeapYear = 366;
  132. daysInFourYears = daysInLeapYear + 3 * daysInYear;
  133. monthsInYear = 12;
  134. maxDays = UInt32(numberOfYears div 4 * daysInFourYears - 1);
  135. maxSeconds = UInt32((maxDays+1) * daysInSeconds - 1);
  136. // Values returned by DayOfWeek routine.
  137. sunday = 0;
  138. monday = 1;
  139. tuesday = 2;
  140. wednesday = 3;
  141. thursday = 4;
  142. friday = 5;
  143. saturday = 6;
  144. // Months of the year
  145. january = 1;
  146. february = 2;
  147. march = 3;
  148. april = 4;
  149. may = 5;
  150. june = 6;
  151. july = 7;
  152. august = 8;
  153. september = 9;
  154. october = 10;
  155. november = 11;
  156. december = 12;
  157. // Values returned by DayOfMonth routine.
  158. type
  159. DayOfMonthType = Enum;
  160. // It would have been cool to have a real DayOfWeekType, but we #define the
  161. // following for compatibility with existing code. Please use the new name
  162. // (DayOfMonthType).
  163. DayOfWeekType = DayOfMonthType;
  164. const
  165. dom1stSun = 0;
  166. dom1stMon = Succ(dom1stSun);
  167. dom1stTue = Succ(dom1stMon);
  168. dom1stWen = Succ(dom1stTue);
  169. dom1stThu = Succ(dom1stWen);
  170. dom1stFri = Succ(dom1stThu);
  171. dom1stSat = Succ(dom1stFri);
  172. dom2ndSun = Succ(dom1stSat);
  173. dom2ndMon = Succ(dom2ndSun);
  174. dom2ndTue = Succ(dom2ndMon);
  175. dom2ndWen = Succ(dom2ndTue);
  176. dom2ndThu = Succ(dom2ndWen);
  177. dom2ndFri = Succ(dom2ndThu);
  178. dom2ndSat = Succ(dom2ndFri);
  179. dom3rdSun = Succ(dom2ndSat);
  180. dom3rdMon = Succ(dom3rdSun);
  181. dom3rdTue = Succ(dom3rdMon);
  182. dom3rdWen = Succ(dom3rdTue);
  183. dom3rdThu = Succ(dom3rdWen);
  184. dom3rdFri = Succ(dom3rdThu);
  185. dom3rdSat = Succ(dom3rdFri);
  186. dom4thSun = Succ(dom3rdSat);
  187. dom4thMon = Succ(dom4thSun);
  188. dom4thTue = Succ(dom4thMon);
  189. dom4thWen = Succ(dom4thTue);
  190. dom4thThu = Succ(dom4thWen);
  191. dom4thFri = Succ(dom4thThu);
  192. dom4thSat = Succ(dom4thFri);
  193. domLastSun = Succ(dom4thSat);
  194. domLastMon = Succ(domLastSun);
  195. domLastTue = Succ(domLastMon);
  196. domLastWen = Succ(domLastTue);
  197. domLastThu = Succ(domLastWen);
  198. domLastFri = Succ(domLastThu);
  199. domLastSa = Succ(domLastFri);
  200. // Values used by DateTemplateToAscii routine.
  201. dateTemplateChar = chrCircumflexAccent;
  202. dateTemplateDayNum = '0';
  203. dateTemplateDOWName = Succ(dateTemplateDayNum);
  204. dateTemplateMonthName = Succ(dateTemplateDOWName);
  205. dateTemplateMonthNum = Succ(dateTemplateMonthName);
  206. dateTemplateYearNum = Succ(dateTemplateMonthNum);
  207. dateTemplateShortModifier = 's';
  208. dateTemplateRegularModifier = 'r';
  209. dateTemplateLongModifier = 'l';
  210. dateTemplateLeadZeroModifier = 'z';
  211. //************************************************************
  212. //* Date and Time macros
  213. //***********************************************************
  214. {
  215. // Convert a date in a DateType structure to an UInt16.
  216. DateToInt(date) (*(UInt16 *) &date)
  217. // Convert a date in a DateType structure to a signed int.
  218. TimeToInt(time) (*(Int16 *) &time)
  219. }
  220. //************************************************************
  221. //* Date Time procedures
  222. //************************************************************
  223. procedure TimSecondsToDateTime(seconds: UInt32; dateTimeP: DateTimePtr); syscall sysTrapTimSecondsToDateTime;
  224. function TimDateTimeToSeconds(dateTimeP: DateTimePtr): UInt32; syscall sysTrapTimDateTimeToSeconds;
  225. procedure TimAdjust(dateTimeP: DateTimePtr; adjustment: Int32); syscall sysTrapTimAdjust;
  226. procedure TimeToAscii(hours, minutes: UInt8; timeFormat: TimeFormatType; pString: PChar); syscall sysTrapTimeToAscii;
  227. function TimTimeZoneToUTC(seconds: UInt32; timeZone: Int16; daylightSavingAdjustment: Int16): UInt32; syscall sysTrapTimTimeZoneToUTC;
  228. function TimUTCToTimeZone(seconds: UInt32; timeZone: Int16; daylightSavingAdjustment: Int16): UInt32; syscall sysTrapTimUTCToTimeZone;
  229. procedure TimeZoneToAscii(timeZone: Int16; localeP: LmLocalePtr; string_: PChar); syscall sysTrapTimeZoneToAscii;
  230. function DaysInMonth(month, year: Int16): Int16; syscall sysTrapDaysInMonth;
  231. function DayOfWeek(month, day, year: Int16): Int16; syscall sysTrapDayOfWeek;
  232. function DayOfMonth(month, day, year: Int16): Int16; syscall sysTrapDayOfMonth;
  233. // Date routines.
  234. procedure DateSecondsToDate(seconds: UInt32; date: DatePtr); syscall sysTrapDateSecondsToDate;
  235. procedure DateDaysToDate(days: UInt32; date: DatePtr); syscall sysTrapDateDaysToDate;
  236. function DateToDays(date: DateType): UInt32; syscall sysTrapDateToDays;
  237. procedure DateAdjust(dateP: DatePtr; adjustment: Int32); syscall sysTrapDateAdjust;
  238. procedure DateToAscii(months, days: UInt8; years: UInt16;
  239. dateFormat: DateFormatType; pString: PChar); syscall sysTrapDateToAscii;
  240. procedure DateToDOWDMFormat(months, days: UInt8; years: UInt16;
  241. dateFormat: DateFormatType; pString: PChar); syscall sysTrapDateToDOWDMFormat;
  242. function DateTemplateToAscii(const templateP: PChar; months, days: UInt8;
  243. years: UInt16; stringP: PChar; stringLen: Int16): UInt16; syscall sysTrapDateTemplateToAscii;
  244. implementation
  245. end.