Fix up null check in Timestamps.TryParse

Signed-off-by: Safia Abdalla <safia@safia.rocks>
This commit is contained in:
Safia Abdalla 2024-03-06 10:41:09 -08:00
parent 915b465129
commit c7c4cbc62e
2 changed files with 10 additions and 6 deletions

View File

@ -44,13 +44,16 @@ namespace CloudNative.CloudEvents
/// <summary>
/// Attempts to parse a string as an RFC-3339-formatted date/time and UTC offset.
/// </summary>
/// <param name="input"></param>
/// <param name="result"></param>
/// <returns></returns>
/// <param name="input">A string to be parsed as a <see cref="DateTimeOffset"/>.</param>
/// <param name="result">A <see cref="DateTimeOffset"/> parsed from the <paramref name="input"/>.</param>
/// <returns><see langword="true"/> if <paramref name="input"/> was parsed successfully, <see langword="false"/> otherwise.</returns>
public static bool TryParse(string input, out DateTimeOffset result)
{
// TODO: Check this and add a test
Validation.CheckNotNull(input, nameof(input));
if (string.IsNullOrEmpty(input))
{
result = default;
return false;
}
if (input.Length < MinLength) // "yyyy-MM-ddTHH:mm:ssZ" is the shortest possible value.
{

View File

@ -1,4 +1,4 @@
// Copyright 2021 Cloud Native Foundation.
// Copyright 2021 Cloud Native Foundation.
// Licensed under the Apache 2.0 license.
// See LICENSE file in the project root for full license information.
@ -89,6 +89,7 @@ namespace CloudNative.CloudEvents.UnitTests
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData("garbage")]
[InlineData("garbage that is long enough")]