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)
-
0
Hi @cangunaydin,
What about using https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Timing/DisableDateTimeNormalization.cs on the server side ?
-
0
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?
-
0
@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.
-
0
Thank you so much @ismcagdas, this information helped me a lot.
-
0
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.
-
0
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?
-
0
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
-
0
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.