AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Time zone settings not propagated to query

Open MrKevHunter opened this issue 3 years ago • 10 comments

Using Microsoft.AspNetCore.OData V 8.0.4

in my startup I set

                .AddOData(opt =>
                {

                    opt.Select().Filter().OrderBy().Count().SetMaxTop(1000)
                        .AddRouteComponents("api", EdmModelBuilder.GetEdmModel())
                        .TimeZone = TimeZoneInfo.Utc;
                    opt.EnableAttributeRouting = true;

                })

And specify the time zone i want to use

When using

[HttpGet("api/my-endpoint")]
        [EnableQuery(PageSize = 44, MaxTop = 100, AllowedQueryOptions = AllowedQueryOptions.All)]

The ExpressionBinderHelper is not setting the TimeZone

             right = DateTimeOffsetToDateTime(right, querySettings.TimeZone, querySettings);

https://github.com/OData/AspNetCoreOData/blob/master/src/Microsoft.AspNetCore.OData/Query/Expressions/ExpressionBinderHelper.cs#L76

Has a null timezone

I've read https://github.com/OData/AspNetCoreOData/issues/268 But this doesn't seem to have fixed the issue in 8.0.4

MrKevHunter avatar Nov 18 '21 16:11 MrKevHunter

See commit at: bcdf32e285072ae0552847b0518ae4036ebab91f

xuzhg avatar Nov 30 '21 22:11 xuzhg

@MrKevHunter would you please help verify your project using the latest nightly bit?

xuzhg avatar Nov 30 '21 22:11 xuzhg

@MrKevHunter would you please help verify your project using the latest nightly bit?

yep should be able to, will take a look

MrKevHunter avatar Dec 01 '21 15:12 MrKevHunter

looks good to me, setting the timezone to UTC in the startup.cs fixes our issue

MrKevHunter avatar Dec 01 '21 15:12 MrKevHunter

Could you please post the fix? I am facing the same issue

I am trying the latest 8.0.11 package.

manikandantk88 avatar Dec 01 '22 03:12 manikandantk88

Having the same issue with 8.0.12, Anyone found any fix? @MrKevHunter

jineshpatel99 avatar Jan 06 '23 15:01 jineshpatel99

I'm seeing the same problem with the latest version as of 6/29/2023. Breaking Datetime values is a huge problem, how is this still broken?

Olivercomputing avatar Jun 30 '23 06:06 Olivercomputing

I'm also see the problem. Please check the description I provided in the issue #378. Any suggestion? Thanks D

darkeagle76 avatar Aug 10 '23 08:08 darkeagle76

We are also facing this issue, only enabling legacyTimestampBehavior on postgres does fix it for now. I have placed a module initializer in the repo project while also setting UTC in odatasettings:

ODataSettings = new ODataSettings
            {
                TimeZone = TimeZoneInfo.Utc,
            },
public static class PostgresModuleInitializer
{
    [ModuleInitializer]
    public static void Initialize()
    {
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
    }
}

@darkeagle76

pgrimmert avatar Sep 06 '23 10:09 pgrimmert

@pgrimmert My original problem is not related to postgres but thanks for the hint! I see you also saw my PR... I hope someone will approve it soon. Thanks!

darkeagle76 avatar Sep 07 '23 05:09 darkeagle76