Is there a way to check if it's DST (Daylight Saving Time) with UTC?

Is there a way to check if it's DST (Daylight Saving Time) with UTC, without using conversion?

I don't want to use conversion because it's ambiguous on the 28 october at 2 am. This:

using System;

namespace Rextester
{
    public class Program
    {
        public static void PrintSeasonKindTime(DateTime utcDate)
        {
            // Convert dt to Romance Standard Time
            TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
            DateTime localDate = TimeZoneInfo.ConvertTime(utcDate, tzi);

            Console.WriteLine("Local date: " + localDate.ToString("yyyy.MM.d HH:mm:ss") +  (tzi.IsDaylightSavingTime(localDate) ? " is summer" : " is winter"));
        }

        public static void Main(string[] args)
        {
            DateTime currentUTCDateTime = new DateTime(2018,10,27,23,59,0, DateTimeKind.Utc);
            double nbMinutes = 1.0;

            PrintSeasonKindTime(currentUTCDateTime);
            PrintSeasonKindTime(currentUTCDateTime.AddMinutes(nbMinutes));
        }
    }
}

Will display this:

Local date: 2018.10.28 01:59:00 is summer
Local date: 2018.10.28 02:00:00 is winter

While I wish the following display:

Local date: 2018.10.28 01:59:00 is summer
Local date: 2018.10.28 02:00:00 is summer

Since the time change is at 2018.10.28 03:00:00 local time in the specified time zone not at 2 am (see here enter link description here).

However, that behaviour is "ambiguously" correct since it's two times 2 am on 28th October; once at 00:00 UTC (2 am summer time) and once at 1 am (2 am winter time). Do you have any idea?

Jon Skeet
people
quotationmark

Just use TimeZoneInfo.IsDaylightSavingTime, passing in your UTC DateTime value. That will effectively convert that UTC value into the given time zone and check whether the result is in daylight saving time, although whether it actually performs that conversion or just checks whether it would be in DST is a different matter.

Note that this is never ambiguous, as a UTC value is never ambiguous.

TimeZoneInfo.IsDaylightSavingTime returns true when passed 2018-10-28T00:00:00Z in the time zone you're interested in.

people

See more on this question at Stackoverflow