TimeZoneInfo.TransitionTime.IsFixedDateRule Property


Gets a value indicating whether the time change occurs at a fixed date and time (such as November 1) or a floating date and time (such as the last Sunday of October).

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

Public ReadOnly Property IsFixedDateRule As Boolean

Property Value

Type: System.Boolean

true if the time change rule is fixed-date; false if the time change rule is floating-date.

A fixed-date rule indicates that the transition occurs on the same date and time of each year to which the adjustment rule applies. For example, a time change that occurs every November 3 follows a fixed-date rule. A floating-date rule indicates that the transition occurs on a specific day of a specific week of a specific month for each year to which the adjustment rule applies. For example, a time change that occurs on the first Sunday of November follows a floating-date rule.

The value of the IsFixedDateRule property determines which properties of a TimeZoneInfo.TransitionTime object have valid values. The following table indicates which properties are affected by the value of the IsFixedDateRule property.

TransitionTime property

IsFixedDateRule = true

IsFixedDateRule = false
















The following example lists the transition times to and from daylight saving time for all time zones that are available on the local system. For time zones with fixed-date rules, it displays transition time information from the properties of the TimeZoneInfo.TransitionTime object. For time zones without fixed-date rules, it uses a Calendar object that represents the current system calendar to determine the actual start and end dates of the transition. The example displays the results to the console.

Private Sub GetTransitionTimes(year As Integer)
   ' Get and iterate time zones on local computer
   Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
   For Each timeZone As TimeZoneInfo In timeZones
      Console.WriteLine("{0}:", timeZone.StandardName)
      Dim adjustments() As TimeZoneInfo.AdjustmentRule = timeZone.GetAdjustmentRules()
      Dim startYear As Integer = year
      Dim endYear As Integer = startYear

      If adjustments.Length = 0 Then
         Console.WriteLine("   No adjustment rules.")
         Dim adjustment As TimeZoneInfo.AdjustmentRule = GetAdjustment(adjustments, year)
         If adjustment Is Nothing Then
            Console.WriteLine("   No adjustment rules available for this year.")
            Continue For
         End If
         Dim startTransition, endTransition As TimeZoneInfo.TransitionTime

         ' Determine if starting transition is fixed 
         startTransition = adjustment.DaylightTransitionStart
         ' Determine if starting transition is fixed and display transition info for year
         If startTransition.IsFixedDateRule Then
            Console.WriteLine("   Begins on {0} {1} at {2:t}", _
                              MonthName(startTransition.Month), _
                              startTransition.Day, _
            DisplayTransitionInfo(startTransition, startYear, "Begins on")
         End If    

         ' Determine if ending transition is fixed and display transition info for year
         endTransition = adjustment.DaylightTransitionEnd

         ' Does the transition back occur in an earlier month (i.e., 
         ' the following year) than the transition to DST? If so, make
         ' sure we have the right adjustment rule.
         If endTransition.Month < startTransition.Month Then
            endTransition = GetAdjustment(adjustments, year + 1).DaylightTransitionEnd
            endYear += 1
         End If

         If endTransition.IsFixedDateRule Then
            Console.WriteLine("   Ends on {0} {1} at {2:t}", _
                              MonthName(endTransition.Month), _
                              endTransition.Day, _
            DisplayTransitionInfo(endTransition, endYear, "Ends on")
         End If    
      End If   
End Sub

Private Function GetAdjustment(adjustments As TimeZoneInfo.AdjustmentRule(), _
                               year As Integer) As TimeZoneInfo.AdjustmentRule
   ' Iterate adjustment rules for time zone
   For Each adjustment As TimeZoneInfo.AdjustmentRule In adjustments
      ' Determine if this adjustment rule covers year desired
      If adjustment.DateStart.Year <= year And adjustment.DateEnd.Year >= year Then
         Return adjustment
      End If
   Return Nothing
End Function

Private Sub DisplayTransitionInfo(transition As TimeZoneInfo.TransitionTime, year As Integer, label As String)
   ' For non-fixed date rules, get local calendar
   Static cal As Calendar = CultureInfo.CurrentCulture.Calendar

   ' Get first day of week for transition
   ' For example, the 3rd week starts no earlier than the 15th of the month
   Dim startOfWeek As Integer = transition.Week * 7 - 6
   ' What day of the week does the month start on?
   Dim firstDayOfWeek As Integer = cal.GetDayOfWeek(New Date(year, transition.Month, 1))
   ' Determine how much start date has to be adjusted
   Dim transitionDay As Integer 
   Dim changeDayOfWeek As Integer = transition.DayOfWeek

   If firstDayOfWeek <= changeDayOfWeek Then
      transitionDay = startOfWeek + (changeDayOfWeek - firstDayOfWeek)
      transitionDay = startOfWeek + (7 - firstDayOfWeek + changeDayOfWeek)
   End If
   ' Adjust for months with no fifth week
   If transitionDay > cal.GetDaysInMonth(year, transition.Month) Then  
      transitionDay -= 7
   End If
   Console.WriteLine("   {0} {1}, {2:d} at {3:t}", _
                     label, _
                     transition.DayOfWeek, _
                     New DateTime(year, transition.Month, transitionDay), _
End Sub   

.NET Framework
Available since 3.5
Return to top