Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ Type: `{0}`</value>
<value>The stability must follow the GraphQL type name rules.</value>
</data>
<data name="DateTimeOptions_InputPrecision_InvalidValue" xml:space="preserve">
<value>InputPrecision must be less than or equal to 7.</value>
<value>InputPrecision must be less than or equal to 9.</value>
</data>
<data name="DateTimeOptions_OutputPrecision_InvalidValue" xml:space="preserve">
<value>OutputPrecision must be less than or equal to 7.</value>
Expand Down
13 changes: 9 additions & 4 deletions src/HotChocolate/Core/src/Types/Types/Scalars/DateTimeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace HotChocolate.Types;
/// </summary>
public struct DateTimeOptions
{
public const byte DefaultInputPrecision = 7;
public const byte DefaultInputPrecision = 9;

// DateTimeOffset, DateTime, and TimeOnly all have a maximum of 7 fractional second digits.
public const byte DefaultOutputPrecision = 7;
Comment thread
glen-84 marked this conversation as resolved.

public DateTimeOptions()
Expand All @@ -17,17 +19,20 @@ public DateTimeOptions()

/// <summary>
/// Gets the maximum number of fractional second digits to expect when parsing date and time
/// input values.
/// input values. Note that the underlying .NET types (<see cref="DateTimeOffset"/>,
/// <see cref="DateTime"/>, and <see cref="TimeOnly"/>) have a maximum resolution of 7
/// fractional digits (100-nanosecond ticks), so digits beyond the 7th are rounded during
/// parsing.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when the value is greater than 7.
/// Thrown when the value is greater than 9.
/// </exception>
public byte InputPrecision
{
get;
init
{
if (value > 7)
if (value > 9)
{
throw new ArgumentOutOfRangeException(
nameof(InputPrecision),
Expand Down
14 changes: 13 additions & 1 deletion src/HotChocolate/Core/src/Types/Types/Scalars/DateTimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ private Regex GetDateTimeRegex()
4 => DateTimeRegex4(),
5 => DateTimeRegex5(),
6 => DateTimeRegex6(),
_ => DateTimeRegex7()
7 => DateTimeRegex7(),
8 => DateTimeRegex8(),
_ => DateTimeRegex9()
};

[GeneratedRegex(
Expand Down Expand Up @@ -238,4 +240,14 @@ private Regex GetDateTimeRegex()
@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,7})?(Z|[+-][0-9]{2}:[0-9]{2})\z",
RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase)]
private static partial Regex DateTimeRegex7();

[GeneratedRegex(
@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,8})?(Z|[+-][0-9]{2}:[0-9]{2})\z",
RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase)]
private static partial Regex DateTimeRegex8();

[GeneratedRegex(
@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,9})?(Z|[+-][0-9]{2}:[0-9]{2})\z",
RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase)]
private static partial Regex DateTimeRegex9();
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ private Regex GetLocalDateTimeRegex()
4 => LocalDateTimeRegex4(),
5 => LocalDateTimeRegex5(),
6 => LocalDateTimeRegex6(),
_ => LocalDateTimeRegex7()
7 => LocalDateTimeRegex7(),
8 => LocalDateTimeRegex8(),
_ => LocalDateTimeRegex9()
};

[GeneratedRegex(@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\z",
Expand Down Expand Up @@ -210,4 +212,12 @@ private Regex GetLocalDateTimeRegex()
[GeneratedRegex(@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,7})?\z",
RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase)]
private static partial Regex LocalDateTimeRegex7();

[GeneratedRegex(@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,8})?\z",
RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase)]
private static partial Regex LocalDateTimeRegex8();

[GeneratedRegex(@"^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,9})?\z",
RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase)]
private static partial Regex LocalDateTimeRegex9();
}
10 changes: 9 additions & 1 deletion src/HotChocolate/Core/src/Types/Types/Scalars/LocalTimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ private Regex GetLocalTimeRegex()
4 => LocalTimeRegex4(),
5 => LocalTimeRegex5(),
6 => LocalTimeRegex6(),
_ => LocalTimeRegex7()
7 => LocalTimeRegex7(),
8 => LocalTimeRegex8(),
_ => LocalTimeRegex9()
};

