Base solution for your next web application
Open Closed

Timezone in Angular UI, What should be the approach? #6324


User avatar
0
cangunaydin created

Hello AspnetZero Team, I am using Asp.Net Zero v6.4 Angular App. I have a problem with dates for my application. Cause of the problem is, in some pages i need to get the date from the user as utc and reflect back to that page as utc value (as it is in database). My application use timezones. So every user can choose different timezones.

As i see it in Asp.net Zero, all the date (momentjs) values are converted to utc before it goes the server side and when you get the values from the server it is converted to timezone of the user has chosen and reflected to ui. I was wondering if there is any solution or function in abp framework to disable it in certain pages so all the date values can go to the database, only for that page as utc values, instead of converting them. Cause i have an application that the users needs to set certain values as utc.

How should i approach the problem and what should be the best way to solve it in aspnetzero application? Thanks for your assistance.


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

    Hello @ismcagdas, Thank you for your help, it is very promising, I was wondering in dto object if there are dates with utc and local settings what will be the solution? Should i split my update method into 2 different server side methods and call seperately from the client? One method for local dates and one for utc dates?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @cangunaydin

    This attribute can be used for Dto fields. So, you can define two date fields and use this attribute only for the one which you don't want ABP to normalize. In that case, you don't have to create two separate methods.

  • User Avatar
    0
    cangunaydin created

    Thank you so much @ismcagdas, this information helped me a lot.

  • User Avatar
    0
    cangunaydin created

    Hello @ismcagdas, sorry to bother you again, but i believe DisableDateTimeNormalization attribute doesn't work as i expected. I have a scenario to explain it little bit further.

    I logged in as a user in Western European Standard Time, and created a model from that page Which has startDate and endDate properties. Both properties on the server side defined with attribute DisableDateTimeNormalization,

    let's say as a user i selected 2019-02-06 00:00 and 2019-02-12 23:59, the values i selected goes to the server side as 2019-02-05T23:00:00Z and 2019-02-12T22:59:59.999Z is this an expected behavior? Should i do an extra coding on the client side to remove the timezone values? Like as it is on the local time cause i want the value 2019-02-06T00:00:00Z and 2019-02-12T23:59:59.999Z values to be stored in Database. Also when i try to list the values it comes up with the same values and has shown according to user timezone. Is this also an expected behavior? if it is what does DisableDateTimeNormalization do? cause it has the same behavior when i do not use the attribute DisableDateTimeNormalization?

    Can you clarify the points that i am missing over here? Thanks a lot for the assistance.

  • User Avatar
    0
    aaron created
    Support Team

    Should i do an extra coding on the client side to remove the timezone values?

    Yes. If the client is sending the wrong values, then how would the server know?

  • User Avatar
    0
    cangunaydin created

    hello @aaron, dont get me wrong over here i am just trying to understand the behavior of this attribute. there is no documentation or explanation about how it behaves plus even if it goes the right values i really didnt grasp what does it do in the server side. Cause correct me if i am wrong isnt all the conversions have been done on the client side with moment timezone library? After you save the value to database as utc isnt it going to be converted back to user timezone when you get the values from server side? as it is in my example lets say that it is stored to db as 2019-02-06 00:00 then when i get it from db and list it on the client side it will be different for all the users in different timezones isnt that so? What i want instead is to have that value the same to all users independent from the timezone

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @cangunaydin

    isnt it going to be converted back to user timezone when you get the values from server side?

    Server side returns UTC value if you are using UTC Clock Provider. When you use DisableDateTimeNormalization attribute, ABP doesn't modify your datetime values but ASP.NET Core does.

    Maybe you can try to display this date on the client side without using the moment.