diff --git a/src/libraries/Microsoft.PowerFx.Interpreter/Functions/Library.cs b/src/libraries/Microsoft.PowerFx.Interpreter/Functions/Library.cs index 8cc07d81b6..30eeb4523e 100644 --- a/src/libraries/Microsoft.PowerFx.Interpreter/Functions/Library.cs +++ b/src/libraries/Microsoft.PowerFx.Interpreter/Functions/Library.cs @@ -28,7 +28,7 @@ internal static partial class Library /// public static readonly TexlFunction DistinctInterpreterFunction = new DistinctFunction(); - internal static readonly DateTime _epoch = new DateTime(1899, 12, 30, 0, 0, 0, 0); + internal static readonly DateTime _epoch = new DateTime(1899, 12, 30, 0, 0, 0, 0, DateTimeKind.Utc); // Helper to get a service or fallback to a default if the service is missing. private static T GetService(this IServiceProvider services, T defaultService) diff --git a/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/ConfigTests.cs b/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/ConfigTests.cs index b189dc4194..907567b4c8 100644 --- a/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/ConfigTests.cs +++ b/src/tests/Microsoft.PowerFx.Interpreter.Tests.Shared/ConfigTests.cs @@ -35,6 +35,21 @@ public async Task BasicEvaluation() Assert.Equal(5.0, result.ToObject()); } + [Fact] + public async Task TestDecimalToDateTimeCoercion() + { + // Per expression. + var engine = new RecalcEngine(); + var rc = new RuntimeConfig(); + rc.SetTimeZone(TimeZoneInfo.Utc); + + var res = await engine.EvalAsync("If(false, DateTime(1899, 12, 30, 0, 0, 0, 0), 0)", CancellationToken.None, runtimeConfig: rc); + + var dt = res.ToObject(); + + Assert.Equal(DateTimeKind.Utc, ((DateTime)dt).Kind); + } + [Fact] public async Task BasicDirectEvalFunc() {