Exemplo n.º 1
0
        private DateTime ComputeDateTimeTimeZoneLocalDateUtc(TimeSpan value)
        {
            if (CurrentDate.Kind != DateTimeKind.Local)
            {
                throw new Exception("Invalid CurrentDate DateTimeKind : must be Local");
            }

            var baseUtcOffset = TimeZone.BaseUtcOffset;

            var dateTime = ComputeNewDateTime(value);

            if (TimeZone.SupportsDaylightSavingTime)
            {
                if (TimeZone.IsAmbiguousTime(dateTime))
                {
                    if (IsSummerPeriod)
                    {
                        return(new DateTime(dateTime.AddTicks(-baseUtcOffset.Ticks).AddTicks(-TimeZone.GetAdjustmentRules()[0].DaylightDelta.Ticks).Ticks, DateTimeKind.Utc));
                    }

                    return(new DateTime(dateTime.AddTicks(-baseUtcOffset.Ticks).Ticks, DateTimeKind.Utc));
                }

                IsSummerPeriod = TimeZone.IsDaylightSavingTime(dateTime);
            }

            return(dateTime.ToUniversalTime());
        }