Skip to content

Commit

Permalink
add-DateTime*.TryParseExact (#233)
Browse files Browse the repository at this point in the history
* add DateTime*.TryParseExact

* .

* .
  • Loading branch information
SimonCropp authored Oct 2, 2024
1 parent 79f5d54 commit 99ca541
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apiCount.include.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**API count: 363**
**API count: 365**
2 changes: 2 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetime@))
* `Boolean TryParse(ReadOnlySpan<Char>, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-datetime@))
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, Globalization.DateTimeStyles, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@))
* `Boolean TryParseExact(ReadOnlySpan<Char>, String, IFormatProvider, Globalization.DateTimeStyles, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@))


#### DateTimeOffsetPolyfill
Expand All @@ -473,6 +474,7 @@
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetimeoffset@))
* `Boolean TryParse(ReadOnlySpan<Char>, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-datetimeoffset@))
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, Globalization.DateTimeStyles, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@))
* `Boolean TryParseExact(ReadOnlySpan<Char>, String, IFormatProvider, Globalization.DateTimeStyles, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparseexact#system-datetimeoffset-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@))


#### DoublePolyfill
Expand Down
11 changes: 10 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
* `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0`


**API count: 360**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
**API count: 365**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->


**See [Milestones](../../milestones?state=closed) for release notes.**
Expand Down Expand Up @@ -905,12 +905,20 @@ The class `Polyfill` includes the following extension methods:
* `Boolean TryParse(ReadOnlySpan<Char>, Globalization.NumberStyles, IFormatProvider, Byte&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse#system-byte-tryparse(system-readonlyspan((system-char))-system-globalization-numberstyles-system-iformatprovider-system-byte@))


#### GuidPolyfill

* `Boolean TryParse(String, IFormatProvider, Guid&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse#system-guid-tryparse(system-string-system-iformatprovider-system-guid@))
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, Guid&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse#system-guid-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-guid@))
* `Boolean TryParse(ReadOnlySpan<Char>, Guid&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.guid.tryparse?view=net-8.0#system-guid-tryparse(system-readonlyspan((system-char))-system-guid@))


#### DateTimePolyfill

* `Boolean TryParse(String, IFormatProvider, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-string-system-iformatprovider-system-datetime@))
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetime@))
* `Boolean TryParse(ReadOnlySpan<Char>, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-datetime@))
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, Globalization.DateTimeStyles, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@))
* `Boolean TryParseExact(ReadOnlySpan<Char>, String, IFormatProvider, Globalization.DateTimeStyles, DateTime&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@))


#### DateTimeOffsetPolyfill
Expand All @@ -919,6 +927,7 @@ The class `Polyfill` includes the following extension methods:
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-datetimeoffset@))
* `Boolean TryParse(ReadOnlySpan<Char>, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-datetimeoffset@))
* `Boolean TryParse(ReadOnlySpan<Char>, IFormatProvider, Globalization.DateTimeStyles, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@))
* `Boolean TryParseExact(ReadOnlySpan<Char>, String, IFormatProvider, Globalization.DateTimeStyles, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparseexact#system-datetimeoffset-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@))


#### DoublePolyfill
Expand Down
11 changes: 11 additions & 0 deletions src/Polyfill/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,16 @@ public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider
DateTimeOffset.TryParse(target.ToString(), provider, styles, out result);
#endif

/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparseexact#system-datetimeoffset-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetimeoffset@)")]
public static bool TryParseExact(ReadOnlySpan<char> target, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTimeOffset result) =>
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
DateTimeOffset.TryParseExact(target, format, provider, styles, out result);
#else
DateTimeOffset.TryParseExact(target.ToString(), format, provider, styles, out result);
#endif

#endif
}
11 changes: 11 additions & 0 deletions src/Polyfill/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,16 @@ public static bool TryParse(ReadOnlySpan<char> target, IFormatProvider? provider
DateTime.TryParse(target.ToString(), provider, styles, out result);
#endif

/// <summary>
/// Tries to parse a span of characters into a value.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-readonlyspan((system-char))-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)")]
public static bool TryParseExact(ReadOnlySpan<char> target, string format, IFormatProvider? provider, DateTimeStyles styles, out DateTime result) =>
#if NETSTANDARD2_1 || NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
DateTime.TryParseExact(target, format, provider, styles, out result);
#else
DateTime.TryParseExact(target.ToString(), format, provider, styles, out result);
#endif

#endif
}

0 comments on commit 99ca541

Please sign in to comment.