TimeZoneInfo.AdjustmentRule.Equals Method (TimeZoneInfo.AdjustmentRule)

 

Determines whether the current TimeZoneInfo.AdjustmentRule object is equal to a second TimeZoneInfo.AdjustmentRule object.

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

Public Function Equals (
	other As TimeZoneInfo.AdjustmentRule
) As Boolean

Parameters

other
Type: System.TimeZoneInfo.AdjustmentRule

The object to compare with the current object.

Return Value

Type: System.Boolean

true if both TimeZoneInfo.AdjustmentRule objects have equal values; otherwise, false.

To determine whether two TimeZoneInfo.AdjustmentRule objects are equal, the Equals(TimeZoneInfo.AdjustmentRule) method compares the member values of each object. Two adjustment rules are equal if they have the same effective dates, the same delta, and identical values for the TimeZoneInfo.TransitionTime objects returned by their DaylightTransitionStart and DaylightTransitionEnd properties.

The following example calls the TimeZoneInfo.AdjustmentRule.Equals(TimeZoneInfo.AdjustmentRule) method to compare the adjustment rules for Central Standard Time with those for Canada Central Standard Time and Mexico Standard Time.

Dim timeZoneName As String = String.Empty
' Get CST, Canadian CST, and Mexican CST adjustment rules
Dim usCstAdjustments(), canCstAdjustments(), mexCstAdjustments() As TimeZoneInfo.AdjustmentRule
Try
   timeZoneName = "Central Standard Time"
   usCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules
Catch e As TimeZoneNotFoundException
   Console.WriteLine("The {0} time zone is not defined in the registry.", timeZoneName)
Catch e As InvalidTimeZoneException
   Console.WriteLine("Data for the {0} time zone is invalid.", timeZoneName)
End Try
Try
   timeZoneName = "Canada Central Standard Time"
   canCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules
Catch e As TimeZoneNotFoundException
   Console.WriteLine("The {0} time zone is not defined in the registry.", timeZoneName)
Catch e As InvalidTimeZoneException
   Console.WriteLine("Data for the {0} time zone is invalid.", timeZoneName)
End Try
Try
   timeZoneName = "Central Standard Time (Mexico)"
   mexCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules
Catch e As TimeZoneNotFoundException
   Console.WriteLine("The {0} time zone is not defined in the registry.", timeZoneName)
Catch e As InvalidTimeZoneException
   Console.WriteLine("Data for the {0} time zone is invalid.", timeZoneName)
End Try
' Determine if CST and other time zones have the same rules
For Each rule As TimeZoneInfo.AdjustmentRule In usCstAdjustments
   Console.WriteLine("Comparing Central Standard Time rule for {0:d} to {1:d} with:", _
                     rule.DateStart, rule.DateEnd)
   ' Compare with Canada Central Standard Time
   If canCstAdjustments.Length = 0 Then
      Console.WriteLine("   Canada Central Standard Time has no adjustment rules.")
   Else
      For Each canRule As TimeZoneInfo.AdjustmentRule In canCstAdjustments
         Console.WriteLine("   Canadian CST for {0:d} to {1:d}: {2}", _
                           canRule.DateStart, canRule.DateEnd, _
                           IIf(rule.Equals(canRule), "Equal", "Not Equal"))
      Next              
   End If          

   ' Compare with Mexico Central Standard Time
   If mexCstAdjustments.Length = 0 Then
      Console.WriteLine("   Mexican Central Standard Time has no adjustment rules.")
   Else
      For Each mexRule As TimeZoneInfo.AdjustmentRule In mexCstAdjustments
         Console.WriteLine("   Mexican CST for {0:d} to {1:d}: {2}", _
                           mexRule.DateStart, mexRule.DateEnd, _
                           IIf(rule.Equals(mexRule), "Equal", "Not Equal"))
      Next              
   End If
Next   
' This code displays the following output to the console:
' 
' Comparing Central Standard Time rule for 1/1/0001 to 12/31/9999 with:
'    Canada Central Standard Time has no adjustment rules.
'    Mexican CST for 1/1/0001 to 12/31/9999: Equal

This code displays the following output to the console:

Comparing Central Standard Time rule for 1/1/0001 to 12/31/9999 with:
   Canada Central Standard Time has no adjustment rules.
   Mexican CST for 1/1/0001 to 12/31/9999: Equal

.NET Framework
Available since 3.5
Return to top
Show: