Microsoft KB Archive/933509

From BetaArchive Wiki
Knowledge Base


Article ID: 933509

Article Last Modified on 12/3/2007



APPLIES TO

  • Microsoft .NET Framework 2.0
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0



INTRODUCTION

This article describes how the changes to daylight saving time (DST) in 2007 affect developers who use the Microsoft .NET Framework.

These changes do not affect Microsoft Internet Information Services (IIS). However, these changes may affect some Web pages that are developed in Microsoft ASP.NET and that use the System.TimeZone namespace.

MORE INFORMATION

Starting in 2007, the start date and the end date for DST in the United States will change to comply with the U.S. Energy Policy Act of 2005. Therefore, DST in the United States starts three weeks earlier than it started in the past. Additionally, DST ends one week later than it ended in the past. DST now uses the following start date and the following end date:

  • Daylight saving time starts at 2:00 A.M. on the second Sunday in March.
  • Daylight saving time ends at 2:00 A.M. on the first Sunday in November.

For the .NET Framework, you may experience a problem that involves the System.TimeZone namespace and historical calculations. The nature of the problem depends on whether you have applied the DST hotfix that is described in Microsoft Knowledge Base article 928388 on a computer that is running the .NET Framework. If you have applied this hotfix on a computer that is running the .NET Framework, calculations are incorrect for the affected times in 2006 and in earlier years. If you have not applied this hotfix on the computer that is running the .NET Framework, calculations for the problem dates are incorrect for 2007 and for later years.

For example, the DST change affects March 28. If you apply the hotfix that is described in Microsoft Knowledge Base article 928388, the TimeZone.CurrentTimeZone.IsDaylightSavingTime function returns the correct value (true) for March 28, 2007. However, the TimeZone.CurrentTimeZone.IsDaylightSavingTime function also returns a value of true for March 28, 2006. This function should return a value of false for March 28, 2006.

Additionally, many developers use coordinated universal time (UTC) in calculations to avoid various DST issues. Programs that use UTC also receive incorrect values for the problem dates. For example, if you use the DateDiff method to determine the number of hours between 1:00 A.M. on March 12, 2006, and 5:00 A.M. on March 12, 2006, you receive a value of three hours instead of the correct value of four hours. According to the new DST rules, clocks move ahead one hour on the second Sunday of March.

Example scenario

The following example scenario assumes that the following conditions are true:

  • The computer is running the .NET Framework.
  • You have applied the hotfix that is described in the following Microsoft Knowledge Base article:

    928388 2007 time zone update for Microsoft Windows operating systems

The following code example returns a value of true:

Dim DateSet As New DateTime()
DateSet = Convert.ToDateTime("3/28/2006 1:00:00 PM")
Label1.Text = DateSet.IsDaylightSavingTime()

To resolve this problem, create a function that handles the mismatched dates for a particular year and another function that finds the specific key dates for the particular year. For example, the functions may resemble the functions in the following code example.

Function GetKeyDate(ByVal MyMonthDay As String, ByVal myYear As Integer) As Date
        
        Dim NextSun As Date
        NextSun = MyMonthDay & myYear

    'Find the next Sunday.
        While Not (NextSun.DayOfWeek = DayOfWeek.Sunday)
            NextSun = NextSun.AddDays(1)
        End While
        GetKeyDate = NextSun
    End Function

    Function FindCorrectDST(ByVal chkDate As DateTime) As Boolean
        Dim DST As Boolean
        DST = chkDate.IsDaylightSavingTime
        If chkDate.Year > 2006 Then
            Return DST
        End If
        Dim ds1, ds2, ds3, ds4 As Date
'Use the earliest possible key Sunday.
        ds1 = GetKeyDate("03/08/", chkDate.Year)
        ds2 = GetKeyDate("04/01/", chkDate.Year)
        ds3 = GetKeyDate("10/25/", chkDate.Year)
        ds4 = GetKeyDate("11/01/", chkDate.Year)

        If ((Date.Compare(chkDate, ds1) >= 0) And (Date.Compare(chkDate, ds2) < 0)) Or ((Date.Compare(chkDate, ds3) >= 0) And (Date.Compare(chkDate, ds4) < 0)) Then
            Return Not DST  'If the date is within one of these ranges, the result will be exactly wrong.
        Else
            Return DST
        End If
    End Function

REFERENCES

For more information about the Daylight Saving Time Help and Support Center, visit the following Microsoft Web site:

For more information about Visual Studio and the DST change, visit the following Microsoft Developer Network (MSDN) Web site:


Additional query words: DST 2007

Keywords: kbinfo kbtshoot kbcode kbpubtypekc KB933509