Base solution for your next web application
Open Closed

Calculating Dates #3676


User avatar
0
jseger created

I'm a little confused on how I should approach this.

Let's say I have an event that always happens on Sunday. The user makes a request to get the date of the next event. The server calculates the date by getting the date of next Sunday. The date even comes back to the client correctly. However, the angular date filter converts it to local time, which for me is Saturday.

This brings up another question. Let's say I am creating a time entry in my local time zone and I'm trying to communicate when the entry was actually created in my local time zone. In other words, I want them to know the event happened at 7:00 AM my time.

What is the best way to handle date times?


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

    hi,

    I think you have to save all dates in UTC format. Whenever user wants a date, you have to convert it user's local timezone. In datepickers, momentjs is used. Momentjs is configured to show in local timezone.

  • User Avatar
    0
    jseger created

    That's not quite right.

    Let's say I save a UTC date time as July 1, 2017 0:00 Z. This is the DAY the event is happening. July 1st.

    Now when someone 1 hour west of me opens the event, it says that it is happening June 30th.

  • User Avatar
    0
    alper created
    Support Team

    Hi again

    It's a general concept out of the AspNet Zero subject. I suggest you to read the doc below

    <a class="postlink" href="https://weblog.west-wind.com/posts/2015/feb/10/back-to-basics-utc-and-timezones-in-net-web-apps">https://weblog.west-wind.com/posts/2015 ... t-web-apps</a>

  • User Avatar
    0
    jseger created

    Thanks! The article was somewhat helpful. However, I do think this is an Abp issue or at least I need further help understanding what it is doing.

    The article talks about converting to and from local time. Basically, I don't want to convert. When I send a date to the server, that's date what I want to store. But it seems like Abp adjusts if for me when it maps my Dtos.

    Cinco de Mayo is always May 5th. Christmas is always on December 25th. New Years is always January 1st.

  • User Avatar
    0
    bilalhaidar created

    My 2 cents.

    I had to read about that long time ago and caused me some confusion.

    First of all, you can configure the ClockProvider to be UTC (server side). This way, any date you send to the server, will be stored in the database as UTC. For me, I had to do some cleaning for the dates so that I always send the date without a time or at least (00:00:00).

    On the client side, depending on the timezone the user have selected, the date will be shown accordingly.

    Moment is configured by default to local date (because ClockProvider is configured so on the server). However, I prefer always to use ClockProvider.Utc to make things easy.

    HTH

  • User Avatar
    0
    jseger created

    Thanks. I will continue to do some tests. Maybe it will be clearer for me or at least I'll have more specific questions. I'll also play with the EventCloud source for a while.

    My goal was to find out if I was missing anything obvious or if someone ran into the same issue as me.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @jseger,

    I read your first post and in my opinion, you need to store timezone information of your event in database as well. You can use datetime offset or you can store it in an extra field on your database.

    Then, you must display correct date-time using this timezone information.

    Thanks.