Base solution for your next web application
Open Closed

Question regarding timezones and daylight savings #6033


User avatar
0
gep13 created

Hello,

I am hoping that someone can point me in the right direction regarding how timezones work in ASP.NET Zero. Firstly, let me explain what I have done...

I am using 6.2.1 of the template, and I have made the following modifications:

Added the following into my Startup.cs:

Clock.Provider = ClockProviders.Utc;

I have then changed the Date Time Format strings in the Users/index.js to the following:

 return moment(lastLoginTime).format('D MMM YYYY HH:mm:ss');

i.e. to include the Time portion.

So the first question, with the changes that I have made above, I would expect that all DateTimes stored in the database would be treated as UTC times, and as such, any display of these times, or export to Excel, to account for this. I can see this in action if I change the currently logged in user to another time zone (for example Greenland, which is three hours away from UTC)

In the above screenshot, everything works. The UTC date in the database is correctly displayed in the currently configured local timezone.

However, if I now do the following, things no longer do what I expect...

I change the creation date time to be on the 24th October 2018. On this day, Britain was in Daylight Savings mode, and as a result, we were 1 hour away from UTC. If at this point in time I created a user (which is what I am trying to simulate by making this change), the date stored in the database should have been offset by one hour. As a result, when I export/display the values, I would expect a 1 hour offset. This isn't happening, as you can see in this screenshot:

Are my expectations here invalid?

Assuming that all times are stored in UTC, and the site takes into account daylight savings, when exporting/displaying the Last Login DateTime, I would expect there to be a 1 hour offset. Can you please confirm if there is another setting that I need to enable to get the expected output?

Thanks

Gary


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

    Hi @gep13

    Your expectation is correct. Could you also share the value for user's timezone setting in AbpSettings table ? Is it "Greenland Standard Time" ?

    When I try something like below, it's result is 2018-10-24 14:10:47 which is different than yours. So, I guess I have tried with a wrong time zone value.

    var date = new DateTime(2018, 10, 24, 16, 10, 47);
    var result = TimezoneHelper.ConvertFromUtc(date, "Greenland Standard Time");
    
  • User Avatar
    0
    gep13 created

    @ismcagdas does the TimeZoneHelper simply wrap the TimeZoneConverter? That is what I am using in the code above?

    I can confirm that the value in the AbpSetttings table for that User is indeed:

    Greenland Standard Time
    
  • User Avatar
    0
    gep13 created

    Can you also confirm where the list of Time Zones is coming from? I notice in version 6.2.1 there has been a change in the way the list is formatted compared to another version we were using (where it also included location information, for example, London.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @gep13

    TimeZoneConverter uses TimeZoneHelper and it finally executes below code;

    TimeZoneInfo.ConvertTime(date, sourceTimeZone, destinationTimeZone)

    We were using TimeZoneInfo to get list of timezones but it is not supported on non-windows operating systems. We have switched to https://github.com/mj1856/TimeZoneConverter which has a list named TZConvert.KnownWindowsTimeZoneIds.

    Could you create an issue about this on https://github.com/aspnetzero/aspnet-zero-core/issues/new ? We will test this again and fix if there is a problem.