test: ttime.c File Reference

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

# ttime.c File Reference

`#include <stdio.h>`
`#include "nt.h"`
`#include "ntrtl.h"`

Go to the source code of this file.

## Functions

VOID | PrintTimeFields (IN PTIME_FIELDS TimeFields)
int | main (int argc, char *argv[])

## Variables

LARGE_INTEGER | Zero
LARGE_INTEGER | OneSecond
LARGE_INTEGER | OneMinute
LARGE_INTEGER | OneHour
LARGE_INTEGER | OneDay
LARGE_INTEGER | OneWeek
LARGE_INTEGER | OneNormalYear
LARGE_INTEGER | OneLeapYear
LARGE_INTEGER | OneCentury
LARGE_INTEGER | TwoCenturies
LARGE_INTEGER | ThreeCenturies
LARGE_INTEGER | FourCenturies
LARGE_INTEGER | Sum
TIME_FIELDS | TimeFields
LARGE_INTEGER | Time
LARGE_INTEGER | StartOf1970
LARGE_INTEGER | StartOf1980

## Function Documentation

int main | ( | int | argc,
|  | char * | argv[]
| ) |

Definition at line 53 of file ttime.c.

References DbgPrint, FourCenturies, OneCentury, OneDay, OneHour, OneLeapYear, OneMinute, OneNormalYear, OneSecond, OneWeek, PrintTimeFields(), RtlSecondsSince1970ToTime(), RtlSecondsSince1980ToTime(), RtlTimeFieldsToTime(), RtlTimeToSecondsSince1970(), RtlTimeToSecondsSince1980(), RtlTimeToTimeFields(), StartOf1970, StartOf1980, Sum, ThreeCenturies, Time, TimeFields, TRUE, TwoCenturies, and Zero.

    00057 {
    00058     ULONG i;
    00059
    00060     //
    00061     //  We're starting the test
    00062     //
    00063
    00064     DbgPrint("Start Time Test\n");
    00065
    00066     //
    00067     //  Start by initializing some constants and making sure they
    00068     //  are correct
    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     //  Setup and test the start 1970 time
    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     //  Setup and test the start 1980 time
    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     //  Lets try to print the Christmas when Santa arrives for 1901 to 2001
    00255     //  every 10 years
    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     //  Let's see how old I really am, when I turn 10, 20, 30, ...
    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 }

VOID PrintTimeFields | ( | IN PTIME_FIELDS | TimeFields | ) |

Definition at line 306 of file ttime.c.

References DbgPrint, and TimeFields.

Referenced by main().

    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 }

## Variable Documentation

LARGE_INTEGER FourCenturies

| Definition at line 42 of file ttime.c. Referenced by main().

LARGE_INTEGER OneCentury

| Definition at line 39 of file ttime.c. Referenced by main().

LARGE_INTEGER OneDay

| Definition at line 35 of file ttime.c. Referenced by main().

LARGE_INTEGER OneHour

| Definition at line 34 of file ttime.c. Referenced by main().

LARGE_INTEGER OneLeapYear

| Definition at line 38 of file ttime.c. Referenced by main().

LARGE_INTEGER OneMinute

| Definition at line 33 of file ttime.c. Referenced by main().

LARGE_INTEGER OneNormalYear

| Definition at line 37 of file ttime.c. Referenced by main().

LARGE_INTEGER OneSecond

| Definition at line 32 of file ttime.c. Referenced by main().

LARGE_INTEGER OneWeek

| Definition at line 36 of file ttime.c. Referenced by main().

LARGE_INTEGER StartOf1970

| Definition at line 49 of file ttime.c. Referenced by main().

LARGE_INTEGER StartOf1980

| Definition at line 50 of file ttime.c. Referenced by main().

LARGE_INTEGER Sum

| Definition at line 44 of file ttime.c. Referenced by GetStdDev(), main(), and WndProc().

LARGE_INTEGER ThreeCenturies

| Definition at line 41 of file ttime.c. Referenced by main().

LARGE_INTEGER Time

| Definition at line 47 of file ttime.c. Referenced by DaysAndFractionToTime(), DoTest(), ExpAllocateUuids(), ExpUuidGetValues(), ExUuidCreate(), main(), NtAllocateUuids(), Reader(), ReaderTurnedWriter(), RtlRunEncodeUnicodeString(), RtlSecondsSince1970ToTime(), RtlSecondsSince1980ToTime(), RtlTimeFieldsToTime(), RtlTimeToElapsedTimeFields(), RtlTimeToSecondsSince1970(), RtlTimeToSecondsSince1980(), RtlTimeToTimeFields(), TimeToDaysAndFraction(), and Writer().

TIME_FIELDS TimeFields

| Definition at line 46 of file ttime.c. Referenced by ExGetNextWakeTime(), IopCopyBootLogRegistryToFile(), KdEnterDebugger(), KdExitDebugger(), KeSetSystemTime(), main(), MiInitializeSpecialPoolCriteria(), PrintTimeFields(), RtlTimeFieldsToTime(), RtlTimeToElapsedTimeFields(), RtlTimeToTimeFields(), SeMakeAnonymousLogonToken(), and SeMakeSystemToken().

LARGE_INTEGER TwoCenturies

| Definition at line 40 of file ttime.c. Referenced by main().

LARGE_INTEGER Zero

| Definition at line 31 of file ttime.c. Referenced by CcPreparePinWrite(), main(), RtlpFreeStack(), UnlockConsole(), and UnusedEntryFill().