Base solution for your next web application
Open Closed

Timezone removed from Datetime data by API #10392


User avatar
0
admin@SYNTAQ created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? 8.8
  • What is your product type (Angular or MVC)? MVC
  • What is product framework type (.net framework or .net core)? .net Core

On submitting the data delow to an API post method using the swagger interface the time zone (+12:00) information is stripped out and has converted it to 2021-06-21T12:00:00+00:00.

{ "dateTime":"2021-06-21T00:00:00+12:00", }

If I view the Audit Log I can see that the data is already altered to 2021-06-20T12:00:00+00:00.

This is having the effect of showing date controls getting confused and showing 2021-06-19

Our web servers are running on MS Azure Web apps


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    AspNet Zero only modifies date values if you use UtcClockProvider or LocalClockPrivider. If you are using UtcClockProvider, you can switch to LocalClockProvider, see https://aspnetboilerplate.com/Pages/Documents/Timing.

    If you don't want AspNet Zero to modify these values at all, you can use UnspecifiedClockProvider. In that case, ASP.NET Core will handle string to datetime conversion.

  • User Avatar
    0
    admin@SYNTAQ created

    Thanks,

    Each of our tenants must be able to set their own time zone, so we are restricted to using Clock.Provider = ClockProviders.Utc;

    Client UTC = +12

    The result we see is that if a userr enters a value of 2021-06-22 (no time value) the value as it passes into the API is converted to

    dateTime: "2021-06-21T12:00:00+00:00",

  • User Avatar
    0
    admin@SYNTAQ created

    Hi,

    Still trying to find an answer for this

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    The result we see is that if a userr enters a value of 2021-06-22 (no time value) the value as it passes into the API is converted to

    dateTime: "2021-06-21T12:00:00+00:00",

    This is the expected behaviour. The value is converted to UTC according to current user's timezone. And then, whe displaying the same value in UI, it must be converted to current user's timezone.

    For example, in this case, value is saved to DB as 2021-06-21T12:00:00+00:00. If another user logins to the system and have a timezone value as UTC, then the value 2021-06-21T12:00:00+00:00 must be displayed to this user. If a user with UTC+6 logins, then that user will see 2021-06-21T18:00:00+00:00.

    So, probably you are posting value with a tenant with timezone UTC+12 and viewing the values with a tenant with timezone UTC. Could that be the case ?

  • User Avatar
    0
    admin@SYNTAQ created

    How would you recommend dealing with standard and daylight savings? Potientially a date can show as the wrong day when this changes.

  • User Avatar
    0
    admin@SYNTAQ created

    Also. Recommendations when running background jobs on tenant data where the function does not know the timezone? i.e a date time value sent in an email will show the original UTC date without considering the users timezone.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    For Daylight saving, if you are showind data on client side, JS libraries automatically handles this. For server side, I think ASP.NET Core doesn't handle it (I'm not %100 sure). In that case, you can use a library like NodaTime.

    For background jobs, you can use https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Timing/Timezone/TimeZoneConverter.cs and convert UTC date to a user's timezone easily.