Skip to content

Commit 35ee506

Browse files
ericstjtarekgh
andauthored
Apply suggestions from code review
Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com>
1 parent 1a5246d commit 35ee506

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/libraries/System.Management/src/System/Management/ManagementDateTime.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static DateTime ToDateTime(string dmtfDate)
193193
throw new ArgumentOutOfRangeException(nameof(dmtfDate));
194194
}
195195

196-
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - DateTime not constructed from multiple elements - it's parsed from a string.
196+
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - DateTime not constructed from multiple elements - it's parsed from a string with defaults that are stable DateTime.MinValue. It would be intentional to throw if an invalid combination occurred.
197197
var datetime = new DateTime(year, month, day, hour, minute, second, 0, DateTimeKind.Local);
198198
// Then add the ticks calculated from the microseconds
199199
datetime = datetime.AddTicks(ticks);

src/libraries/System.Private.CoreLib/src/System/DateTime.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second)
332332
else
333333
{
334334
// if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute.
335-
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - DateTime is constructed using the user specifed values, not a combination of different sources.
335+
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - DateTime is constructed using the user specified values, not a combination of different sources. It would be intentional to throw if an invalid combination occurred.
336336
this = new DateTime(year, month, day, hour, minute, 59);
337337
ValidateLeapSecond();
338338
}

src/libraries/System.Private.CoreLib/src/System/Globalization/GregorianCalendarHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal EraInfo(int era, int startYear, int startMonth, int startDay, int yearO
3535
this.yearOffset = yearOffset;
3636
this.minEraYear = minEraYear;
3737
this.maxEraYear = maxEraYear;
38-
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - DateTime is constructed using the user specifed values, not a combination of different sources.
38+
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - A DateTime object is created using values obtained from the machine configuration.
3939
this.ticks = new DateTime(startYear, startMonth, startDay).Ticks;
4040
this.eraName = eraName;
4141
this.abbrevEraName = abbrevEraName;

src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public static implicit operator DateTime(XsdDateTime xdt)
396396
{
397397
case DateTimeTypeCode.GMonth:
398398
case DateTimeTypeCode.GDay:
399-
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - DateTime not constructed from multiple elements - it's converted from an XsdDateTime.
399+
// codeql[cs/leap-year/unsafe-date-construction-from-two-elements] - The XML specification does not explicitly define this behavior for parsing in a non-leap year. We intentionally throw here. Altering this behavior to be more resilient, producing dates like 2/28 or 3/1, could introduce unintended consequences and may not be desirable for user.
400400
result = new DateTime(DateTime.Now.Year, xdt.Month, xdt.Day);
401401
break;
402402
case DateTimeTypeCode.Time:

0 commit comments

Comments
 (0)