-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix for XSLT extension methods format-date & format-time #114200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Maximys
wants to merge
10
commits into
dotnet:main
from
Maximys:bugfix/93189-xslt-format-date-and-format-time-fix
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ab48c7b
fix(#93189): Fix invalid test.
Maximys 4dc4d13
refactor(#93189): Changing tabs to spaces.
Maximys 27a44ee
feat(#93189): Adding test case for check working with fractional.
Maximys 3de59e5
refactor(#93189): Replacing some "InlineDataAttribute" by "MemberData…
Maximys 84b163f
refactor(#93189): Refactoring some tests.
Maximys 95ff95a
refactor(#93189): Extracting "XsdDateTimeParser" and it's environment…
Maximys dea09ad
refactor(#93189): Refactoring of "XsdDateTimeParser".
Maximys 0f4201c
refactor(#93189): Renaming "System.Xml.Schema.DateAndTime.Parsers.Xsd…
Maximys 7a30df2
fix(#93189): Fix functionality of "ms:format-date" function.
Maximys 6bdbe81
fix(#93189): Fix functionality of "ms:format-time" function.
Maximys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
644 changes: 644 additions & 0 deletions
644
...s/System.Private.Xml/src/System/Xml/Schema/DateAndTime/Converters/DateAndTimeConverter.cs
Large diffs are not rendered by default.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
...libraries/System.Private.Xml/src/System/Xml/Schema/DateAndTime/Helpers/DateAndTimeInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Xml.Schema.DateAndTime.Specifications; | ||
|
|
||
| namespace System.Xml.Schema.DateAndTime.Helpers | ||
| { | ||
| internal struct DateAndTimeInfo | ||
| { | ||
| public DateInfo Date { get; } | ||
| public XsdDateTimeKind Kind { get; } | ||
| public TimeInfo Time { get; } | ||
| public DateTimeTypeCode TypeCode { get; } | ||
| public int ZoneHour { get; } | ||
| public int ZoneMinute { get; } | ||
|
|
||
| public DateAndTimeInfo( | ||
| DateInfo date, | ||
| XsdDateTimeKind kind, | ||
| TimeInfo time, | ||
| DateTimeTypeCode typeCode, | ||
| int zoneHour, | ||
| int zoneMinute) | ||
| { | ||
| Date = date; | ||
| Kind = kind; | ||
| Time = time; | ||
| TypeCode = typeCode; | ||
| ZoneHour = zoneHour; | ||
| ZoneMinute = zoneMinute; | ||
| } | ||
|
|
||
| public DateAndTimeInfo() | ||
| : this( | ||
| default, | ||
| XsdDateTimeKind.Unspecified, | ||
| default, | ||
| default, | ||
| 0, | ||
| 0) | ||
| { | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
src/libraries/System.Private.Xml/src/System/Xml/Schema/DateAndTime/Helpers/DateInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Xml.Schema.DateAndTime.Helpers | ||
| { | ||
| internal struct DateInfo | ||
| { | ||
| public static readonly DateInfo DefaultValue = new DateInfo(FirstDay, FirstMonth, LeapYear); | ||
|
|
||
| public const int FirstDay = 1; | ||
| public const int FirstMonth = 1; | ||
| public const int LeapYear = 1904; | ||
|
|
||
| public int Day { get; } | ||
| public int Month { get; } | ||
| public int Year { get; } | ||
|
|
||
| public DateInfo(int day, int month, int year) | ||
| { | ||
| Day = day; | ||
| Month = month; | ||
| Year = year; | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/libraries/System.Private.Xml/src/System/Xml/Schema/DateAndTime/Helpers/TimeInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Xml.Schema.DateAndTime.Helpers | ||
| { | ||
| internal struct TimeInfo | ||
| { | ||
| public int Fraction { get; } | ||
| public int Hour { get; } | ||
| public int Microsecond | ||
| { | ||
| get | ||
| { | ||
| return Convert.ToInt32((Fraction % TimeSpan.TicksPerMillisecond) / TimeSpan.TicksPerMicrosecond); | ||
| } | ||
| } | ||
|
|
||
| public int Millisecond | ||
| { | ||
| get | ||
| { | ||
| return Convert.ToInt32(Fraction / TimeSpan.TicksPerMillisecond); | ||
| } | ||
| } | ||
|
|
||
| public int Minute { get; } | ||
| public int Second { get; } | ||
|
|
||
| public TimeInfo(int fraction, int hour, int minute, int second) | ||
| { | ||
| Fraction = fraction; | ||
| Hour = hour; | ||
| Minute = minute; | ||
| Second = second; | ||
| } | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...s/System.Private.Xml/src/System/Xml/Schema/DateAndTime/Specifications/DateTimeTypeCode.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Xml.Schema.DateAndTime.Specifications | ||
| { | ||
| /// <summary> | ||
| /// Subset of represented XML Schema types. | ||
| /// </summary> | ||
| internal enum DateTimeTypeCode | ||
| { | ||
| DateTime, | ||
| Time, | ||
| Date, | ||
| GYearMonth, | ||
| GYear, | ||
| GMonthDay, | ||
| GDay, | ||
| GMonth, | ||
| XdrDateTime, | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
...es/System.Private.Xml/src/System/Xml/Schema/DateAndTime/Specifications/XsdDateTimeKind.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Xml.Schema.DateAndTime.Specifications | ||
| { | ||
| /// <summary> | ||
| /// Internal representation of <see cref="System.DateTimeKind"/>. | ||
| /// </summary> | ||
| internal enum XsdDateTimeKind | ||
| { | ||
| Unspecified, | ||
| Zulu, | ||
| LocalWestOfZulu, // GMT-1..14, N..Y | ||
| LocalEastOfZulu // GMT+1..14, A..M | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/libraries/System.Private.Xml/src/System/Xml/Schema/DateAndTime/XsdDate.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Xml.Schema.DateAndTime.Converters; | ||
| using System.Xml.Schema.DateAndTime.Helpers; | ||
|
|
||
| namespace System.Xml.Schema.DateAndTime | ||
| { | ||
| internal struct XsdDate : IFormattable | ||
| { | ||
| private DateOnly Date { get; set; } | ||
|
|
||
| private XsdDate(DateInfo parsedValue) | ||
| : this() | ||
| { | ||
| Date = new DateOnly(parsedValue.Year, parsedValue.Month, parsedValue.Day); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string ToString(string? format, IFormatProvider? formatProvider) | ||
| { | ||
| return Date.ToString(format, formatProvider); | ||
| } | ||
|
|
||
| internal static bool TryParse(string text, out XsdDate result) | ||
| { | ||
| if (!DateAndTimeConverter.TryParse(text, out DateInfo parsedValue)) | ||
| { | ||
| result = default; | ||
| return false; | ||
| } | ||
|
|
||
| result = new XsdDate(parsedValue); | ||
| return true; | ||
| } | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/libraries/System.Private.Xml/src/System/Xml/Schema/DateAndTime/XsdTime.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Xml.Schema.DateAndTime.Converters; | ||
| using System.Xml.Schema.DateAndTime.Helpers; | ||
|
|
||
| namespace System.Xml.Schema.DateAndTime | ||
| { | ||
| internal struct XsdTime : IFormattable | ||
| { | ||
| private TimeOnly Time { get; set; } | ||
|
|
||
| private XsdTime(TimeInfo parsedValue) | ||
| : this() | ||
| { | ||
| Time = new TimeOnly( | ||
| parsedValue.Hour, | ||
| parsedValue.Minute, | ||
| parsedValue.Second, | ||
| parsedValue.Millisecond, | ||
| parsedValue.Microsecond); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public string ToString(string? format, IFormatProvider? formatProvider) | ||
| { | ||
| return Time.ToString(format, formatProvider); | ||
| } | ||
|
|
||
| internal static bool TryParse(string text, out XsdTime result) | ||
| { | ||
| if (!DateAndTimeConverter.TryParse(text, out TimeInfo parsedValue)) | ||
| { | ||
| result = default; | ||
| return false; | ||
| } | ||
|
|
||
| result = new XsdTime(parsedValue); | ||
| return true; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to introduce extra data structures? The original code didn't seem to have them