ttime.c
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
#include <stdio.h>
00022 
00023 
#include "nt.h"
00024 
#include "ntrtl.h"
00025 
00026 
VOID
00027 
PrintTimeFields(
00028     IN PTIME_FIELDS TimeFields
00029     );
00030 
00031 LARGE_INTEGER 
Zero;
00032 LARGE_INTEGER 
OneSecond;
00033 LARGE_INTEGER 
OneMinute;
00034 LARGE_INTEGER 
OneHour;
00035 LARGE_INTEGER 
OneDay;
00036 LARGE_INTEGER 
OneWeek;
00037 LARGE_INTEGER 
OneNormalYear;
00038 LARGE_INTEGER 
OneLeapYear;
00039 LARGE_INTEGER 
OneCentury;
00040 LARGE_INTEGER 
TwoCenturies;
00041 LARGE_INTEGER 
ThreeCenturies;
00042 LARGE_INTEGER 
FourCenturies;
00043 
00044 LARGE_INTEGER 
Sum;
00045 
00046 TIME_FIELDS 
TimeFields;
00047 LARGE_INTEGER 
Time;
00048 
00049 LARGE_INTEGER 
StartOf1970;
00050 LARGE_INTEGER 
StartOf1980;
00051 
00052 
int
00053 main(
00054     
int argc,
00055     
char *argv[]
00056     )
00057 {
00058     ULONG i;
00059 
00060     
00061     
00062     
00063 
00064     
DbgPrint(
"Start Time Test\n");
00065 
00066     
00067     
00068     
00069     
00070 
00071     
Zero.QuadPart = 0;
00072     
OneSecond.QuadPart = 10000000;
00073     
OneMinute.QuadPart = 
OneSecond.QuadPart * 60;
00074     
OneHour.QuadPart = 
OneMinute.QuadPart * 60;
00075     
OneDay.QuadPart = 
OneHour.QuadPart * 24;
00076     
OneWeek.QuadPart = 
OneDay.QuadPart * 7;
00077     
OneNormalYear.QuadPart = 
OneDay.QuadPart * 365;
00078     
OneLeapYear.QuadPart = 
OneDay.QuadPart * 366;
00079     
OneCentury.QuadPart =  (
OneNormalYear.QuadPart * 76) + (
OneLeapYear.QuadPart * 24);
00080     
TwoCenturies.QuadPart = 
OneCentury.QuadPart * 2;
00081     
ThreeCenturies.QuadPart = 
OneCentury.QuadPart * 3;
00082     
FourCenturies.QuadPart = (
OneCentury.QuadPart * 4) + 
OneDay.QuadPart;
00083 
00084     
Sum.QuadPart   = 
Zero.QuadPart +
00085                      
OneSecond.QuadPart +
00086                      
OneMinute.QuadPart +
00087                      
OneHour.QuadPart +
00088                      
OneDay.QuadPart +
00089                      
OneWeek.QuadPart +
00090                      
OneNormalYear.QuadPart +
00091                      
ThreeCenturies.QuadPart;
00092 
00093 
00094     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
Zero, &
TimeFields );
00095     
DbgPrint(
"StartOf1601     = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00096     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00097         
DbgPrint(
"****ERROR converting TimeFields back to Zero\n");
00098     }
00099     
if ((
Time.LowPart != 
Zero.LowPart) || (
Time.HighPart != 
Zero.HighPart)) {
00100         
DbgPrint(
"****ERROR Time != Zero\n");
00101     }
00102 
00103     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneSecond, &
TimeFields );
00104     
DbgPrint(
" + 1 Second     = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00105     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00106         
DbgPrint(
"****ERROR converting TimeFields back to OneSecond\n");
00107     }
00108     
if ((
Time.LowPart != 
OneSecond.LowPart) || (
Time.HighPart != 
OneSecond.HighPart)) {
00109         
DbgPrint(
"****ERROR Time != OneSecond\n");
00110     }
00111 
00112     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneMinute, &
TimeFields );
00113     
DbgPrint(
" + 1 Minute     = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00114     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00115         
DbgPrint(
"****ERROR converting TimeFields back to OneMinute\n");
00116     }
00117     
if ((
Time.LowPart != 
OneMinute.LowPart) || (
Time.HighPart != 
OneMinute.HighPart)) {
00118         
DbgPrint(
"****ERROR Time != OneMinute\n");
00119     }
00120 
00121     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneHour, &
TimeFields );
00122     
DbgPrint(
" + 1 Hour       = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00123     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00124         
DbgPrint(
"****ERROR converting TimeFields back to OneHour\n");
00125     }
00126     
if ((
Time.LowPart != 
OneHour.LowPart) || (
Time.HighPart != 
OneHour.HighPart)) {
00127         
DbgPrint(
"****ERROR Time != OneHour\n");
00128     }
00129 
00130     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneDay, &
TimeFields );
00131     
DbgPrint(
" + 1 Day        = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00132     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00133         
DbgPrint(
"****ERROR converting TimeFields back to OneDay\n");
00134     }
00135     
if ((
Time.LowPart != 
OneDay.LowPart) || (
Time.HighPart != 
OneDay.HighPart)) {
00136         
DbgPrint(
"****ERROR Time != OneDay\n");
00137     }
00138 
00139     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneWeek, &
TimeFields );
00140     
DbgPrint(
" + 1 Week       = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00141     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00142         
DbgPrint(
"****ERROR converting TimeFields back to OneWeek\n");
00143     }
00144     
if ((
Time.LowPart != 
OneWeek.LowPart) || (
Time.HighPart != 
OneWeek.HighPart)) {
00145         
DbgPrint(
"****ERROR Time != OneWeek\n");
00146     }
00147 
00148     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneNormalYear, &
TimeFields );
00149     
DbgPrint(
" + 1 NormalYear = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00150     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00151         
DbgPrint(
"****ERROR converting TimeFields back to OneNormalYear\n");
00152     }
00153     
if ((
Time.LowPart != 
OneNormalYear.LowPart) || (
Time.HighPart != 
OneNormalYear.HighPart)) {
00154         
DbgPrint(
"****ERROR Time != OneNormalYear\n");
00155     }
00156 
00157     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneLeapYear, &
TimeFields );
00158     
DbgPrint(
" + 1 LeapYear   = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00159     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00160         
DbgPrint(
"****ERROR converting TimeFields back to OneLeapYear\n");
00161     }
00162     
if ((
Time.LowPart != 
OneLeapYear.LowPart) || (
Time.HighPart != 
OneLeapYear.HighPart)) {
00163         
DbgPrint(
"****ERROR Time != OneLeapYear\n");
00164     }
00165 
00166     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
OneCentury, &
TimeFields );
00167     
DbgPrint(
" + 1 Century    = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00168     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00169         
DbgPrint(
"****ERROR converting TimeFields back to OneCentury\n");
00170     }
00171     
if ((
Time.LowPart != 
OneCentury.LowPart) || (
Time.HighPart != 
OneCentury.HighPart)) {
00172         
DbgPrint(
"****ERROR Time != OneCentury\n");
00173     }
00174 
00175     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
TwoCenturies, &
TimeFields );
00176     
DbgPrint(
" + 2 Centuries  = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00177     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00178         
DbgPrint(
"****ERROR converting TimeFields back to TwoCenturies\n");
00179     }
00180     
if ((
Time.LowPart != 
TwoCenturies.LowPart) || (
Time.HighPart != 
TwoCenturies.HighPart)) {
00181         
DbgPrint(
"****ERROR Time != TwoCenturies\n");
00182     }
00183 
00184     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
ThreeCenturies, &
TimeFields );
00185     
DbgPrint(
" + 3 Centuries  = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00186     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00187         
DbgPrint(
"****ERROR converting TimeFields back to ThreeCenturies\n");
00188     }
00189     
if ((
Time.LowPart != 
ThreeCenturies.LowPart) || (
Time.HighPart != 
ThreeCenturies.HighPart)) {
00190         
DbgPrint(
"****ERROR Time != ThreeCenturies\n");
00191     }
00192 
00193     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
FourCenturies, &
TimeFields );
00194     
DbgPrint(
" + 4 Centuries  = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00195     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00196         
DbgPrint(
"****ERROR converting TimeFields back to FourCenturies\n");
00197     }
00198     
if ((
Time.LowPart != 
FourCenturies.LowPart) || (
Time.HighPart != 
FourCenturies.HighPart)) {
00199         
DbgPrint(
"****ERROR Time != FourCenturies\n");
00200     }
00201 
00202     
RtlTimeToTimeFields( (PLARGE_INTEGER)&
Sum, &
TimeFields );
00203     
DbgPrint(
" + sum          = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00204     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00205         
DbgPrint(
"****ERROR converting TimeFields back to Sum\n");
00206     }
00207     
if ((
Time.LowPart != 
Sum.LowPart) || (
Time.HighPart != 
Sum.HighPart)) {
00208         
DbgPrint(
"****ERROR Time != Sum\n");
00209     }
00210 
00211     
DbgPrint(
"\n");
00212 
00213     
00214     
00215     
00216 
00217     
RtlSecondsSince1970ToTime( 0, &
StartOf1970 );
00218     
RtlTimeToTimeFields( &
StartOf1970, &
TimeFields );
00219     
DbgPrint(
" Start of 1970  = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00220     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00221         
DbgPrint(
"****ERROR converting TimeFields back to start of 1970\n");
00222     }
00223     
if ((
Time.LowPart != 
StartOf1970.LowPart) || (
Time.HighPart != 
StartOf1970.HighPart)) {
00224         
DbgPrint(
"****ERROR Time != StartOf1970\n");
00225     }
00226     
if (!
RtlTimeToSecondsSince1970( &
StartOf1970, &i )) {
00227         
DbgPrint(
"****ERROR converting time to seconds since 1970\n");
00228     }
00229     
if (i != 0) {
00230         
DbgPrint(
"****ERROR seconds since 1970 != 0\n");
00231     }
00232 
00233     
00234     
00235     
00236 
00237     
RtlSecondsSince1980ToTime( 0, &
StartOf1980 );
00238     
RtlTimeToTimeFields( &
StartOf1980, &
TimeFields );
00239     
DbgPrint(
" Start of 1980  = "); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00240     
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00241         
DbgPrint(
"****ERROR converting TimeFields back to start of 1980\n");
00242     }
00243     
if ((
Time.LowPart != 
StartOf1980.LowPart) || (
Time.HighPart != 
StartOf1980.HighPart)) {
00244         
DbgPrint(
"****ERROR Time != StartOf1980\n");
00245     }
00246     
if (!
RtlTimeToSecondsSince1980( &
StartOf1980, &i )) {
00247         
DbgPrint(
"****ERROR converting time to seconds since 1980\n");
00248     }
00249     
if (i != 0) {
00250         
DbgPrint(
"****ERROR seconds since 1980 != 0\n");
00251     }
00252 
00253     
00254     
00255     
00256     
00257 
00258     
TimeFields.Month = 12;
00259     
TimeFields.Day = 25;
00260     
TimeFields.Hour = 3;
00261     
TimeFields.Minute = 30;
00262     
TimeFields.Second = 15;
00263     
TimeFields.Milliseconds = 250;
00264 
00265     
for (i = 1901; i < 2002; i += 10) {
00266 
00267         
TimeFields.Year = i;
00268 
00269         
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00270             
DbgPrint(
"****ERROR converting TimeFields to Christmas %4d\n", 
TimeFields.Year);
00271         }
00272         
RtlTimeToTimeFields( &
Time, &
TimeFields );
00273         
DbgPrint(
" Christmas %4d = ", i); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00274 
00275     }
00276 
00277     
00278     
00279     
00280 
00281     
TimeFields.Month = 12;
00282     
TimeFields.Day = 5;
00283     
TimeFields.Hour = 3;
00284     
TimeFields.Minute = 14;
00285     
TimeFields.Second = 0;
00286     
TimeFields.Milliseconds = 0;
00287 
00288     
for (i = 1956; i <= 1956+60; i += 10) {
00289 
00290         
TimeFields.Year = i;
00291 
00292         
if (!
RtlTimeFieldsToTime( &
TimeFields, &
Time )) {
00293             
DbgPrint(
"****ERROR converting TimeFields to DOB %4d\n", 
TimeFields.Year);
00294         }
00295         
RtlTimeToTimeFields( &
Time, &
TimeFields );
00296         
DbgPrint(
" DOB + %4d = ", i-1956); 
PrintTimeFields( &
TimeFields ); 
DbgPrint(
"\n");
00297 
00298     }
00299 
00300     
DbgPrint(
"End Time Test\n");
00301 
00302     
return TRUE;
00303 }
00304 
00305 
VOID
00306 PrintTimeFields (
00307     IN PTIME_FIELDS TimeFields
00308     )
00309 {
00310     
static PCHAR Months[] = {
"Jan", 
"Feb", 
"Mar", 
"Apr", 
"May", 
"Jun",
00311                             
"Jul", 
"Aug", 
"Sep", 
"Oct", 
"Nov", 
"Dec"};
00312 
00313     
static PCHAR Days[] = {
"Sun", 
"Mon", 
"Tue", 
"Wed", 
"Thu", 
"Fri", 
"Sat"};
00314 
00315     
DbgPrint(
" %d", 
TimeFields->Year);
00316     
DbgPrint(
"-%s", Months[
TimeFields->Month-1]);
00317     
DbgPrint(
"-%d", 
TimeFields->Day);
00318 
00319     
DbgPrint(
" %2d", 
TimeFields->Hour);
00320     
DbgPrint(
":%2d", 
TimeFields->Minute);
00321     
DbgPrint(
":%2d", 
TimeFields->Second);
00322     
DbgPrint(
".%3d", 
TimeFields->Milliseconds);
00323 
00324     
DbgPrint(
" (%s)", Days[
TimeFields->Weekday]);
00325 }
Generated on Sat May 15 19:42:05 2004 for test by
 1.3.7
 1.3.7