diff --git a/src/libraries/Microsoft.PowerFx.Interpreter/Functions/LibraryUntypedObject.cs b/src/libraries/Microsoft.PowerFx.Interpreter/Functions/LibraryUntypedObject.cs index 771d35ef8a..663ed9842f 100644 --- a/src/libraries/Microsoft.PowerFx.Interpreter/Functions/LibraryUntypedObject.cs +++ b/src/libraries/Microsoft.PowerFx.Interpreter/Functions/LibraryUntypedObject.cs @@ -20,11 +20,6 @@ namespace Microsoft.PowerFx.Functions { internal static partial class Library { - private static bool IsValidDateTimeUO(string s) - { - 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]; @@ -476,7 +471,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); @@ -520,7 +515,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); diff --git a/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ExpressionTestCases/ParseJson.txt b/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ExpressionTestCases/ParseJson.txt index c258a0a468..750905e494 100644 --- a/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ExpressionTestCases/ParseJson.txt +++ b/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ExpressionTestCases/ParseJson.txt @@ -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}) @@ -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})