In connection with the abolition of the transition to “winter” time, development companies ask us questions related to possible problems that may arise with the correct operation of applications. To answer these questions, we prepared this material, which contains tips on using date / time functions correctly, checking the code to find potential problems, and describing the steps that need to be performed to correctly deploy the update of both the operating system and the applications themselves. . Below we will cover the following topics:
- Approaches to testing applications and checking code
- Recommendations for correct work with date / time
- Approaches to search for operating system updates
- App Updates
- Additional materials
Introduction
In the summer of this year, the Government of the Russian Federation passed a law abolishing the seasonal rendition of hours and set the relevant time zones and time values. “Summer” and “winter” time, also called “seasonal time” or “Daylight Saving Time” (DST), is a time-calculating mode in which the clock is shifted one hour ahead in spring and one hour back in the fall. Spring and autumn transitions differ in the Northern and Southern Hemispheres. The transition to summer time in the Northern Hemisphere usually begins in March or April (depending on the country and continent), and the transition to winter time takes place in October or November. In the Southern Hemisphere, the opposite is true: “summer” time begins in October, and “winter” time begins in March or April. Note that the transition to "summer" and "winter" time does not occur in all countries.
Application Testing and Code Verification
The first step in preparing to cancel winter time is to install the appropriate operating system update, which is available at
http://support.microsoft.com/kb/2570791 . Next, you need to make sure that the application works correctly with the new time zone settings and the disabled settings for the transition to "winter" and "summer" time. To do this, it is recommended to write a test script and compare the results of the application on a computer where the update has not yet been installed and on the computer with the update installed. If problems are found, it is recommended to check the application code, paying attention to the following functional blocks:
- Getting or calculating the date / time
- Using proprietary algorithms for checking the time zone, the transition to the "winter" and "summer" time
- Own calculations of time ranges, such as date differences in hours, minutes, and seconds
- Calculations related to the compensation of transitions to the "winter" and "summer" time
- Convert date / time representation for storage or display
The recommendations below will minimize the effect of canceling the transition to winter time and, in general, improve the work with date / time in applications.
- When installing updates, pay attention to the fact that updates were performed sequentially, preferably sequentially, one after the other.
- Use the date / time stored in UTC (Coordinated Universal Time replaces the “obsolete” GMT, GMT). This view accurately displays historical data. In most cases, problems arise with the conversion to a local representation, since in this case, it is necessary to obtain information about the time zone and DST (day-saving time). This information can be obtained from various sources:
- When implementing communications between computers, including the exchange of date / time, must be performed in the UTC-representation - this gives both computers the same contextual information for UTC
Below are some scenarios for using date / time functions that can be used to perform date / time conversions to a local representation.
')
Date / Time Conversion to Local View
There are a number of software interfaces in the Microsoft Windows operating system that can be used to convert UTC time to a local representation.
- The functions GetSystemTime () and GetSystemTimeAsFileTime () return the time in UTC in a structure of type SYSTEMTIME or FILETIME
- The GetLocalTime () function returns the current local time in a structure of the SYSTEMTIME type
- The GetTimeZoneInformation () function returns a TIME _ ZONE _ INFORMATION structure describing the current time zone and DST settings of the computer.
- The functions SystemTimeToFileTime () and FileTimeToSystemTime () are used to convert data in structures of type SYSTEMTIME or FILETIME
- The FileTimeToLocalFileTime () and LocalFileTimeToFileTime () functions convert the FILETIME structure between UTC and local time, taking into account the DST settings
- The SystemTimeToTzSpecificLocalTime () and TzSpecificTimeToSystemTime () functions convert a UTC-date / time in the SYSTEMTIME structure to a local SYSTEMTIME structure. These functions use the TIME _ ZONE _ INFORMATION structure, which describes the start and end date of the DST.
Starting with the Microsoft Windows Vista operating system, the concept of “dynamic time zones” has been introduced - support for time zones with “start” and “end” DST dates floating from year to year. The rules for determining the start / end date are saved in the registry (see below) and can be obtained through the function
GetDynamicTimeZoneInformation () , which fills the structure
DYNAMIC _ TIME _ ZONE _ INFORMATION .
Using the .NET Framework
In the .NET Framework, there are classes for date / time conversion, which include the
DateTime ,
TimeZone ,
TimeSpan, and
DateTimeKind classes. These classes use the Windows API functions listed above. In addition to these functions, in the .NET Framework there are functions for changing the date / time to a specified interval -
AddHours () ,
AddMinutes () ,
AddSeconds () , which are implemented in the
DateTime class.
Time Zone Information
As we noted above, information about time zones is stored in the registry. Descriptions of all time zones can be found in the following registry branch:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Time Zones
Each time zone has its own unique element, the nested elements of which contain such attributes as the name of the official time zone, the formal name, as well as links to multilingual resources and, in fact, information about the time zone. The Dynamic DST nested element contains information about previous changes in time zones. Beginning with the Windows Vista operating system, this information is populated when the operating system is installed. For Windows XP and Windows Server 2003 operating systems, the information is filled in when installing the appropriate service packs.
Information about the current time zone selected in the
Date and Time panel is also stored in the registry
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ TimeZoneInformation
Approaches to updating applications
Companies that develop software products should check the correctness of their applications after installing the update (
http://support.microsoft.com/kb/2570791 ), which cancels automatic switching of Windows to the "winter" time. The verification process is described above. If necessary, companies should release updates of their products, allowing to work correctly with the date / time after 10/30/2011.
Search for installed updates
To correctly install updates for your products, you need to make sure that the operating system update itself (KB2570791) is installed, because not all users have the Windows Update mechanism enabled and operating system updates are installed at the time of their appearance. Below are several ways to verify the installation of an operating system update (KB2570791).
Manual ways
To detect the fact that an operating system update has been installed (KB2570791), you can use the
Windows Update section of the
Control Panel . To do this, perform the following sequence of actions:
- Call the Start menu
- Call Control Panel Utility
- Go to Programs \ Programs and Features \ Installed Updates
- In the list of installed updates, find the Update for Microsoft Windows ( KB2570791) entry with the date 08/24/2011
You can also use PowerShell to detect the fact that an operating system update has been installed (KB2570791). To find the OS update we are interested in, use the standard
get- hotfix cmdlet as follows: PS C: \> get-hotfix KB2570791
Information about installed updates is also available through the Unified Operating System Management Interface - Windows Management Instrumentation (WMI). You can do this manually using the Windows Management Instrumentation Console (WMIC) utility. To get a list of all installed updates, run the wmic qfe list command and to find a specific operating system update, use the command
wmic qfe | find “2570791”
Software methods
Among the software methods, you can highlight a search in the registry, the use of the unified operating system management interface –WMI already mentioned, and the use of the Windows Update software interfaces. Search in the registry is not recommended, as in different versions of the operating system information is stored in different branches of the registry, for example, in recent versions of Windows, the Component Based Update section is used. The Windows Update programming interfaces are quite complex and should be used in cases when other methods are not suitable.
The easiest way to programmatically detect the fact that an operating system update is installed is WMI. To find all installed updates, you need to run a query.
select * from Win32_QuickFixEngineering and to find a specific update - the query select * from Win32_QuickFixEngineering where HotFixID = "KB2570791"
Further, if the operating system update is installed, the update of the software of the developer company is installed. If an update of the operating system is required, this can be done in one of the following ways:
- Programmatically, through the Component Based Servicing API functions
- Along with the installation of the application update - in this case, all versions of the operating system update should be distributed on disk along with the updated application.
- Manually, through Windows Update - each user must independently install the operating system updates before installing the updated version of the application
- If the Windows Update mechanism is not used, updates can be installed manually by downloading them from the link - http://support.microsoft.com/kb/2570791 , choosing the required version of the operating system
Additional Information
- Help and support center for daylight saving time
- Date and Time Functions - Windows API
- Date and Time Structures - Windows API
- Using the .NET Framework Classes
- Windows Management Instrumentation Description
- Software Interfaces Component Based Servicing
/ AF