Base solution for your next web application
Open Closed

DateTime normalization suppression. #4595


User avatar
0
bertusvanzyl created

When sending a datetime back from the angular application, it gets changes to UTC, and the API and the database use the UTC date. This is good. However, sometimes, when sending a datetime back from the browser into the API, I want the specific date to be stored in the database etc.

For example, when speciifying a birthdate, I send back 1981-09-25 to the API. This is the persons birthday, regardless of timezone.

If the DTO is of type DateTime, the API receives something like 1981-09-24 10:00:00, because it has been converted to UTC.

So my question is, how do I suppress the conversion to UTC for specific properties on a DTO?

For now I am sending the year, month, and day as seperate integers, but I am not happy with this clunky workaround. Otherwise I might end up sending a string? What do you guys suggest?

Thank you.


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

    @BertusVanZyl can you create an issue on ABP Framework and we will think this for the next release, <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues">https://github.com/aspnetboilerplate/as ... ate/issues</a>.

  • User Avatar
    0
    bertusvanzyl created

    I have added an issue: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3050">https://github.com/aspnetboilerplate/as ... ssues/3050</a>

    Thank you. In meantime I will split up into year, month and day ints, or use a string.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @BertusVanZyl, we will try to complete it for the next release.

  • User Avatar
    0
    ribbo created

    For anyone that comes across this thread and would like a workaround.

    I had the same issue and needed to suppress the date timezone conversion for some of my dates. On the Angular side I remove the timezone offset before sending and when I get it back from the API for reading.

    When you are sending the date to the API run this function on your property and it will remove the timezone offset yourDate.utcOffset(0, true);

    When you get the date from the API this will keep it as the date sent without any offset applied yourDate.utc();

    By doing this before sending and when you receive you will be saving and reading the dates as they are selected regardless of any timezone settings. Eg. great for Date of Birth which doesn't change based on Timezone settings.

    It is not ideal because it requires you to remember to do this anywhere you send\receive this date and open to you forgetting. But it gets the job done while ABP implements the Suppression attribute.

    Hope it helps someone, Matt

  • User Avatar
    0
    ismcagdas created
    Support Team

    @Ribbo thanks a lot for sharing this :). By the way, we are planning to complete <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1240">https://github.com/aspnetboilerplate/as ... ssues/1240</a> in the ABP's v3.6.