TimeZoneInfo structure for TIME_ZONE_INFORMATION

Hey, I have a TimeZoneInfo , and from this I want to create a TIME_ZONE_INFO struct.

Offsets, StandardDate, and Daylightdate are pretty easy to get. However, I am having problems getting standard bins and daytime events. So, the question is how can I get standard encores from a TimeZOneInfo object and how can I get the same thing for daytime systems (there is an AdjustmentRule.DaylightDelta parameter, but as you can see, I need an offset, not a delta).

Thanks.

+3
source share
2 answers

CrankedUp ( TIME_ZONE_INFORMATION), sp3 Windows XP. .

TimeZoneInfo.AdjustmentRule[] adjustmentRules = timeZoneInfo.GetAdjustmentRules();
TimeZoneInfo.AdjustmentRule adjustmentRule = null;
if (adjustmentRules.Length > 0)
{
    // Find the single record that encompasses today date. If none exists, sets adjustmentRule to null.
    adjustmentRule = adjustmentRules.SingleOrDefault(ar => ar.DateStart <= DateTime.Now && DateTime.Now <= ar.DateEnd);
}

double bias = -timeZoneInfo.BaseUtcOffset.TotalMinutes; // I'm not sure why this number needs to be negated, but it does.
string daylightName = timeZoneInfo.DaylightName;
string standardName = timeZoneInfo.StandardName;
double daylightBias = adjustmentRule == null ? -60 : -adjustmentRule.DaylightDelta.TotalMinutes; // Not sure why default is -60, or why this number needs to be negated, but it does.
int daylightDay = 0;
int daylightDayOfWeek = 0;
int daylightHour = 0;
int daylightMonth = 0;
int standardDay = 0;
int standardDayOfWeek = 0;
int standardHour = 0;
int standardMonth = 0;

if (adjustmentRule != null)
{
    TimeZoneInfo.TransitionTime daylightTime = adjustmentRule.DaylightTransitionStart;
    TimeZoneInfo.TransitionTime standardTime = adjustmentRule.DaylightTransitionEnd;

    // Valid values depend on IsFixedDateRule: http://msdn.microsoft.com/en-us/library/system.timezoneinfo.transitiontime.isfixeddaterule.
    daylightDay = daylightTime.IsFixedDateRule ? daylightTime.Day : daylightTime.Week;
    daylightDayOfWeek = daylightTime.IsFixedDateRule ? -1 : (int)daylightTime.DayOfWeek;
    daylightHour = daylightTime.TimeOfDay.Hour;
    daylightMonth = daylightTime.Month;

    standardDay = standardTime.IsFixedDateRule ? standardTime.Day : standardTime.Week;
    standardDayOfWeek = standardTime.IsFixedDateRule ? -1 : (int)standardTime.DayOfWeek;
    standardHour = standardTime.TimeOfDay.Hour;
    standardMonth = standardTime.Month;
}
+1

TIME_ZONE_INFORMATION . , 0. , standardbias . , ""?

DaylightDelta - UTC UTC . DaylightBias , DaylightDelta DaylightBias.

, . , Win32 TIME_ZONE_INFORMATION TimeZoneInfo ? - GetTimeZoneInformationForYear, TimeZoneInfo.StandardName DYNAMIC_TIME_ZONE_INFORMATION.StandardName?

0

Source: https://habr.com/ru/post/1709730/


All Articles