00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
#include "ntrtlp.h"
00049
00050
#if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
00051
#pragma alloc_text(PAGE, RtlCutoverTimeToSystemTime)
00052
#pragma alloc_text(PAGE, RtlTimeToElapsedTimeFields)
00053
#endif
00054
00055
00056
00057
00058
00059
00060
00061
00062 CONST UCHAR
LeapYearDayToMonth[366] = {
00063 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00064 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00065 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00066 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00067 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
00068 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
00069 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
00070 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00071 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
00072 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
00073 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
00074 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11};
00075
00076 CONST UCHAR
NormalYearDayToMonth[365] = {
00077 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
00078 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
00079 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
00080 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
00081 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
00082 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
00083 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
00084 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
00085 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
00086 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
00087 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
00088 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11};
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 CONST CSHORT
LeapYearDaysPrecedingMonth[13] = {
00099 0,
00100 31,
00101 31+29,
00102 31+29+31,
00103 31+29+31+30,
00104 31+29+31+30+31,
00105 31+29+31+30+31+30,
00106 31+29+31+30+31+30+31,
00107 31+29+31+30+31+30+31+31,
00108 31+29+31+30+31+30+31+31+30,
00109 31+29+31+30+31+30+31+31+30+31,
00110 31+29+31+30+31+30+31+31+30+31+30,
00111 31+29+31+30+31+30+31+31+30+31+30+31};
00112
00113 CONST CSHORT
NormalYearDaysPrecedingMonth[13] = {
00114 0,
00115 31,
00116 31+28,
00117 31+28+31,
00118 31+28+31+30,
00119 31+28+31+30+31,
00120 31+28+31+30+31+30,
00121 31+28+31+30+31+30+31,
00122 31+28+31+30+31+30+31+31,
00123 31+28+31+30+31+30+31+31+30,
00124 31+28+31+30+31+30+31+31+30+31,
00125 31+28+31+30+31+30+31+31+30+31+30,
00126 31+28+31+30+31+30+31+31+30+31+30+31};
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 #define WEEKDAY_OF_1601 1
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 const LARGE_INTEGER
SecondsToStartOf1970 = {0xb6109100, 0x00000002};
00150
00151 const LARGE_INTEGER
SecondsToStartOf1980 = {0xc8df3700, 0x00000002};
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 const LARGE_INTEGER
Magic10000 = {0xe219652c, 0xd1b71758};
00165 #define SHIFT10000 13
00166
00167 const LARGE_INTEGER
Magic10000000 = {0xe57a42bd, 0xd6bf94d5};
00168 #define SHIFT10000000 23
00169
00170 const LARGE_INTEGER
Magic86400000 = {0xfa67b90e, 0xc6d750eb};
00171 #define SHIFT86400000 26
00172
00173
00174
00175
00176
00177
00178 #define Convert100nsToMilliseconds(LARGE_INTEGER) ( \
00179
RtlExtendedMagicDivide( (LARGE_INTEGER), Magic10000, SHIFT10000 ) \
00180
)
00181
00182 #define ConvertMillisecondsTo100ns(MILLISECONDS) ( \
00183
RtlExtendedIntegerMultiply( (MILLISECONDS), 10000 ) \
00184
)
00185
00186 #define Convert100nsToSeconds(LARGE_INTEGER) ( \
00187
RtlExtendedMagicDivide( (LARGE_INTEGER), Magic10000000, SHIFT10000000 ) \
00188
)
00189
00190 #define ConvertSecondsTo100ns(SECONDS) ( \
00191
RtlExtendedIntegerMultiply( (SECONDS), 10000000 ) \
00192
)
00193
00194 #define ConvertMillisecondsToDays(LARGE_INTEGER) ( \
00195
RtlExtendedMagicDivide( (LARGE_INTEGER), Magic86400000, SHIFT86400000 ) \
00196
)
00197
00198 #define ConvertDaysToMilliseconds(DAYS) ( \
00199
Int32x32To64( (DAYS), 86400000 ) \
00200
)
00201
00202
00203
00204
00205
00206
00207 ULONG
00208 ElapsedDaysToYears (
00209 IN ULONG ElapsedDays
00210 )
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 {
00235 ULONG NumberOf400s;
00236 ULONG NumberOf100s;
00237 ULONG NumberOf4s;
00238 ULONG Years;
00239
00240
00241
00242
00243
00244
00245
00246
00247 NumberOf400s = ElapsedDays / 146097;
00248 ElapsedDays -= NumberOf400s * 146097;
00249
00250
00251
00252
00253
00254
00255
00256
00257 NumberOf100s = (ElapsedDays * 100 + 75) / 3652425;
00258 ElapsedDays -= NumberOf100s * 36524;
00259
00260
00261
00262
00263
00264 NumberOf4s = ElapsedDays / 1461;
00265 ElapsedDays -= NumberOf4s * 1461;
00266
00267
00268
00269
00270
00271
00272
00273
00274 Years = (NumberOf400s * 400) +
00275 (NumberOf100s * 100) +
00276 (NumberOf4s * 4) +
00277 (ElapsedDays * 100 + 75) / 36525;
00278
00279
return Years;
00280 }
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 #define NumberOfLeapYears(YEARS) ( \
00296
((YEARS) / 4) - ((YEARS) / 100) + ((YEARS) / 400) \
00297
)
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 #define ElapsedYearsToDays(YEARS) ( \
00311
((YEARS) * 365) + NumberOfLeapYears(YEARS) \
00312
)
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 #define IsLeapYear(YEARS) ( \
00325
(((YEARS) % 400 == 0) || \
00326
((YEARS) % 100 != 0) && ((YEARS) % 4 == 0)) ? \
00327
TRUE \
00328
: \
00329
FALSE \
00330
)
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 #define MaxDaysInMonth(YEAR,MONTH) ( \
00345
IsLeapYear(YEAR) ? \
00346
LeapYearDaysPrecedingMonth[(MONTH) + 1] - \
00347
LeapYearDaysPrecedingMonth[(MONTH)] \
00348
: \
00349
NormalYearDaysPrecedingMonth[(MONTH) + 1] - \
00350
NormalYearDaysPrecedingMonth[(MONTH)] \
00351
)
00352
00353
00354
00355
00356
00357
00358
00359
static
00360
VOID
00361 TimeToDaysAndFraction (
00362 IN PLARGE_INTEGER Time,
00363 OUT PULONG ElapsedDays,
00364 OUT PULONG Milliseconds
00365 )
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 {
00390 LARGE_INTEGER TotalMilliseconds;
00391 LARGE_INTEGER Temp;
00392
00393
00394
00395
00396
00397 TotalMilliseconds =
Convert100nsToMilliseconds( *(PLARGE_INTEGER)
Time );
00398
00399
00400
00401
00402
00403 Temp =
ConvertMillisecondsToDays( TotalMilliseconds );
00404
00405
00406
00407
00408
00409
00410 *ElapsedDays = Temp.LowPart;
00411
00412
00413
00414
00415
00416
00417
00418 Temp.QuadPart =
ConvertDaysToMilliseconds( *ElapsedDays );
00419
00420 Temp.QuadPart = TotalMilliseconds.QuadPart - Temp.QuadPart;
00421
00422
00423
00424
00425
00426
00427 *Milliseconds = Temp.LowPart;
00428
00429
00430
00431
00432
00433
return;
00434 }
00435
00436
00437
00438
00439
00440
00441
00442
VOID
00443 DaysAndFractionToTime (
00444 IN ULONG ElapsedDays,
00445 IN ULONG Milliseconds,
00446 OUT PLARGE_INTEGER Time
00447 )
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 {
00471 LARGE_INTEGER Temp;
00472 LARGE_INTEGER Temp2;
00473
00474
00475
00476
00477
00478 Temp.QuadPart =
ConvertDaysToMilliseconds( ElapsedDays );
00479
00480
00481
00482
00483
00484 Temp2.LowPart = Milliseconds;
00485 Temp2.HighPart = 0;
00486
00487
00488
00489
00490
00491 Temp.QuadPart = Temp.QuadPart + Temp2.QuadPart;
00492
00493
00494
00495
00496
00497 *(PLARGE_INTEGER)
Time =
ConvertMillisecondsTo100ns( Temp );
00498
00499
00500
00501
00502
00503
return;
00504 }
00505
00506
00507
VOID
00508 RtlTimeToTimeFields (
00509 IN PLARGE_INTEGER Time,
00510 OUT PTIME_FIELDS TimeFields
00511 )
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534 {
00535 ULONG Years;
00536 ULONG Month;
00537 ULONG Days;
00538
00539 ULONG Hours;
00540 ULONG Minutes;
00541 ULONG Seconds;
00542 ULONG Milliseconds;
00543
00544
00545
00546
00547
00548
00549
TimeToDaysAndFraction(
Time, &Days, &Milliseconds );
00550
00551
00552
00553
00554
00555
00556
00557
00558
TimeFields->Weekday = (CSHORT)((Days +
WEEKDAY_OF_1601) % 7);
00559
00560
00561
00562
00563
00564
00565 Years =
ElapsedDaysToYears( Days );
00566
00567
00568
00569
00570
00571
00572
00573 Days = Days -
ElapsedYearsToDays( Years );
00574
00575
00576
00577
00578
00579
00580
00581
if (
IsLeapYear( Years + 1 )) {
00582
00583
00584
00585
00586
00587
00588
00589 Month =
LeapYearDayToMonth[Days];
00590 Days = Days -
LeapYearDaysPrecedingMonth[Month];
00591
00592 }
else {
00593
00594
00595
00596
00597
00598
00599 Month =
NormalYearDayToMonth[Days];
00600 Days = Days -
NormalYearDaysPrecedingMonth[Month];
00601
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615 Seconds = Milliseconds / 1000;
00616 Milliseconds = Milliseconds % 1000;
00617
00618
00619
00620
00621
00622
00623 Minutes = Seconds / 60;
00624 Seconds = Seconds % 60;
00625
00626
00627
00628
00629
00630
00631 Hours = Minutes / 60;
00632 Minutes = Minutes % 60;
00633
00634
00635
00636
00637
00638
00639
TimeFields->Year = (CSHORT)(Years + 1601);
00640
TimeFields->Month = (CSHORT)(Month + 1);
00641
TimeFields->Day = (CSHORT)(Days + 1);
00642
TimeFields->Hour = (CSHORT)Hours;
00643
TimeFields->Minute = (CSHORT)Minutes;
00644
TimeFields->Second = (CSHORT)Seconds;
00645
TimeFields->Milliseconds = (CSHORT)Milliseconds;
00646
00647
00648
00649
00650
00651
return;
00652 }
00653
00654 BOOLEAN
00655 RtlCutoverTimeToSystemTime(
00656 PTIME_FIELDS CutoverTime,
00657 PLARGE_INTEGER SystemTime,
00658 PLARGE_INTEGER CurrentSystemTime,
00659 BOOLEAN ThisYear
00660 )
00661 {
00662 TIME_FIELDS CurrentTimeFields;
00663
00664
00665
00666
00667
00668
RtlTimeToTimeFields(CurrentSystemTime,&CurrentTimeFields);
00669
00670
00671
00672
00673
00674
00675
if ( CutoverTime->Year ) {
00676
00677
00678
00679
00680
00681
00682
if ( !
RtlTimeFieldsToTime(CutoverTime,SystemTime) ) {
00683
return FALSE;
00684 }
00685
00686
if (SystemTime->QuadPart < CurrentSystemTime->QuadPart) {
00687
return FALSE;
00688 }
00689
return TRUE;
00690 }
00691
else {
00692
00693 TIME_FIELDS WorkingTimeField;
00694 TIME_FIELDS ScratchTimeField;
00695 LARGE_INTEGER ScratchTime;
00696 CSHORT BestWeekdayDate;
00697 CSHORT WorkingWeekdayNumber;
00698 CSHORT TargetWeekdayNumber;
00699 CSHORT TargetYear;
00700 CSHORT TargetMonth;
00701 CSHORT TargetWeekday;
00702 BOOLEAN MonthMatches;
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714 TargetWeekdayNumber = CutoverTime->Day;
00715
if ( TargetWeekdayNumber > 5 || TargetWeekdayNumber == 0 ) {
00716
return FALSE;
00717 }
00718 TargetWeekday = CutoverTime->Weekday;
00719 TargetMonth = CutoverTime->Month;
00720 MonthMatches =
FALSE;
00721
if ( !ThisYear ) {
00722
if ( TargetMonth < CurrentTimeFields.Month ) {
00723 TargetYear = CurrentTimeFields.Year + 1;
00724 }
00725
else if ( TargetMonth > CurrentTimeFields.Month ) {
00726 TargetYear = CurrentTimeFields.Year;
00727 }
00728
else {
00729 TargetYear = CurrentTimeFields.Year;
00730 MonthMatches =
TRUE;
00731 }
00732 }
00733
else {
00734 TargetYear = CurrentTimeFields.Year;
00735 }
00736 try_next_year:
00737 BestWeekdayDate = 0;
00738
00739 WorkingTimeField.Year = TargetYear;
00740 WorkingTimeField.Month = TargetMonth;
00741 WorkingTimeField.Day = 1;
00742 WorkingTimeField.Hour = CutoverTime->Hour;
00743 WorkingTimeField.Minute = CutoverTime->Minute;
00744 WorkingTimeField.Second = CutoverTime->Second;
00745 WorkingTimeField.Milliseconds = CutoverTime->Milliseconds;
00746 WorkingTimeField.Weekday = 0;
00747
00748
00749
00750
00751
00752
00753
if ( !
RtlTimeFieldsToTime(&WorkingTimeField,&ScratchTime) ) {
00754
return FALSE;
00755 }
00756
RtlTimeToTimeFields(&ScratchTime,&ScratchTimeField);
00757
00758
00759
00760
00761
if ( ScratchTimeField.Weekday > TargetWeekday ) {
00762 WorkingTimeField.Day += (7-(ScratchTimeField.Weekday - TargetWeekday));
00763 }
00764
else if ( ScratchTimeField.Weekday < TargetWeekday ) {
00765 WorkingTimeField.Day += (TargetWeekday - ScratchTimeField.Weekday);
00766 }
00767
00768
00769
00770
00771
00772 BestWeekdayDate = WorkingTimeField.Day;
00773 WorkingWeekdayNumber = 1;
00774
00775
00776
00777
00778
00779
00780
while ( WorkingWeekdayNumber < TargetWeekdayNumber ) {
00781 WorkingTimeField.Day += 7;
00782
if ( !
RtlTimeFieldsToTime(&WorkingTimeField,&ScratchTime) ) {
00783
break;
00784 }
00785
RtlTimeToTimeFields(&ScratchTime,&ScratchTimeField);
00786 WorkingWeekdayNumber++;
00787 BestWeekdayDate = ScratchTimeField.Day;
00788 }
00789 WorkingTimeField.Day = BestWeekdayDate;
00790
00791
00792
00793
00794
00795
00796
if ( !
RtlTimeFieldsToTime(&WorkingTimeField,&ScratchTime) ) {
00797
return FALSE;
00798 }
00799
if ( MonthMatches ) {
00800
if ( WorkingTimeField.Day < CurrentTimeFields.Day ) {
00801 MonthMatches =
FALSE;
00802 TargetYear++;
00803
goto try_next_year;
00804 }
00805
if ( WorkingTimeField.Day == CurrentTimeFields.Day ) {
00806
00807
if (ScratchTime.QuadPart < CurrentSystemTime->QuadPart) {
00808 MonthMatches =
FALSE;
00809 TargetYear++;
00810
goto try_next_year;
00811 }
00812 }
00813 }
00814 *SystemTime = ScratchTime;
00815
00816
return TRUE;
00817 }
00818 }
00819
00820
00821 BOOLEAN
00822 RtlTimeFieldsToTime (
00823 IN PTIME_FIELDS TimeFields,
00824 OUT PLARGE_INTEGER Time
00825 )
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847 {
00848 ULONG Year;
00849 ULONG Month;
00850 ULONG Day;
00851 ULONG Hour;
00852 ULONG Minute;
00853 ULONG Second;
00854 ULONG Milliseconds;
00855
00856 ULONG ElapsedDays;
00857 ULONG ElapsedMilliseconds;
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868 Year =
TimeFields->Year;
00869 Month =
TimeFields->Month - 1;
00870 Day =
TimeFields->Day - 1;
00871 Hour =
TimeFields->Hour;
00872 Minute =
TimeFields->Minute;
00873 Second =
TimeFields->Second;
00874 Milliseconds =
TimeFields->Milliseconds;
00875
00876
00877
00878
00879
00880
00881
if ((
TimeFields->Month < 1) ||
00882 (
TimeFields->Day < 1) ||
00883 (Year < 1601) ||
00884 (Month > 11) ||
00885 ((CSHORT)Day >=
MaxDaysInMonth(Year, Month)) ||
00886 (Hour > 23) ||
00887 (Minute > 59) ||
00888 (Second > 59) ||
00889 (Milliseconds > 999)) {
00890
00891
return FALSE;
00892
00893 }
00894
00895
00896
00897
00898
00899
00900 ElapsedDays =
ElapsedYearsToDays( Year - 1601 );
00901
00902
if (
IsLeapYear( Year - 1600 )) {
00903
00904 ElapsedDays +=
LeapYearDaysPrecedingMonth[ Month ];
00905
00906 }
else {
00907
00908 ElapsedDays +=
NormalYearDaysPrecedingMonth[ Month ];
00909
00910 }
00911
00912 ElapsedDays += Day;
00913
00914
00915
00916
00917
00918
00919 ElapsedMilliseconds = (((Hour*60) + Minute)*60 + Second)*1000 + Milliseconds;
00920
00921
00922
00923
00924
00925
00926
DaysAndFractionToTime( ElapsedDays, ElapsedMilliseconds,
Time );
00927
00928
00929
00930
00931
00932
return TRUE;
00933 }
00934
00935
00936
VOID
00937 RtlTimeToElapsedTimeFields (
00938 IN PLARGE_INTEGER Time,
00939 OUT PTIME_FIELDS TimeFields
00940 )
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963 {
00964 ULONG Days;
00965 ULONG Hours;
00966 ULONG Minutes;
00967 ULONG Seconds;
00968 ULONG Milliseconds;
00969
00970
00971
00972
00973
00974
00975
TimeToDaysAndFraction(
Time, &Days, &Milliseconds );
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988 Seconds = Milliseconds / 1000;
00989 Milliseconds = Milliseconds % 1000;
00990
00991
00992
00993
00994
00995
00996 Minutes = Seconds / 60;
00997 Seconds = Seconds % 60;
00998
00999
01000
01001
01002
01003
01004 Hours = Minutes / 60;
01005 Minutes = Minutes % 60;
01006
01007
01008
01009
01010
01011
01012
TimeFields->Year = 0;
01013
TimeFields->Month = 0;
01014
TimeFields->Day = (CSHORT)Days;
01015
TimeFields->Hour = (CSHORT)Hours;
01016
TimeFields->Minute = (CSHORT)Minutes;
01017
TimeFields->Second = (CSHORT)Seconds;
01018
TimeFields->Milliseconds = (CSHORT)Milliseconds;
01019
01020
01021
01022
01023
01024
return;
01025 }
01026
01027
01028 BOOLEAN
01029 RtlTimeToSecondsSince1980 (
01030 IN PLARGE_INTEGER Time,
01031 OUT PULONG ElapsedSeconds
01032 )
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 {
01057 LARGE_INTEGER Seconds;
01058
01059
01060
01061
01062
01063 Seconds =
Convert100nsToSeconds( *(PLARGE_INTEGER)
Time );
01064
01065
01066
01067
01068
01069 Seconds.QuadPart = Seconds.QuadPart -
SecondsToStartOf1980.QuadPart;
01070
01071
01072
01073
01074
01075
01076
01077
if (Seconds.HighPart != 0) {
01078
01079
return FALSE;
01080
01081 }
01082
01083
01084
01085
01086
01087 *ElapsedSeconds = Seconds.LowPart;
01088
01089
01090
01091
01092
01093
return TRUE;
01094 }
01095
01096
01097
VOID
01098 RtlSecondsSince1980ToTime (
01099 IN ULONG ElapsedSeconds,
01100 OUT PLARGE_INTEGER Time
01101 )
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123 {
01124 LARGE_INTEGER Seconds;
01125
01126
01127
01128
01129
01130 Seconds.LowPart = ElapsedSeconds;
01131 Seconds.HighPart = 0;
01132
01133
01134
01135
01136
01137 Seconds.QuadPart = Seconds.QuadPart +
SecondsToStartOf1980.QuadPart;
01138
01139
01140
01141
01142
01143 *(PLARGE_INTEGER)
Time =
ConvertSecondsTo100ns( Seconds );
01144
01145
01146
01147
01148
01149
return;
01150 }
01151
01152
01153 BOOLEAN
01154 RtlTimeToSecondsSince1970 (
01155 IN PLARGE_INTEGER Time,
01156 OUT PULONG ElapsedSeconds
01157 )
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181 {
01182 LARGE_INTEGER Seconds;
01183
01184
01185
01186
01187
01188 Seconds =
Convert100nsToSeconds( *(PLARGE_INTEGER)
Time );
01189
01190
01191
01192
01193
01194 Seconds.QuadPart = Seconds.QuadPart -
SecondsToStartOf1970.QuadPart;
01195
01196
01197
01198
01199
01200
01201
01202
if (Seconds.HighPart != 0) {
01203
01204
return FALSE;
01205
01206 }
01207
01208
01209
01210
01211
01212 *ElapsedSeconds = Seconds.LowPart;
01213
01214
01215
01216
01217
01218
return TRUE;
01219 }
01220
01221
01222
VOID
01223 RtlSecondsSince1970ToTime (
01224 IN ULONG ElapsedSeconds,
01225 OUT PLARGE_INTEGER Time
01226 )
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248 {
01249 LARGE_INTEGER Seconds;
01250
01251
01252
01253
01254
01255 Seconds.LowPart = ElapsedSeconds;
01256 Seconds.HighPart = 0;
01257
01258
01259
01260
01261
01262 Seconds.QuadPart = Seconds.QuadPart +
SecondsToStartOf1970.QuadPart;
01263
01264
01265
01266
01267
01268 *(PLARGE_INTEGER)
Time =
ConvertSecondsTo100ns( Seconds );
01269
01270
01271
01272
01273
01274
return;
01275 }
01276
01277
NTSTATUS
01278 RtlSystemTimeToLocalTime (
01279 IN PLARGE_INTEGER SystemTime,
01280 OUT PLARGE_INTEGER LocalTime
01281 )
01282 {
01283
NTSTATUS Status;
01284 SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay;
01285
01286
Status = ZwQuerySystemInformation(
01287 SystemTimeOfDayInformation,
01288 &TimeOfDay,
01289
sizeof(TimeOfDay),
01290
NULL
01291 );
01292
if ( !
NT_SUCCESS(
Status) ) {
01293
return Status;
01294 }
01295
01296
01297
01298
01299
01300 LocalTime->QuadPart = SystemTime->QuadPart - TimeOfDay.TimeZoneBias.QuadPart;
01301
01302
return STATUS_SUCCESS;
01303 }
01304
01305
NTSTATUS
01306 RtlLocalTimeToSystemTime (
01307 IN PLARGE_INTEGER LocalTime,
01308 OUT PLARGE_INTEGER SystemTime
01309 )
01310 {
01311
01312
NTSTATUS Status;
01313 SYSTEM_TIMEOFDAY_INFORMATION TimeOfDay;
01314
01315
Status = ZwQuerySystemInformation(
01316 SystemTimeOfDayInformation,
01317 &TimeOfDay,
01318
sizeof(TimeOfDay),
01319
NULL
01320 );
01321
if ( !
NT_SUCCESS(
Status) ) {
01322
return Status;
01323 }
01324
01325
01326
01327
01328
01329 SystemTime->QuadPart = LocalTime->QuadPart + TimeOfDay.TimeZoneBias.QuadPart;
01330
01331
return STATUS_SUCCESS;
01332 }