[GeneratedRegex(@"^[0-9]{2}:[0-9]{2}:[0-9]{2}\z", RegexOptions.ExplicitCapture)]
Expand All @@ -200,4 +202,10 @@ private Regex GetLocalTimeRegex()

[GeneratedRegex(@"^[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,7})?\z", RegexOptions.ExplicitCapture)]
private static partial Regex LocalTimeRegex7();

[GeneratedRegex(@"^[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,8})?\z", RegexOptions.ExplicitCapture)]
private static partial Regex LocalTimeRegex8();

[GeneratedRegex(@"^[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,9})?\z", RegexOptions.ExplicitCapture)]
private static partial Regex LocalTimeRegex9();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void DefaultConstructor_ShouldSetDefaultPrecisions()
public void DefaultConstants_ShouldBeCorrect()
{
// assert
Assert.Equal(7, DateTimeOptions.DefaultInputPrecision);
Assert.Equal(9, DateTimeOptions.DefaultInputPrecision);
Assert.Equal(7, DateTimeOptions.DefaultOutputPrecision);
}

Expand All @@ -30,6 +30,8 @@ public void DefaultConstants_ShouldBeCorrect()
[InlineData(5)]
[InlineData(6)]
[InlineData(7)]
[InlineData(8)]
[InlineData(9)]
public void InputPrecision_ValidValues_ShouldSet(byte precision)
{
// arrange & act
Expand Down Expand Up @@ -58,8 +60,6 @@ public void OutputPrecision_ValidValues_ShouldSet(byte precision)
}

