Skip to content
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

Remove extra validation when DateTimeValue(uo) #2589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ namespace Microsoft.PowerFx.Functions
{
internal static partial class Library
{
private static bool IsValidDateTimeUO(string s)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsValidDateTimeUO

Introduced at #527

{
return Regex.IsMatch(s, @"^[0-9]{4,4}-[0-1][0-9]-[0-3][0-9](T[0-2][0-9]:[0-5][0-9]:[0-5][0-9](\.[0-9]{0,7})?Z?)?$");
}

public static FormulaValue Index_UO(IRContext irContext, FormulaValue[] args)
{
var arg0 = (UntypedObjectValue)args[0];
Expand Down Expand Up @@ -474,7 +469,7 @@ public static FormulaValue DateValue_UO(EvalVisitor runner, EvalVisitorContext c
{
var s = impl.GetString();

if (IsValidDateTimeUO(s) && DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTime datetime))
if (DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTime datetime))
{
var timeZoneInfo = runner.TimeZoneInfo;
datetime = MakeValidDateTime(runner, datetime, timeZoneInfo);
Expand Down Expand Up @@ -518,7 +513,7 @@ public static FormulaValue DateTimeValue_UO(EvalVisitor runner, EvalVisitorConte
{
var s = impl.GetString();

if (IsValidDateTimeUO(s) && DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTime datetime))
if (DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTime datetime))
{
datetime = MakeValidDateTime(runner, datetime, runner.TimeZoneInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,13 @@ Error({Kind:ErrorKind.InvalidArgument})
Error({Kind:ErrorKind.InvalidArgument})

>> DateValue(ParseJSON("""2011-1-15"""))
Error({Kind:ErrorKind.InvalidArgument})
Date(2011,1,15)

>> DateValue(ParseJSON("""2011-01"""))
Error({Kind:ErrorKind.InvalidArgument})
Date(2011,1,1)

>> DateValue(ParseJSON("""2011-1-15""")) = DateValue("2011-1-15")
true

>> DateValue(ParseJSON("""2011"""))
Error({Kind:ErrorKind.InvalidArgument})
Expand All @@ -266,6 +269,9 @@ Error({Kind:ErrorKind.InvalidArgument})
>> DateDiff(DateTimeValue(ParseJSON("""2011-01-15T00:00:00""")), DateTimeValue(ParseJSON("""2011-01-30""")))
15

>> DateDiff(DateTimeValue(ParseJSON("""8/13/2024 9:10 AM""")), DateTimeValue(ParseJSON("""8/14/2024 9:10 AM""")))
1

>> DateTimeValue(ParseJSON("""2011-01-15T08:0:00.000Z"""))
Error({Kind:ErrorKind.InvalidArgument})

Expand Down