Skip to content

Commit

Permalink
add DateTimePolyfill and DateTimeOffsetPolyfill (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Oct 2, 2024
1 parent 047eb30 commit d76228e
Show file tree
Hide file tree
Showing 6 changed files with 174 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: 352**
**API count: 360**
16 changes: 16 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,22 @@
* `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@))


#### 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@))


#### DateTimeOffsetPolyfill

* `Boolean TryParse(String, IFormatProvider, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-string-system-iformatprovider-system-datetimeoffset@))
* `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@))


#### DoublePolyfill

* `Boolean TryParse(String, IFormatProvider, Double&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.double.tryparse#system-double-tryparse(system-string-system-iformatprovider-system-double@))
Expand Down
24 changes: 23 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: 352**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
**API count: 362**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->


**See [Milestones](../../milestones?state=closed) for release notes.**
Expand Down Expand Up @@ -905,6 +905,28 @@ 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<Byte>, IFormatProvider, Byte&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.byte.tryparse#system-byte-tryparse(system-readonlyspan((system-byte))-system-iformatprovider-system-byte@))


#### 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@))


#### DateTimeOffsetPolyfill

* `Boolean TryParse(String, IFormatProvider, DateTimeOffset&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-string-system-iformatprovider-system-datetimeoffset@))
* `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@))


#### DoublePolyfill

* `Boolean TryParse(String, IFormatProvider, Double&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.double.tryparse#system-double-tryparse(system-string-system-iformatprovider-system-double@))
Expand Down
66 changes: 66 additions & 0 deletions src/Polyfill/DateTimeOffsetPolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// <auto-generated />
#pragma warning disable

namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using Link = System.ComponentModel.DescriptionAttribute;

[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
#if PolyPublic
public
#endif
static partial class DateTimeOffsetPolyfill
{
/// <summary>
/// Tries to parse a string into a value.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.tryparse#system-datetimeoffset-tryparse(system-string-system-iformatprovider-system-datetimeoffset@)")]
public static bool TryParse(string? target, IFormatProvider? provider, out DateTimeOffset result) =>
#if NET7_0_OR_GREATER
DateTimeOffset.TryParse(target, provider, out result);
#else
DateTimeOffset.TryParse(target, provider, DateTimeStyles.None, out result);
#endif

#if FeatureMemory

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

#endif
}
66 changes: 66 additions & 0 deletions src/Polyfill/DateTimePolyfill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// <auto-generated />
#pragma warning disable

namespace Polyfills;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using Link = System.ComponentModel.DescriptionAttribute;

[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
#if PolyPublic
public
#endif
static partial class DateTimePolyfill
{
/// <summary>
/// Tries to parse a string into a value.
/// </summary>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparse#system-datetime-tryparse(system-string-system-iformatprovider-system-datetime@)")]
public static bool TryParse(string? target, IFormatProvider? provider, out DateTime result) =>
#if NET7_0_OR_GREATER
DateTime.TryParse(target, provider, out result);
#else
DateTime.TryParse(target, provider, DateTimeStyles.None, out result);
#endif

#if FeatureMemory

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

#endif
}
2 changes: 2 additions & 0 deletions src/Tests/BuildApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public void Run()
WriteHelper(types, "RegexPolyfill", writer, ref count);
WriteHelper(types, "StringPolyfill", writer, ref count);
WriteHelper(types, "BytePolyfill", writer, ref count);
WriteHelper(types, "DateTimePolyfill", writer, ref count);
WriteHelper(types, "DateTimeOffsetPolyfill", writer, ref count);
WriteHelper(types, "DoublePolyfill", writer, ref count);
WriteHelper(types, "IntPolyfill", writer, ref count);
WriteHelper(types, "LongPolyfill", writer, ref count);
Expand Down

0 comments on commit d76228e

Please sign in to comment.