home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 8.img / CLASSINC.ZIP / LDATE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  3.0 KB  |  142 lines

  1. #ifndef __LDATE_H
  2. #define __LDATE_H
  3.  
  4.  
  5. //
  6. // This file contains proprietary information of Borland International.
  7. // Copying or reproduction without prior written approval is prohibited.
  8. //
  9. // Copyright (c) 1990
  10. // Borland International
  11. // 1800 Scotts Valley Dr.
  12. // Scotts Valley, CA 95066
  13. // (408) 438-8400
  14. //
  15.  
  16. // Contents ----------------------------------------------------------------
  17. //
  18. //     BaseDate
  19. //
  20. // Description
  21. //
  22. /*  Provides BaseDate as an abstract base class for handling date    */
  23. /*  storage and formatting                                           */
  24. //
  25. /*  Provides the Date class for storing dates and converting them    */
  26. /*  to an ASCII string of the form                                   */
  27. /*                                                                   */
  28. /*      January 1, 1990                                              */
  29. //
  30. // End ---------------------------------------------------------------------
  31.  
  32. #include <assert.h>
  33. #include <dos.h>
  34. #include "strng.h"
  35.  
  36. class BaseDate : public Sortable
  37. {
  38. public:
  39.     unsigned Month() const;
  40.     unsigned Day() const;
  41.     unsigned Year() const;
  42.     void SetMonth( unsigned char );
  43.     void SetDay( unsigned char );
  44.     void SetYear( unsigned );
  45.     virtual operator String() const = 0;
  46.  
  47.     virtual classType       isA() const = 0;
  48.     virtual char            *nameOf() const = 0;
  49.     virtual hashValueType   hashValue() const;
  50.     virtual int             isEqual( const Object& ) const;
  51.     virtual int             isLessThan( const Object& ) const;
  52.     virtual void            printOn( ostream& ) const;
  53. protected:
  54.     BaseDate();
  55.     BaseDate( unsigned char, unsigned char, unsigned );
  56.     BaseDate( const BaseDate& );
  57.     ~BaseDate();
  58. private:
  59.     unsigned char MM;
  60.     unsigned char DD;
  61.     unsigned int YY;
  62. };
  63.  
  64. inline BaseDate::BaseDate()
  65. {
  66.     struct date d;
  67.     getdate( &d );
  68.     MM = d.da_mon - 1;
  69.     DD = d.da_day;
  70.     YY = d.da_year;
  71. }
  72.  
  73. inline BaseDate::BaseDate( unsigned char M, unsigned char D, unsigned Y )
  74. {
  75.     SetMonth( M );
  76.     SetDay( D );
  77.     SetYear( Y );
  78. }
  79.  
  80. inline BaseDate::BaseDate( const BaseDate& B ) :
  81.     MM(B.MM), DD(B.DD), YY(B.YY)
  82. {
  83. }
  84.  
  85. inline unsigned BaseDate::Month() const
  86. {
  87.     return MM;
  88. }
  89.  
  90. inline unsigned BaseDate::Day() const
  91. {
  92.     return DD;
  93. }
  94.  
  95. inline unsigned BaseDate::Year() const
  96. {
  97.     return YY;
  98. }
  99.  
  100. inline void BaseDate::SetMonth( unsigned char M )
  101. {
  102.     assert( M > 0 && M < 13 );
  103.     MM = M - 1;
  104. }
  105.  
  106. inline void BaseDate::SetDay( unsigned char D )
  107. {
  108.     assert( D < 32 );
  109.     DD = D;
  110. }
  111.  
  112. inline void BaseDate::SetYear( unsigned Y )
  113. {
  114.     YY = Y;
  115. }
  116.  
  117. class Date : public BaseDate
  118. {
  119. public:
  120.     Date();
  121.     Date( unsigned char, unsigned char, unsigned );
  122.     Date( const Date& );
  123.     ~Date();
  124.     virtual operator String() const;
  125.     virtual classType       isA() const;
  126.     virtual char            *nameOf() const;
  127. };
  128.  
  129. inline Date::Date()
  130. {
  131. }
  132.  
  133. inline Date::Date( unsigned char M, unsigned char D, unsigned Y ) : BaseDate( M, D, Y )
  134. {
  135. }
  136.  
  137. inline Date::Date( const Date& D ) : BaseDate( D )
  138. {
  139. }
  140.  
  141. #endif  // ifndef __LDATE_H //
  142.