Microsoft Year 2000 Readiness Disclosure
& Resource Center |
|
|
|
ANSI Time and Visual C++
libraries |
|
The Microsoft C
Run Time provides two ANSI-C data structures to track time. These
are
- struct tm
- time_t
ANSI types: struct tm and time_t
The ANSI C standard has established these types, their meaning
and to some extent, the underlying type of each. In Visual C++, the
type of time_t is long and it represents seconds since
January 1, 1970 when used with the ANSI C functions that utilize
variables of this type. The type struct tm is used to track
the components of a date. The struct tm uses internal
variables to store years as the number of years since 1900, the
month of the year, day of the week, day of the month, day of the
year, hour of the day, minute of the hour, and seconds of the minute
are accounted for in this structure as well as if Daylight Savings
Time is in effect. These members are of type int. These types
are what ANSI functions use to manipulate, input, and output times.
The Visual C++ documentation has more information on these types.
Avoiding issues with ANSI time
functions
An application can appear to have a year 2000 issue because of
how ANSI functions are permitted to behave. You can create year 2000
compliant applications and avoid confusing output from your programs
if you follow some simple guidelines when using ANSI functions,
primarily the strftime and wcsftime functions.
- Present 4-digit years when displaying dates to users of your
application. When using the strftime and wcsftime
functions, use %Y to display a 4-digit year instead %y
(lowercase) which displays a 2-digit year. For example:
#include <time.h> #include
<stdio.h> const int BUFSIZE = 256; char
buf[BUFSIZE]; int main() { struct tm now; time_t tmp =
time(0); // get current time now = *localtime(&tmp); // get
components
// 2-digit vs. 4-digit year char fmt[] = "
%m/%d/%y \n %m/%d/%Y "; strftime( buf, BUFSIZ,
fmt, &now ); printf(buf);
return
0; }
- Require users of your application to provide fully qualified
dates (using 4-digit years) when accepting date input into your
application.
- Avoid using the %x or %c format, or if used, use # to get the
long date version when using strftime and wcsftime.
The %x and %c formatting codes default to printing a 2-digit
year. Change the initialization of fmt in the above program
to " %x \n %#x " to see the difference.
Keep
your times in a time_t variable or a struct tm and
manipulate them there. ANSI C mandates some other time functions
to aid in this task. Here is a list and brief description of these
functions. See your Visual C++ documentation for more details.
- time û gets the current calendar time in a
time_t
- difftime û computes the difference between two
time_t's
- gmtime û converts a time_t to a struct
tm, in terms of Coordinated Universal Time (UTC)
- localtime û converts a time_t to a struct
tm, in terms of local time
- asctime, _wasctime û returns a string
corresponding to the passed struct tm*. The string is of
the form "DDD MMM dd HH:MM:SS YYYY\n\0" and is always 26
characters.
- ctime, _wctimeû given a time_t, returns
the local time in the form of a string. Exactly the same as
asctime( localtime( time_t_val ))
- mktime û returns a locally adjusted time_t
given a struct tm*, which is updated so values fall into
appropriate ranges. For example
#include <time.h> #include
<stdio.h> const int BUFSIZE = 1024; char
buf[BUFSIZE]; int main() { struct tm now; time_t tmp
= time(0); // current time now =
*localtime(&tmp); size_t len = strftime(buf, BUFSIZE,
"%#c\n", &now);
now.tm_hour += 48; //jump ahead two
days
// should get a bogus hour value len +=
strftime(buf+len, BUFSIZE-len, "%#c\n",
&now);
mktime(&now); // mktime will
correct strftime(buf+len, BUFSIZE-len, "%#c\n",
&now);
printf(buf); return
0; }
- Although not an ANSI function, the _strdate and
_wstrdate functions generates a 9-character string to a
buffer that it receives a pointer to as a parameter. The output
has the form "MM/DD/YY". Use the strftime or wcsftime
function instead.
ALL
COMMUNICATIONS OR CONVEYANCES OF INFORMATION TO YOU CONCERNING
MICROSOFT AND THE YEAR 2000, INCLUDING BUT NOT LIMITED TO THIS
DOCUMENT OR ANY OTHER PAST, PRESENT OR FUTURE INFORMATION REGARDING
YEAR 2000 TESTING, ASSESSMENTS, READINESS, TIME TABLES, OBJECTIVES,
OR OTHER (COLLECTIVELY THE "MICROSOFT YEAR 2000 STATEMENT"), ARE
PROVIDED AS A "YEAR 2000 READINESS DISCLOSURE" (AS DEFINED BY
THE YEAR 2000 INFORMATION AND READINESS DISCLOSURE ACT) AND CAN BE
FOUND AT MICROSOFT'S YEAR 2000 WEBSITE LOCATED AT http://www.microsoft.com/year2000/
(THE "Y2K WEBSITE"). EACH MICROSOFT YEAR 2000 STATEMENT IS
PROVIDED PURSUANT TO THE TERMS HEREOF, THE TERMS OF THE Y2K WEBSITE,
AND THE YEAR 2000 INFORMATION AND READINESS DISCLOSURE ACT FOR THE
SOLE PURPOSE OF ASSISTING THE PLANNING FOR THE TRANSITION TO THE
YEAR 2000. EACH MICROSOFT YEAR 2000 STATEMENT CONTAINS INFORMATION
CURRENTLY AVAILABLE AND IS UPDATED REGULARLY AND SUBJECT TO CHANGE.
MICROSOFT THEREFORE RECOMMENDS THAT YOU CHECK THE Y2K WEBSITE
REGULARLY FOR ANY CHANGES TO ANY MICROSOFT YEAR 2000 STATEMENT.
EACH MICROSOFT YEAR 2000 STATEMENT IS PROVIDED "AS IS" WITHOUT
WARRANTY OF ANY KIND. CONSEQUENTLY, MICROSOFT DISCLAIMS ALL
WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. MOREOVER,
MICROSOFT DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE
USE OR THE RESULTS OF THE USE OF ANY MICROSOFT YEAR 2000 STATEMENT
IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY, OR OTHERWISE. NO
ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY MICROSOFT OR ITS
AUTHORIZED REPRESENTATIVES SHALL CREATE A WARRANTY OR IN ANY WAY
DECREASE THE SCOPE OF THIS WARRANTY DISCLAIMER. IN NO EVENT SHALL
MICROSOFT OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER
REGARDING ANY MICROSOFT YEAR 2000 STATEMENT INCLUDING DIRECT,
INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS,
PUNITIVE OR SPECIAL DAMAGES, EVEN IF MICROSOFT OR ITS SUPPLIERS HAVE
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO
NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL
OR INCIDENTAL DAMAGES, SO THE FOREGOING LIMITATION MAY NOT APPLY TO
YOU. THE INFORMATION CONTAINED IN EACH MICROSOFT YEAR 2000 STATEMENT
IS FOUND AT THE Y2K WEBSITE AND IS INTENDED TO BE READ IN
CONJUNCTION WITH OTHER INFORMATION LOCATED AT THE Y2K WEBSITE,
INCLUDING BUT NOT LIMITED TO MICROSOFT'S YEAR 2000 COMPLIANCE
STATEMENT, THE DESCRIPTION OF THE CATEGORIES OF COMPLIANCE INTO
WHICH MICROSOFT HAS CLASSIFIED ITS PRODUCTS IN ITS YEAR 2000 PRODUCT
GUIDE, AND THE MICROSOFT YEAR 2000 TEST CRITERIA.
ANY MICROSOFT YEAR 2000 STATEMENTS MADE TO YOU IN THE COURSE OF
PROVIDING YEAR 2000 RELATED UPDATES, YEAR 2000 DIAGNOSTIC TOOLS, OR
REMEDIATION SERVICES (IF ANY) ARE SUBJECT TO THE YEAR 2000
INFORMATION AND READINESS DISCLOSURE ACT (112 STAT. 2386). IN CASE
OF A DISPUTE, THIS ACT MAY REDUCE YOUR LEGAL RIGHTS REGARDING THE
USE OF ANY SUCH STATEMENTS, UNLESS OTHERWISE SPECIFIED BY YOUR
CONTRACT OR TARIFF.
|
|
|