RtlCutoverTimeToSystemTime(): The 4th argument determines whether the cutover time...
authorEric Kohl <eric.kohl@reactos.org>
Fri, 7 Jan 2005 12:58:46 +0000 (12:58 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 7 Jan 2005 12:58:46 +0000 (12:58 +0000)
svn path=/trunk/; revision=12864

reactos/include/ntos/rtl.h
reactos/lib/rtl/time.c

index c800fcd..b4fc9c4 100755 (executable)
@@ -112,7 +112,7 @@ static __inline VOID
 InsertHeadList(
        IN PLIST_ENTRY  ListHead,
        IN PLIST_ENTRY  Entry)
-{ 
+{
        PLIST_ENTRY OldFlink;
        OldFlink = ListHead->Flink;
        Entry->Flink = OldFlink;
@@ -140,7 +140,7 @@ static __inline VOID
 InsertTailList(
        IN PLIST_ENTRY  ListHead,
        IN PLIST_ENTRY  Entry)
-{ 
+{
        PLIST_ENTRY OldBlink;
        OldBlink = ListHead->Blink;
        Entry->Flink = ListHead;
@@ -882,7 +882,7 @@ BOOLEAN STDCALL
 RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,
                            OUT PLARGE_INTEGER SystemTime,
                            IN PLARGE_INTEGER CurrentTime,
-                           IN ULONG Unknown);
+                           IN BOOLEAN ThisYearsCutoverOnly);
 
 NTSTATUS STDCALL
 RtlDecompressBuffer(IN USHORT CompressionFormat,
index b84b146..3e5d543 100644 (file)
@@ -74,7 +74,7 @@ BOOLEAN STDCALL
 RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,
                            OUT PLARGE_INTEGER SystemTime,
                            IN PLARGE_INTEGER CurrentTime,
-                           IN ULONG Unknown)
+                           IN BOOLEAN ThisYearsCutoverOnly)
 {
   TIME_FIELDS AdjustedTimeFields;
   TIME_FIELDS CurrentTimeFields;
@@ -82,6 +82,7 @@ RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,
   LARGE_INTEGER CutoverSystemTime;
   CSHORT MonthLength;
   CSHORT Days;
+  BOOLEAN NextYearsCutover = FALSE;
 
   /* Check fixed cutover time */
   if (CutoverTimeFields->Year != 0)
@@ -105,44 +106,59 @@ RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,
 
   RtlTimeToTimeFields(CurrentTime, &CurrentTimeFields);
 
-  /* Compute the cutover time of the first day of the current month */
-  AdjustedTimeFields.Year = CurrentTimeFields.Year;
-  AdjustedTimeFields.Month = CutoverTimeFields->Month;
-  AdjustedTimeFields.Day = 1;
-  AdjustedTimeFields.Hour = CutoverTimeFields->Hour;
-  AdjustedTimeFields.Minute = CutoverTimeFields->Minute;
-  AdjustedTimeFields.Second = CutoverTimeFields->Second;
-  AdjustedTimeFields.Milliseconds = CutoverTimeFields->Milliseconds;
+  while (TRUE)
+  {
+    /* Compute the cutover time of the first day of the current month */
+    AdjustedTimeFields.Year = CurrentTimeFields.Year;
+    if (NextYearsCutover == TRUE)
+      AdjustedTimeFields.Year++;
+
+    AdjustedTimeFields.Month = CutoverTimeFields->Month;
+    AdjustedTimeFields.Day = 1;
+    AdjustedTimeFields.Hour = CutoverTimeFields->Hour;
+    AdjustedTimeFields.Minute = CutoverTimeFields->Minute;
+    AdjustedTimeFields.Second = CutoverTimeFields->Second;
+    AdjustedTimeFields.Milliseconds = CutoverTimeFields->Milliseconds;
+
+    if (!RtlTimeFieldsToTime(&AdjustedTimeFields, &CutoverSystemTime))
+      return FALSE;
 
-  if (!RtlTimeFieldsToTime(&AdjustedTimeFields, &CutoverSystemTime))
-    return FALSE;
+    RtlTimeToTimeFields(&CutoverSystemTime, &CutoverSystemTimeFields);
 
-  RtlTimeToTimeFields(&CutoverSystemTime, &CutoverSystemTimeFields);
+    /* Adjust day to first matching weekday */
+    if (CutoverSystemTimeFields.Weekday != CutoverTimeFields->Weekday)
+    {
+      if (CutoverSystemTimeFields.Weekday < CutoverTimeFields->Weekday)
+        Days = CutoverTimeFields->Weekday - CutoverSystemTimeFields.Weekday;
+      else
+        Days = DAYSPERWEEK - (CutoverSystemTimeFields.Weekday - CutoverTimeFields->Weekday);
 
-  /* Adjust day to first matching weekday */
-  if (CutoverSystemTimeFields.Weekday != CutoverTimeFields->Weekday)
-  {
-    if (CutoverSystemTimeFields.Weekday < CutoverTimeFields->Weekday)
-      Days = CutoverTimeFields->Weekday - CutoverSystemTimeFields.Weekday;
-    else
-      Days = DAYSPERWEEK - (CutoverSystemTimeFields.Weekday - CutoverTimeFields->Weekday);
+      AdjustedTimeFields.Day += Days;
+    }
 
-    AdjustedTimeFields.Day += Days;
-  }
+    /* Adjust the number of weeks */
+    if (CutoverTimeFields->Day > 1)
+    {
+      Days = DAYSPERWEEK * (CutoverTimeFields->Day - 1);
+      MonthLength = MonthLengths[IsLeapYear(AdjustedTimeFields.Year)][AdjustedTimeFields.Month - 1];
+      if ((AdjustedTimeFields.Day + Days) > MonthLength)
+        Days -= DAYSPERWEEK;
 
-  /* Adjust the number of weeks */
-  if (CutoverTimeFields->Day > 1)
-  {
-    Days = DAYSPERWEEK * (CutoverTimeFields->Day - 1);
-    MonthLength = MonthLengths[IsLeapYear(AdjustedTimeFields.Year)][AdjustedTimeFields.Month - 1];
-    if ((AdjustedTimeFields.Day + Days) > MonthLength)
-      Days -= DAYSPERWEEK;
+      AdjustedTimeFields.Day += Days;
+    }
 
-    AdjustedTimeFields.Day += Days;
-  }
+    if (!RtlTimeFieldsToTime(&AdjustedTimeFields, &CutoverSystemTime))
+      return FALSE;
 
-  if (!RtlTimeFieldsToTime(&AdjustedTimeFields, &CutoverSystemTime))
-    return FALSE;
+    if (ThisYearsCutoverOnly == TRUE ||
+        NextYearsCutover == TRUE ||
+        CutoverSystemTime.QuadPart >= CurrentTime->QuadPart)
+    {
+      break;
+    }
+
+    NextYearsCutover = TRUE;
+  }
 
   SystemTime->QuadPart = CutoverSystemTime.QuadPart;