Base solution for your next web application
Open Closed

AbpJsonResult converts DateTime to Clock.Provider? #3157


User avatar
0
bilalhaidar created

Hi, I noticed that AbpJsonResult returns results to client by converting DateTime properties to whatever is configured at Clock.Provider.

Since Clock.Provider I configured to be UTC it means that dates are stored in the DB as UTC, correct? When returning data to client, shouldn't the Abp Framework convert those Dates to the user's TimeZone instead of using again Clock.Normalize?

Thanks


5 Answer(s)
  • User Avatar
    0
    tteoh created

    Hi,

    Based on documentation, my understanding is below:

    1. Clock.Provider set in Global.asax determines the system timezone. Default, it is set to UTC for AspNet Zero template.

    2. Therefore, Abp will always stored date/time as UTC in DB.

    3. On client side, it will receive date/time in UTC. You wil need to use timing property of abp object to retrieve User's timezone set from My Setting, to perform the required translation using moment.js directive provided by abp framework. I believe this is already the default implementation on standard views.

    NOTE: If you remove the default UTC, then Abp not do the conversion to UTC.

    My learning is only up to here as I just completed writing a Real-time clock to be display at footer.cshtml. Based on local date/time, it is converted to Server Timezone and User Timezone retrieved from AbpSettings table.

    If you have further findings, pls share here.

    Thanks, /tommy

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    @drcgreece,

    When returning data to client, shouldn't the Abp Framework convert those Dates to the user's TimeZone instead of using again Clock.Normalize?

    As @tteoh also metioned, when you use UtcClockProvider, the date is returned to client in UTC not in user's timezone. You should use momentjs to handle client side operations to handle user's timezone.

    @tteoh, your findings are correct :).

    Thanks.

  • User Avatar
    0
    tteoh created

    <cite>ismcagdas: </cite> Hi,

    @drcgreece,

    When returning data to client, shouldn't the Abp Framework convert those Dates to the user's TimeZone instead of using again Clock.Normalize?

    As @tteoh also metioned, when you use UtcClockProvider, the date is returned to client in UTC not in user's timezone. You should use momentjs to handle client side operations to handle user's timezone.

    @tteoh, your findings are correct :).

    Thanks.

    Hi Support,

    Just one question, while default is saving with UTC but if I wish to save date/time with specific timezone instead of UTC, WHERE and HOW should i implement this?

    Use Case: for system monitoring and internal reporting where I don't have to convert from UTC date/time.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Abp should save date in db as per Clock Provider configured. So if I set provider to be local then Abp should save data in db in the local time of server. This is my understanding

    I thought data were converted to user timezone automatically that's why the confusion.

    But given abp.timing.convertToUserTimeZone() can help in that conversion when needed. I'm not sure about AuditLog but there might be a valid example there.

  • User Avatar
    0
    ismcagdas created
    Support Team

    I hope the confusion is gone now. The DateTime operations are hard to understand and confusing most of the time for me as well :).