Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

stdtimep.h

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 stdtimep.h 00008 00009 Abstract: 00010 00011 This module contains definitions and function prototypes which are local to 00012 stdime.c and fmttime.c. 00013 00014 Author: 00015 00016 Rob McKaughan (t-robmc) 17-Jul-1991 00017 00018 Revision History: 00019 00020 --*/ 00021 00022 #ifndef _STD_TIME_P_ 00023 #define _STD_TIME_P_ 00024 00025 // 00026 // These are the magic numbers needed to do our extended division. The 00027 // only numbers we ever need to divide by are 00028 // 00029 // 10,000 = convert 100ns tics to millisecond tics 00030 // 00031 // 10,000,000 = convert 100ns tics to one second tics 00032 // 00033 // 86,400,000 = convert Millisecond tics to one day tics 00034 // 00035 00036 extern LARGE_INTEGER Magic10000; 00037 #define SHIFT10000 13 00038 00039 extern LARGE_INTEGER Magic10000000; 00040 #define SHIFT10000000 23 00041 00042 extern LARGE_INTEGER Magic86400000; 00043 #define SHIFT86400000 26 00044 00045 // 00046 // To make the code more readable we'll also define some macros to 00047 // do the actual division for use 00048 // 00049 00050 #define Convert100nsToMilliseconds(LARGE_INTEGER) ( \ 00051 RtlExtendedMagicDivide( (LARGE_INTEGER), Magic10000, SHIFT10000 ) \ 00052 ) 00053 00054 #define ConvertMillisecondsTo100ns(MILLISECONDS) ( \ 00055 RtlExtendedIntegerMultiply( (MILLISECONDS), 10000 ) \ 00056 ) 00057 00058 #define Convert100nsToSeconds(LARGE_INTEGER) ( \ 00059 RtlExtendedMagicDivide( (LARGE_INTEGER), Magic10000000, SHIFT10000000 ) \ 00060 ) 00061 00062 #define ConvertSecondsTo100ns(SECONDS) ( \ 00063 RtlExtendedIntegerMultiply( (SECONDS), 10000000L ) \ 00064 ) 00065 00066 #define ConvertMillisecondsToDays(LARGE_INTEGER) ( \ 00067 RtlExtendedMagicDivide( (LARGE_INTEGER), Magic86400000, SHIFT86400000 ) \ 00068 ) 00069 00071 // // 00072 // Macros for Time Differentials and Time Revisions // 00073 // // 00075 00076 // 00077 // The following define the minimum and maximum possible values for the Time 00078 // Differential Factor as defined by ISO 4031-1978. 00079 // 00080 00081 #define MAX_STDTIME_TDF (780) 00082 #define MIN_STDTIME_TDF (-720) 00083 00084 // 00085 // The revision of this design (will be inserted in the revision field of any 00086 // STANDARD_TIMEs created by this revision). 00087 // 00088 00089 #define STDTIME_REVISION (4) 00090 00091 00092 // 00093 // The number of bits we need to shift to get to and from a revision in a 00094 // StdTime.TdfAndRevision field. 00095 // 00096 00097 #define STDTIME_REVISION_SHIFT 12 00098 00099 00100 // 00101 // USHORT 00102 // ShiftStandardTimeRevision( 00103 // IN USHORT Rev 00104 // ) 00105 // Description: 00106 // This routine shifts the given revision number to its proper place for 00107 // storing in a STANDARD_TIME.TdfAndRevision field. 00108 // 00109 00110 #define ShiftStandardTimeRevision(Rev) \ 00111 ((USHORT) ((Rev) << STDTIME_REVISION_SHIFT)) 00112 00113 00114 // 00115 // The pre-shifted value of the current revision 00116 // 00117 00118 #define SHIFTED_STDTIME_REVISION (ShiftStandardTimeRevision(STDTIME_REVISION)) 00119 00120 00121 // 00122 // The bit mask used to mask a STANDARD_TIME.TdfAndRevision field to retrieve 00123 // the Tdf value. 00124 // 00125 00126 #define TDF_MASK ((USHORT) 0x0fff) 00127 00128 00129 // 00130 // USHORT 00131 // MaskStandardTimeTdf( 00132 // IN USHORT Tdf 00133 // ) 00134 // Description: 00135 // This routine masks the given tdf field with TDF_MASK and returns the 00136 // result. 00137 // 00138 // BUG: Byte order dependant 00139 // 00140 00141 #define MaskStandardTimeTdf(Tdf) ((USHORT) ((Tdf) & TDF_MASK)) 00142 00143 00144 // 00145 // SHORT 00146 // GetStandardTimeTdf( 00147 // IN STANDARD_TIME 00148 // ) 00149 // Description: 00150 // This routine gets the Time Differential Factor from a tdf field and 00151 // makes any adjustments necessary to preserve the sign of the TDF. 00152 // The resulting TDF is returned. 00153 // 00154 // Since the TDF is stored as a signed 12 bit int, it's sign bit is the 00155 // bit 0x0800. To make it a 16 bit negative, we subtract 0x1000 from the 00156 // bottome 12 bits of the TdfAndRevision field. 00157 // 00158 // BUG: Byte order dependant 00159 // 00160 00161 #define GetStandardTimeTdf(StdTime) \ 00162 ((SHORT) \ 00163 (((StdTime)->TdfAndRevision) & 0x0800) \ 00164 ? (MaskStandardTimeTdf((StdTime)->TdfAndRevision) - 0x1000) \ 00165 : MaskStandardTimeTdf((StdTime)->TdfAndRevision) \ 00166 ) 00167 00168 00169 // 00170 // USHORT 00171 // GetStandardTimeRev( 00172 // IN USHORT Tdf 00173 // ) 00174 // Description: 00175 // This routine gets the revision number from a tdf field and returns it 00176 // shifted back down to its place as a SHORT. 00177 // 00178 00179 #define GetStandardTimeRev(StdTime) \ 00180 ((USHORT) (((StdTime)->TdfAndRevision) >> STDTIME_REVISION_SHIFT)) 00181 00182 00183 00185 // // 00186 // Tests for absolute and delta times // 00187 // // 00189 00190 // 00191 // BOOLEAN 00192 // IsPositive( 00193 // IN LARGE_INTEGER Time 00194 // ) 00195 // Returns: 00196 // TRUE - if the time in Time is positive. 00197 // FALSE - if Time is negative. 00198 // 00199 00200 #define IsPositive(Time) \ 00201 ( ((Time).HighPart > 0) || (((Time).HighPart = 0) & ((Time).LowPart > 0)) ) 00202 00203 // 00204 // BOOLEAN 00205 // IsAbsoluteTime( 00206 // IN PSTANDARDTIME Time 00207 // ) 00208 // Returns: 00209 // TRUE - if the given time is an absolute time 00210 // FALSE - If the given time is not an absolute time 00211 // 00212 00213 #define IsAbsoluteTime(Time) \ 00214 ( IsPositive(Time->SimpleTime) ) 00215 00216 00217 // 00218 // BOOLEAN 00219 // IsDeltaTime( 00220 // IN PSTANDARDTIME Time 00221 // ) 00222 // Returns: 00223 // TRUE - if the given time is a delta time 00224 // FALSE - If the given time is not a delta time 00225 // 00226 00227 #define IsDeltaTime(Time) \ 00228 ( !IsAbsoluteTime(Time) ) 00229 00230 00231 // 00232 // BOOLEAN 00233 // GreaterThanTime( 00234 // IN PLARGE_INTEGER Time1, 00235 // IN PLARGE_INTEGER Time2 00236 // ) 00237 // Returns: 00238 // TRUE - If Time1 is greater (older) than Time2 00239 // FALSE - If not 00240 // 00241 // BUG: Byte order dependant 00242 // BUG: Only works on absolute times 00243 // 00244 00245 #define GreaterThanTime(Time1, Time2) \ 00246 ( \ 00247 ((Time1).HighPart > (Time2).HighPart) \ 00248 || \ 00249 ( \ 00250 ((Time1).HighPart == (Time2).HighPart) \ 00251 && \ 00252 ((Time1).LowPart > (Time2).LowPart) \ 00253 ) \ 00254 ) 00255 00256 00257 // 00258 // BOOLEAN 00259 // GreaterThanStandardTime( 00260 // IN PSTANDARD_TIME Time1, 00261 // IN PSTANDARD_TIME Time2 00262 // ) 00263 // Returns: 00264 // TRUE - If Time1 is greater (older) than Time2 00265 // FALSE - If not 00266 // 00267 00268 #define GreaterThanStdTime(Time1, Time2) \ 00269 GreaterThanTime((Time1).SimpleTime, (Time2).SimpleTime) 00270 00271 00272 00274 // / 00275 // The following definitions and declarations are some important constants / 00276 // used in the time conversion routines / 00277 // / 00279 00280 // 00281 // This is the week day that January 1st, 1601 fell on (a Monday) 00282 // 00283 00284 #define WEEKDAY_OF_1601 1 00285 00286 // 00287 // These are known constants used to convert 1970 and 1980 times to 1601 00288 // times. They are the number of seconds from the 1601 base to the start 00289 // of 1970 and the start of 1980. The number of seconds from 1601 to 00290 // 1970 is 369 years worth, or (369 * 365) + 89 leap days = 134774 days, or 00291 // 134774 * 864000 seconds, which is equal to the large integer defined 00292 // below. The number of seconds from 1601 to 1980 is 379 years worth, or etc. 00293 // 00294 // These are declared in time.c 00295 // 00296 00297 extern LARGE_INTEGER SecondsToStartOf1970; 00298 extern LARGE_INTEGER SecondsToStartOf1980; 00299 00300 00301 // 00302 // ULONG 00303 // ElapsedDaysToYears ( 00304 // IN ULONG ElapsedDays 00305 // ); 00306 // 00307 // To be completely true to the Gregorian calendar the equation to 00308 // go from days to years is really 00309 // 00310 // ElapsedDays / 365.2425 00311 // 00312 // But because we are doing the computation in ulong integer arithmetic 00313 // and the LARGE_INTEGER variable limits the number of expressible days to around 00314 // 11,000,000 we use the following computation 00315 // 00316 // (ElapsedDays * 128 + 127) / (365.2425 * 128) 00317 // 00318 // which will be off from the Gregorian calendar in about 150,000 years 00319 // but that doesn't really matter because LARGE_INTEGER can only express around 00320 // 30,000 years 00321 // 00322 00323 #define ElapsedDaysToYears(DAYS) ( \ 00324 ((DAYS) * 128 + 127) / 46751 \ 00325 ) 00326 00327 // 00328 // ULONG 00329 // NumberOfLeapYears ( 00330 // IN ULONG ElapsedYears 00331 // ); 00332 // 00333 // The number of leap years is simply the number of years divided by 4 00334 // minus years divided by 100 plus years divided by 400. This says 00335 // that every four years is a leap year except centuries, and the 00336 // exception to the exception is the quadricenturies 00337 // 00338 00339 #define NumberOfLeapYears(YEARS) ( \ 00340 ((YEARS) / 4) - ((YEARS) / 100) + ((YEARS) / 400) \ 00341 ) 00342 00343 // 00344 // ULONG 00345 // ElapsedYearsToDays ( 00346 // IN ULONG ElapsedYears 00347 // ); 00348 // 00349 // The number of days contained in elapsed years is simply the number 00350 // of years times 365 (because every year has at least 365 days) plus 00351 // the number of leap years there are (i.e., the number of 366 days years) 00352 // 00353 00354 #define ElapsedYearsToDays(YEARS) ( \ 00355 ((YEARS) * 365) + NumberOfLeapYears(YEARS) \ 00356 ) 00357 00358 // 00359 // BOOLEAN 00360 // IsLeapYear ( 00361 // IN ULONG ElapsedYears 00362 // ); 00363 // 00364 // If it is an even 400 or a non century leapyear then the 00365 // answer is true otherwise it's false 00366 // 00367 00368 #define IsLeapYear(YEARS) ( \ 00369 (((YEARS) % 400 == 0) || \ 00370 ((YEARS) % 100 != 0) && ((YEARS) % 4 == 0)) ? \ 00371 TRUE \ 00372 : \ 00373 FALSE \ 00374 ) 00375 00376 // 00377 // ULONG 00378 // MaxDaysInMonth ( 00379 // IN ULONG Year, 00380 // IN ULONG Month 00381 // ); 00382 // 00383 // The maximum number of days in a month depend on the year and month. 00384 // It is the difference between the days to the month and the days 00385 // to the following month 00386 // 00387 00388 #define MaxDaysInMonth(YEAR,MONTH) ( \ 00389 IsLeapYear(YEAR) ? \ 00390 LeapYearDaysPrecedingMonth[(MONTH) + 1] - \ 00391 LeapYearDaysPrecedingMonth[(MONTH)] \ 00392 : \ 00393 NormalYearDaysPrecedingMonth[(MONTH) + 1] - \ 00394 NormalYearDaysPrecedingMonth[(MONTH)] \ 00395 ) 00396 00397 00398 // 00399 // Local utlity function prototypes 00400 // 00401 00402 VOID 00403 RtlpConvert48To64( 00404 IN PSTDTIME_ERROR num48, 00405 OUT LARGE_INTEGER *num64 00406 ); 00407 00408 NTSTATUS 00409 RtlpConvert64To48( 00410 IN LARGE_INTEGER num64, 00411 OUT PSTDTIME_ERROR num48 00412 ); 00413 00414 LARGE_INTEGER 00415 RtlpTimeToLargeInt( 00416 IN LARGE_INTEGER Time 00417 ); 00418 00419 LARGE_INTEGER 00420 RtlpLargeIntToTime( 00421 IN LARGE_INTEGER Int 00422 ); 00423 00424 NTSTATUS 00425 RtlpAdd48Int( 00426 IN PSTDTIME_ERROR First48, 00427 IN PSTDTIME_ERROR Second48, 00428 IN PSTDTIME_ERROR Result48 00429 ); 00430 00431 NTSTATUS 00432 RtlpAddTime( 00433 IN LARGE_INTEGER Time1, 00434 IN LARGE_INTEGER Time2, 00435 OUT PLARGE_INTEGER Result 00436 ); 00437 00438 NTSTATUS 00439 RtlpSubtractTime( 00440 IN LARGE_INTEGER Time1, 00441 IN LARGE_INTEGER Time2, 00442 OUT PLARGE_INTEGER Result 00443 ); 00444 00445 LARGE_INTEGER 00446 RtlpAbsTime( 00447 IN LARGE_INTEGER Time 00448 ); 00449 00450 #endif //_STD_TIME_P_

Generated on Sat May 15 19:41:52 2004 for test by doxygen 1.3.7