Export (0) Print
Expand All

TimeZoneInfo.AdjustmentRule.Equals Method (TimeZoneInfo.AdjustmentRule)

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

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

public bool Equals(
	TimeZoneInfo..::.AdjustmentRule other
)

Return Value

Type: System.Boolean
true if both TimeZoneInfo.AdjustmentRule objects have equal values; otherwise, false.

Implements

IEquatable<T>.Equals(T)

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.

string timeZoneName = "";
// Get CST, Canadian CST, and Mexican CST adjustment rules
TimeZoneInfo.AdjustmentRule[] usCstAdjustments = null;
TimeZoneInfo.AdjustmentRule[] canCstAdjustments = null;
TimeZoneInfo.AdjustmentRule[] mexCstAdjustments = null;
try
{
   timeZoneName = "Central Standard Time";
   usCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules();
}
catch (TimeZoneNotFoundException)
{
   Console.WriteLine("The {0} time zone is not defined in the registry.", 
                     timeZoneName);
}                           
catch (InvalidTimeZoneException)
{
   Console.WriteLine("Data for the {0} time zone is invalid.", 
                     timeZoneName);
}
try
{
   timeZoneName = "Canada Central Standard Time";
   canCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules();
}
catch (TimeZoneNotFoundException)
{
   Console.WriteLine("The {0} time zone is not defined in the registry.", 
                     timeZoneName);
}                           
catch (InvalidTimeZoneException)
{
   Console.WriteLine("Data for the {0} time zone is invalid.", 
                     timeZoneName);
}
try
{
   timeZoneName = "Mexico Standard Time";
   mexCstAdjustments = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName).GetAdjustmentRules();
}   
catch (TimeZoneNotFoundException)
{
   Console.WriteLine("The {0} time zone is not defined in the registry.", 
                     timeZoneName);
}                           
catch (InvalidTimeZoneException)
{
   Console.WriteLine("Data for the {0} time zone is invalid.", 
                     timeZoneName);
}
// Determine if CST and other time zones have the same rules 
foreach(TimeZoneInfo.AdjustmentRule rule 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)
   {
      Console.WriteLine("   Canada Central Standard Time has no adjustment rules.");
   }   
   else
   {
      foreach (TimeZoneInfo.AdjustmentRule canRule in canCstAdjustments)
      {
         Console.WriteLine("   Canadian CST for {0:d} to {1:d}: {2}", 
                           canRule.DateStart, canRule.DateEnd, 
                           rule.Equals(canRule) ? "Equal" : "Not Equal");
      }              
   }          

   // Compare with Mexico Central Standard Time 
   if (mexCstAdjustments.Length == 0)
   {
      Console.WriteLine("   Mexican Central Standard Time has no adjustment rules.");
   }
   else
   {
      foreach (TimeZoneInfo.AdjustmentRule mexRule in mexCstAdjustments)
      {
         Console.WriteLine("   Mexican CST for {0:d} to {1:d}: {2}", 
                           mexRule.DateStart, mexRule.DateEnd, 
                           rule.Equals(mexRule) ? "Equal" : "Not 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

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5

Community Additions

ADD
Show:
© 2014 Microsoft