[Theory]
[InlineData(8)]
[InlineData(9)]
[InlineData(10)]
[InlineData(255)]
public void InputPrecision_InvalidValues_ShouldThrow(byte precision)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ public void DateTime_Relaxed_Format_Check()
[InlineData(5, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,5})?(?:[Zz]|[+-]\d{2}:\d{2})$")]
[InlineData(6, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:[Zz]|[+-]\d{2}:\d{2})$")]
[InlineData(7, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,7})?(?:[Zz]|[+-]\d{2}:\d{2})$")]
[InlineData(8, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,8})?(?:[Zz]|[+-]\d{2}:\d{2})$")]
[InlineData(9, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:[Zz]|[+-]\d{2}:\d{2})$")]
public void Pattern_Should_Match_InputPrecision(byte precision, string expectedPattern)
{
// arrange & act
Expand All @@ -354,8 +356,8 @@ public static TheoryData<byte, string, DateTimeOffset> ValidInput()
},
{
DateTimeOptions.DefaultInputPrecision,
"2023-12-24T15:30:00.1234567+01:00",
new DateTimeOffset(2023, 12, 24, 15, 30, 0, 123, 456, TimeSpan.FromHours(1)).AddTicks(7)
"2023-12-24T15:30:00.123456789+01:00", // Rounded to ".1234568".
new DateTimeOffset(2023, 12, 24, 15, 30, 0, 123, 456, TimeSpan.FromHours(1)).AddTicks(8)
}
};
}
Expand All @@ -376,13 +378,17 @@ public static TheoryData<byte, string> InvalidInput()
// ReSharper disable once GrammarMistakeInComment
// Invalid date (February 30th).
{ DateTimeOptions.DefaultInputPrecision, "2023-02-30T15:30:00Z" },
// More than 7 fractional second digits.
{ DateTimeOptions.DefaultInputPrecision, "2023-12-24T15:30:00.12345678Z" },
// More than 9 fractional second digits.
{ DateTimeOptions.DefaultInputPrecision, "2023-12-24T15:30:00.1234567890Z" },
// Invalid offset (exceeds maximum).
{ DateTimeOptions.DefaultInputPrecision, "2023-12-24T15:30:00+25:00" },
// Invalid offset format.
{ DateTimeOptions.DefaultInputPrecision, "2023-12-24T15:30:00 UTC" },
// Additional cases.
// More than 8 fractional second digits with precision set to 8.
{ 8, "2023-12-24T15:30:00.123456789Z" },
// More than 7 fractional second digits with precision set to 7.
{ 7, "2023-12-24T15:30:00.12345678Z" },
// More than 6 fractional second digits with precision set to 6.
{ 6, "2023-12-24T15:30:00.1234567Z" },
// More than 5 fractional second digits with precision set to 5.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ public void LocalDateTime_Relaxed_Format_Check()
[InlineData(5, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,5})?$")]
[InlineData(6, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?$")]
[InlineData(7, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,7})?$")]
[InlineData(8, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,8})?$")]
[InlineData(9, @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$")]
public void Pattern_Should_Match_InputPrecision(byte precision, string expectedPattern)
{
// arrange & act
Expand Down Expand Up @@ -375,8 +377,8 @@ public static TheoryData<byte, string, DateTime> ValidInput()
},
{
DateTimeOptions.DefaultInputPrecision,
"2023-12-24t15:30:00.1234567",
new DateTime(2023, 12, 24, 15, 30, 0, 123, 456).AddTicks(7)
"2023-12-24t15:30:00.123456789", // Rounded to ".1234568".
new DateTime(2023, 12, 24, 15, 30, 0, 123, 456).AddTicks(8)
}
};
}
Expand All @@ -399,9 +401,13 @@ public static TheoryData<byte, string> InvalidInput()
// ReSharper disable once GrammarMistakeInComment
// Invalid date (February 30th).
{ DateTimeOptions.DefaultInputPrecision, "2023-02-30T15:30:00" },
// More than 7 fractional second digits.
{ DateTimeOptions.DefaultInputPrecision, "2023-12-24T15:30:00.12345678" },
// More than 9 fractional second digits.
{ DateTimeOptions.DefaultInputPrecision, "2023-12-24T15:30:00.1234567890" },
// Additional cases.
// More than 8 fractional second digits with precision set to 8.
{ 8, "2023-12-24T15:30:00.123456789" },
// More than 7 fractional second digits with precision set to 7.
{ 7, "2023-12-24T15:30:00.12345678" },
// More than 6 fractional second digits with precision set to 6.
{ 6, "2023-12-24T15:30:00.1234567" },
// More than 5 fractional second digits with precision set to 5.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ public void LocalTime_Relaxed_Format_Check()
[InlineData(5, @"^\d{2}:\d{2}:\d{2}(?:\.\d{1,5})?$")]
[InlineData(6, @"^\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?$")]
[InlineData(7, @"^\d{2}:\d{2}:\d{2}(?:\.\d{1,7})?$")]
[InlineData(8, @"^\d{2}:\d{2}:\d{2}(?:\.\d{1,8})?$")]
[InlineData(9, @"^\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$")]
public void Pattern_Should_Match_InputPrecision(byte precision, string expectedPattern)
{
// arrange & act
Expand Down Expand Up @@ -372,8 +374,8 @@ public static TheoryData<byte, string, TimeOnly> ValidInput()
},
{
DateTimeOptions.DefaultInputPrecision,
"07:30:00.1234567",
new TimeOnly(7, 30, 0, 123, 456).Add(TimeSpan.FromTicks(7))
"07:30:00.123456789", // Rounded to ".1234568".
new TimeOnly(7, 30, 0, 123, 456).Add(TimeSpan.FromTicks(8))
}
};
}
Expand All @@ -395,9 +397,13 @@ public static TheoryData<byte, string> InvalidInput()
{ DateTimeOptions.DefaultInputPrecision, "24:00:00" },
// Invalid minute (60).
{ DateTimeOptions.DefaultInputPrecision, "15:60:00" },
// More than 7 fractional second digits.
{ DateTimeOptions.DefaultInputPrecision, "15:30:00.12345678" },
// More than 9 fractional second digits.
{ DateTimeOptions.DefaultInputPrecision, "15:30:00.1234567890" },
// Additional cases.
// More than 8 fractional second digits with precision set to 8.
{ 8, "15:30:00.123456789" },
// More than 7 fractional second digits with precision set to 7.
{ 7, "15:30:00.12345678" },
// More than 6 fractional second digits with precision set to 6.
{ 6, "15:30:00.1234567" },
// More than 5 fractional second digits with precision set to 5.
Expand Down
Loading