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