开发者

How does .NET determine the week in a TimeZoneInfo.TransitionTime?

开发者 https://www.devze.com 2022-12-29 16:19 出处:网络
Greetings I\'m trying to do some DateTime math for various time zones and I wanted to take daylight savings into account.Lets say I have a TimeZoneInfo and i\'开发者_如何学编程ve determined the appro

Greetings

I'm trying to do some DateTime math for various time zones and I wanted to take daylight savings into account. Lets say I have a TimeZoneInfo and i'开发者_如何学编程ve determined the appropriate AdjustmentRule for a given DateTime. Lets also say the particular TimeZoneInfo i'm dealing with is specified as rule.DaylightTransitionStart.IsFixedDateRule == false, so I need to figure out if the given DateTime falls within the start/end TransitionTime.Week values.

This is where I'm getting confused, what is .NET considering as a "week"? My first thought was it probably used something like

DayOfWeek thisMarksWeekBoundaries = Thread.CurrentThread.CurrentUICulture.DateTimeFormat.FirstDayOfWeek;

and went through the calendar assigning days to week, incrementing week every time it crossed a boundary. But, if I do this for May 2010 there are 6 week boundary buckets, and the max valid value for TransitionTime.Week is 5 so this can't be right.

Whats the right way to slice up May 2010?


This article http://msdn.microsoft.com/en-us/library/system.timezoneinfo.transitiontime.isfixeddaterule.aspx shows how to extract the IsFixedDateRule == false, see DisplayTransitionInfo


I finally realized whats going on, I think the property name "Week" is what threw me off. There might be 6 weeks in May (depending on how you count them), but any particular DayOfWeek shows up at most 5 times. The Week property doesn't really refer to what week the DayOfWeek is showing up in, its the nth DayOfWeek for that month--with the magic value 5 meaning its last so either the max n is 4 or 5 for a given month.

0

精彩评论

暂无评论...
验证码 换一张
取 消