Non-MFC Date Routines in ATL





0/5 (0 vote)
Mar 10, 2000

58821

963
Non-MFC Date Routines in an ATL Component.
When writing ATL components, one of the hardest things to overcome for Windows programmers, in my opinion, is the dependency on the MFC library. For dates and strings, MFC simplifies the programmer's job by handling memory allocations and type conversions within its class encapsulation. However, with that simplification comes the price of having to distribute the MFC DLL's with your component.
This article focuses on the issues surrounding the use of dates within an ATL
component. I developed the DateLib
component as part of a project for my
company and, as such, the methods of this component are specific to my company's
requirements (I do not have an intellectual property agreement with this company).
However, the DateLib
component does illustrate how to build an ATL component
that has no MFC dependencies, is thread-safe, and will compile as either ANSI or UNICODE.
The methods within the DateLib component are as follows:
Date Formatting Routines:
Now
- Returns the current system date in aDATE
variable.OLE2Oracle
- For a givenDATE
, returns a formatted string using the DD-Mon-YYYY representation.Int2Oracle
- For a given month, day, and year, returns a formatted string using the DD-Mon-YYYY representation.Int2OLE
- For a given month, day, and year, returns the date in aDATE
variable.OLE2String
- For a givenDATE
, returns a formatted string using the MM/DD/YYYY representation.
Date Parsing Routines:
ParseOracle2OLE
- For a given date given in a M/D/YY format, returns the date in aDATE
variable.ParseOracle2String
- For a given date given in a M/D/YY format, returns a formatted string using the MM/DD/YYYY representation.ParseOracle2Oracle
- For a given date given in a M/D/YY format, returns a formatted string using the DD-Mon-YYYY representation.
Date Math Routines:
GetFirstDay
- For a givenDATE
, returns the first day of the month in aDATE
variable.GetLastDay
- For a givenDATE
, returns the last day of the month in aDATE
variable.GetNextDay
- For a givenDATE
, returns the next day's date in aDATE
variable.GetNextWeek
- For a givenDATE
, returns the next week's date in aDATE
variable.GetNextMonth
- For a givenDATE
, returns the next month's date in aDATE
variable.GetNextYear
- For a givenDATE
, returns the next year's date in aDATE
variable.GetPreviousDay
- For a givenDATE
, returns the previous day's date in aDATE
variable.GetPreviousWeek
- For a givenDATE
, returns the previous week's date in aDATE
variable.GetPreviousMonth
- For a givenDATE
, returns the previous month's date in aDATE
variable.GetPreviousYear
- For a given DATE, returns the previous year's date in aDATE
variable.